From f6877727c65ac326f358cc5214fa945baf60b824 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Fri, 28 May 2021 20:00:43 -0300 Subject: [PATCH 1/4] Promote channel.subscription.end from beta to v1 (Breaking) --- src/NewTwitchApi/Resources/EventSubApi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NewTwitchApi/Resources/EventSubApi.php b/src/NewTwitchApi/Resources/EventSubApi.php index 6b83bec..5b94947 100644 --- a/src/NewTwitchApi/Resources/EventSubApi.php +++ b/src/NewTwitchApi/Resources/EventSubApi.php @@ -109,16 +109,16 @@ public function subscribeToChannelSubscribe(string $bearer, string $secret, stri } /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelunsubscribe-beta + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptionend */ - public function subscribeToChannelUnsubscribe(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + public function subscribeToChannelSubscriptionEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface { return $this->createEventSubSubscription( $bearer, $secret, $callback, - 'channel.unsubscribe', - 'beta', + 'channel.subscription.end', + '1', ['broadcaster_user_id' => $twitchId], ); } From 88b998bff362da3d974f5202634acf7608e5f4a5 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Fri, 28 May 2021 20:07:56 -0300 Subject: [PATCH 2/4] Fix Spec for subscribeToChannelSubscriptionEnd --- spec/NewTwitchApi/Resources/EventSubApiSpec.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/NewTwitchApi/Resources/EventSubApiSpec.php b/spec/NewTwitchApi/Resources/EventSubApiSpec.php index ea53673..d40bb52 100644 --- a/spec/NewTwitchApi/Resources/EventSubApiSpec.php +++ b/spec/NewTwitchApi/Resources/EventSubApiSpec.php @@ -79,10 +79,10 @@ function it_should_subscribe_to_channel_subscribe(RequestGenerator $requestGener $this->subscribeToChannelSubscribe($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); } - function it_should_subscribe_to_channel_unsubscribe(RequestGenerator $requestGenerator, Request $request, Response $response) + function it_should_subscribe_to_channel_subscription_end(RequestGenerator $requestGenerator, Request $request, Response $response) { - $this->createEventSubSubscription('channel.unsubscribe', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelUnsubscribe($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + $this->createEventSubSubscription('channel.subscription.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscriptionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); } function it_should_subscribe_to_channel_cheer(RequestGenerator $requestGenerator, Request $request, Response $response) From 58ac50a76388bca4500a3f6f8c8dcf54438fb957 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Fri, 28 May 2021 20:08:21 -0300 Subject: [PATCH 3/4] Add EventSubApi->subscribeToChannelSubscriptionGift --- spec/NewTwitchApi/Resources/EventSubApiSpec.php | 6 ++++++ src/NewTwitchApi/Resources/EventSubApi.php | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/spec/NewTwitchApi/Resources/EventSubApiSpec.php b/spec/NewTwitchApi/Resources/EventSubApiSpec.php index d40bb52..622794b 100644 --- a/spec/NewTwitchApi/Resources/EventSubApiSpec.php +++ b/spec/NewTwitchApi/Resources/EventSubApiSpec.php @@ -85,6 +85,12 @@ function it_should_subscribe_to_channel_subscription_end(RequestGenerator $reque $this->subscribeToChannelSubscriptionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); } + function it_should_subscribe_to_channel_subscription_gift(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.subscription.gift', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscriptionGift($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + function it_should_subscribe_to_channel_cheer(RequestGenerator $requestGenerator, Request $request, Response $response) { $this->createEventSubSubscription('channel.cheer', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); diff --git a/src/NewTwitchApi/Resources/EventSubApi.php b/src/NewTwitchApi/Resources/EventSubApi.php index 5b94947..ebee688 100644 --- a/src/NewTwitchApi/Resources/EventSubApi.php +++ b/src/NewTwitchApi/Resources/EventSubApi.php @@ -123,6 +123,21 @@ public function subscribeToChannelSubscriptionEnd(string $bearer, string $secret ); } + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptiongift-beta + */ + public function subscribeToChannelSubscriptionGift(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.subscription.gift', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + /** * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcheer */ From 77ae5dd728091f4811d290442a1be641854e63ad Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Fri, 28 May 2021 20:08:33 -0300 Subject: [PATCH 4/4] Add ChatApi --- spec/NewTwitchApi/Resources/ChatApiSpec.php | 30 +++++++++++++++++++ src/NewTwitchApi/NewTwitchApi.php | 8 ++++++ src/NewTwitchApi/Resources/ChatApi.php | 32 +++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 spec/NewTwitchApi/Resources/ChatApiSpec.php create mode 100644 src/NewTwitchApi/Resources/ChatApi.php diff --git a/spec/NewTwitchApi/Resources/ChatApiSpec.php b/spec/NewTwitchApi/Resources/ChatApiSpec.php new file mode 100644 index 0000000..7db8f2b --- /dev/null +++ b/spec/NewTwitchApi/Resources/ChatApiSpec.php @@ -0,0 +1,30 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($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); + $this->getChannelChatBadges('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_global_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/badges/global', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getGlobalChatBadges('TEST_TOKEN')->shouldBe($response); + } +} diff --git a/src/NewTwitchApi/NewTwitchApi.php b/src/NewTwitchApi/NewTwitchApi.php index 25a800a..870d2c9 100644 --- a/src/NewTwitchApi/NewTwitchApi.php +++ b/src/NewTwitchApi/NewTwitchApi.php @@ -11,6 +11,7 @@ use NewTwitchApi\Resources\BitsApi; use NewTwitchApi\Resources\ChannelPointsApi; use NewTwitchApi\Resources\ChannelsApi; +use NewTwitchApi\Resources\ChatApi; use NewTwitchApi\Resources\ClipsApi; use NewTwitchApi\Resources\EntitlementsApi; use NewTwitchApi\Resources\EventSubApi; @@ -37,6 +38,7 @@ class NewTwitchApi private $bitsApi; private $channelPointsApi; private $channelsApi; + private $chatApi; private $clipsApi; private $entitlementsApi; private $eventSubApi; @@ -64,6 +66,7 @@ public function __construct(Client $helixGuzzleClient, string $clientId, string $this->bitsApi = new BitsApi($helixGuzzleClient, $requestGenerator); $this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient, $requestGenerator); $this->channelsApi = new ChannelsApi($helixGuzzleClient, $requestGenerator); + $this->chatApi = new ChatApi($helixGuzzleClient, $requestGenerator); $this->clipsApi = new ClipsApi($helixGuzzleClient, $requestGenerator); $this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator); $this->eventSubApi = new EventSubApi($helixGuzzleClient, $requestGenerator); @@ -113,6 +116,11 @@ public function getChannelsApi(): ChannelsApi return $this->channelsApi; } + public function getChatApi(): ChatApi + { + return $this->chatApi; + } + public function getClipsApi(): ClipsApi { return $this->clipsApi; diff --git a/src/NewTwitchApi/Resources/ChatApi.php b/src/NewTwitchApi/Resources/ChatApi.php new file mode 100644 index 0000000..9b39ae6 --- /dev/null +++ b/src/NewTwitchApi/Resources/ChatApi.php @@ -0,0 +1,32 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('chat/badges', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-global-chat-badges + */ + public function getGlobalChatBadges(string $bearer): ResponseInterface + { + return $this->getApi('chat/badges/global', $bearer); + } +}