Skip to content

Commit

Permalink
Merge pull request #87 from brandinarsenault/master
Browse files Browse the repository at this point in the history
getStreams Improvements
  • Loading branch information
echosa authored Dec 7, 2020
2 parents 2948d8f + 9f4d8d2 commit d81596b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
42 changes: 24 additions & 18 deletions spec/NewTwitchApi/Resources/StreamsApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
19 changes: 16 additions & 3 deletions src/NewTwitchApi/Resources/StreamsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit d81596b

Please sign in to comment.