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