Skip to content

Commit

Permalink
Merge pull request #114 from brandinarsenault/get-followed-streams
Browse files Browse the repository at this point in the history
Add getFollowedStreams
  • Loading branch information
Brandin committed Apr 27, 2021
2 parents 859f8f7 + 21a3a20 commit 6cf9714
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/NewTwitchApi/Resources/StreamsApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ function it_should_get_streams_by_everything(Client $guzzleClient, Response $res
$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);
}

function it_should_get_followed_streams(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'streams/followed?user_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getFollowedStreams('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_get_followed_streams_with_everything(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'streams/followed?user_id=123&first=100&after=abc', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getFollowedStreams('TEST_TOKEN', '123', 100, 'abc')->shouldBeAnInstanceOf(ResponseInterface::class);
}
}
21 changes: 21 additions & 0 deletions src/NewTwitchApi/Resources/StreamsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,25 @@ public function getStreamTags(string $bearer, string $broadcasterId): ResponseIn

return $this->getApi('streams/tags', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference/#get-followed-streams
*/
public function getFollowedStreams(string $bearer, string $userId, int $first = null, string $after = null): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];

if ($first) {
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
}

if ($after) {
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
}

return $this->getApi('streams/followed', $bearer, $queryParamsMap);
}
}

0 comments on commit 6cf9714

Please sign in to comment.