From 21a3a2079cb7dbbb46cbfe06c29b9108a6135e41 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 26 Apr 2021 13:31:59 -0300 Subject: [PATCH] Add getFollowedStreams --- .../NewTwitchApi/Resources/StreamsApiSpec.php | 12 +++++++++++ src/NewTwitchApi/Resources/StreamsApi.php | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/spec/NewTwitchApi/Resources/StreamsApiSpec.php b/spec/NewTwitchApi/Resources/StreamsApiSpec.php index 549e192..f2ff4c9 100644 --- a/spec/NewTwitchApi/Resources/StreamsApiSpec.php +++ b/spec/NewTwitchApi/Resources/StreamsApiSpec.php @@ -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); + } } diff --git a/src/NewTwitchApi/Resources/StreamsApi.php b/src/NewTwitchApi/Resources/StreamsApi.php index a1dc77e..41e77cb 100644 --- a/src/NewTwitchApi/Resources/StreamsApi.php +++ b/src/NewTwitchApi/Resources/StreamsApi.php @@ -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); + } }