diff --git a/spec/NewTwitchApi/Resources/StreamsApiSpec.php b/spec/NewTwitchApi/Resources/StreamsApiSpec.php index 390460a..44e620c 100644 --- a/spec/NewTwitchApi/Resources/StreamsApiSpec.php +++ b/spec/NewTwitchApi/Resources/StreamsApiSpec.php @@ -18,72 +18,78 @@ function let(Client $guzzleClient) function it_should_get_streams_by_ids(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?user_id=12345&user_id=98765', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", ['12345','98765'])->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', ['12345', '98765'])->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_by_usernames(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?user_login=twitchuser&user_login=anotheruser', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], ['twitchuser','anotheruser'])->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], ['twitchuser', 'anotheruser'])->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_by_id_and_username(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?user_id=12345&user_id=98765&user_login=twitchuser&user_login=anotheruser', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", ['12345','98765'], ['twitchuser','anotheruser'])->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', ['12345', '98765'], ['twitchuser', 'anotheruser'])->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_a_single_user_by_id(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?user_id=12345', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreamForUserId("TEST_TOKEN", '12345')->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreamForUserId('TEST_TOKEN', '12345')->shouldBeAnInstanceOf(ResponseInterface::class); + } + + function it_should_get_a_single_game_id(Client $guzzleClient, Response $response) + { + $guzzleClient->send(new Request('GET', 'streams?game_id=12345', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); + $this->getStreamsByGameId('TEST_TOKEN', '12345')->shouldBeAnInstanceOf(ResponseInterface::class); + } + + function it_should_get_a_single_language(Client $guzzleClient, Response $response) + { + $guzzleClient->send(new Request('GET', 'streams?language=en', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); + $this->getStreamsByLanguage('TEST_TOKEN', 'en')->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_a_single_user_by_username(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?user_login=twitchuser', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreamForUsername("TEST_TOKEN", 'twitchuser')->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreamForUsername('TEST_TOKEN', 'twitchuser')->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_by_game_ids(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?game_id=12345&game_id=98765', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], ['12345','98765'])->shouldBeAnInstanceOf(ResponseInterface::class); - } - - function it_should_get_streams_by_community_ids(Client $guzzleClient, Response $response) - { - $guzzleClient->send(new Request('GET', 'streams?community_id=12345&community_id=98765', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], [], ['12345','98765'])->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], [], ['12345', '98765'])->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_by_languages(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?language=en&language=de', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], [], [], ['en','de'])->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], [], [], [], ['en', 'de'])->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_page_by_first(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?first=42', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], [], [], [], 42)->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], [], [], [], [], 42)->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_page_by_before(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?before=42', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], [], [], [], null, 42)->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], [], [], [], [], null, 42)->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_page_by_after(Client $guzzleClient, Response $response) { $guzzleClient->send(new Request('GET', 'streams?after=42', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", [], [], [], [], [], null, null, 42)->shouldBeAnInstanceOf(ResponseInterface::class); + $this->getStreams('TEST_TOKEN', [], [], [], [], [], null, null, 42)->shouldBeAnInstanceOf(ResponseInterface::class); } function it_should_get_streams_by_everything(Client $guzzleClient, Response $response) { - $guzzleClient->send(new Request('GET', 'streams?user_id=12&user_id=34&user_login=twitchuser&user_login=anotheruser&game_id=56&game_id=78&community_id=90&community_id=99&language=en&language=de&first=100&before=200&after=300', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); - $this->getStreams("TEST_TOKEN", ['12','34'], ['twitchuser','anotheruser'], ['56','78'], ['90','99'], ['en','de'], 100, 200, 300)->shouldBeAnInstanceOf(ResponseInterface::class); + $guzzleClient->send(new Request('GET', 'streams?user_id=12&user_id=34&user_login=twitchuser&user_login=anotheruser&game_id=56&game_id=78&language=en&language=de&first=100&before=200&after=300', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); + $this->getStreams('TEST_TOKEN', ['12', '34'], ['twitchuser', 'anotheruser'], ['56', '78'], [], ['en', 'de'], 100, 200, 300)->shouldBeAnInstanceOf(ResponseInterface::class); } } diff --git a/src/NewTwitchApi/Resources/StreamsApi.php b/src/NewTwitchApi/Resources/StreamsApi.php index 06ba59a..ff1c16b 100644 --- a/src/NewTwitchApi/Resources/StreamsApi.php +++ b/src/NewTwitchApi/Resources/StreamsApi.php @@ -25,6 +25,22 @@ public function getStreamForUsername(string $bearer, string $username): Response return $this->getStreams($bearer, [], [$username], [], [], [], null, null, null); } + /** + * @throws GuzzleException + */ + public function getStreamsByGameId(string $bearer, string $gameId, int $first = null, string $before = null, string $after = null): ResponseInterface + { + return $this->getStreams($bearer, [], [], [$gameId], [], [], $first, $before, $after); + } + + /** + * @throws GuzzleException + */ + public function getStreamsByLanguage(string $bearer, string $language, int $first = null, string $before = null, string $after = null): ResponseInterface + { + return $this->getStreams($bearer, [], [], [], [], [$language], $first, $before, $after); + } + /** * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference#get-stream-key @@ -54,9 +70,6 @@ public function getStreams(string $bearer, array $userIds = [], array $usernames foreach ($gameIds as $gameId) { $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; } - foreach ($communityIds as $communityId) { - $queryParamsMap[] = ['key' => 'community_id', 'value' => $communityId]; - } foreach ($languages as $language) { $queryParamsMap[] = ['key' => 'language', 'value' => $language]; }