From a77c1fa773edf52dd7fb585ad925f1d281c44bad Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Thu, 3 Jun 2021 16:24:37 -0300 Subject: [PATCH 1/2] Revert README changes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ad928e8..c48bb67 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ $twitch_client_id = 'TWITCH_CLIENT_ID'; $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; -$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id); +$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); $newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); $oauth = $newTwitchApi->getOauthApi(); @@ -62,7 +62,7 @@ $twitch_client_id = 'TWITCH_CLIENT_ID'; $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; -$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id); +$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); $newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); $oauth = $newTwitchApi->getOauthApi(); @@ -104,7 +104,7 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; $user_refresh_token = 'REFRESH_TOKEN'; -$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id); +$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); $newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); $oauth = $newTwitchApi->getOauthApi(); @@ -140,7 +140,7 @@ $twitch_access_token = 'the token'; // The Guzzle client used can be the included `HelixGuzzleClient` class, for convenience. // You can also use a mock, fake, or other double for testing, of course. -$helixGuzzleClient = \NewTwitchApi\HelixGuzzleClient::getClient($twitch_client_id); +$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); // Instantiate NewTwitchApi. Can be done in a service layer and injected as well. $newTwitchApi = new NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); From 5c7886d574d0f114a3be9825562a1d327a192650 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 9 Jun 2021 16:47:04 -0300 Subject: [PATCH 2/2] Add Emote Endpoints --- spec/NewTwitchApi/Resources/ChatApiSpec.php | 30 ++++++++++++++ src/NewTwitchApi/Resources/ChatApi.php | 44 +++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/spec/NewTwitchApi/Resources/ChatApiSpec.php b/spec/NewTwitchApi/Resources/ChatApiSpec.php index ff8b333..e0c4bfe 100644 --- a/spec/NewTwitchApi/Resources/ChatApiSpec.php +++ b/spec/NewTwitchApi/Resources/ChatApiSpec.php @@ -16,6 +16,36 @@ function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator $guzzleClient->send($request)->willReturn($response); } + function it_should_get_channel_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelEmotes('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_global_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/global', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getGlobalEmotes('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_one_emote_set(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); + $this->getEmoteSets('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_one_emote_set_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); + $this->getEmoteSet('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_multiple_emote_sets(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123'], ['key' => 'emote_set_id', 'value' => '456']], [])->willReturn($request); + $this->getEmoteSets('TEST_TOKEN', ['123', '456'])->shouldBe($response); + } + function it_should_get_channel_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) { $requestGenerator->generate('GET', 'chat/badges', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); diff --git a/src/NewTwitchApi/Resources/ChatApi.php b/src/NewTwitchApi/Resources/ChatApi.php index 9b39ae6..2a88f78 100644 --- a/src/NewTwitchApi/Resources/ChatApi.php +++ b/src/NewTwitchApi/Resources/ChatApi.php @@ -9,6 +9,50 @@ class ChatApi extends AbstractResource { + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-channel-emotes + */ + public function getChannelEmotes(string $bearer, string $broadcasterId): ResponseInterface + { + $queryParamsMap = []; + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('chat/emotes', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-global-emotes + */ + public function getGlobalEmotes(string $bearer): ResponseInterface + { + return $this->getApi('chat/emotes/global', $bearer); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-emote-sets + */ + public function getEmoteSets(string $bearer, array $emoteSetIds = []): ResponseInterface + { + $queryParamsMap = []; + + foreach ($emoteSetIds as $emoteSetId) { + $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; + } + + return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); + } + + public function getEmoteSet(string $bearer, string $emoteSetId): ResponseInterface + { + $queryParamsMap = []; + $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; + + return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); + } + /** * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference#get-channel-chat-badges