From ffc92e205ffa95cfe1b2c85b81cce945e9910be4 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 5 Sep 2022 12:26:45 -0300 Subject: [PATCH 1/5] Add First Param to getBannedUsers --- src/Resources/ModerationApi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Resources/ModerationApi.php b/src/Resources/ModerationApi.php index 4fe99bb..8b15159 100644 --- a/src/Resources/ModerationApi.php +++ b/src/Resources/ModerationApi.php @@ -13,7 +13,7 @@ class ModerationApi extends AbstractResource * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference/#get-banned-users */ - public function getBannedUsers(string $bearer, string $broadcasterId, array $ids = [], string $before = null, string $after = null): ResponseInterface + public function getBannedUsers(string $bearer, string $broadcasterId, array $ids = [], string $before = null, string $after = null, string $first = null): ResponseInterface { $queryParamsMap = []; @@ -31,6 +31,10 @@ public function getBannedUsers(string $bearer, string $broadcasterId, array $ids $queryParamsMap[] = ['key' => 'after', 'value' => $after]; } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + return $this->getApi('moderation/banned', $bearer, $queryParamsMap); } From d9516b8d527fe0684cd23fc3daa0d57acb6b5c70 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 5 Sep 2022 12:28:55 -0300 Subject: [PATCH 2/5] Add First Param to getModerators --- src/Resources/ModerationApi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Resources/ModerationApi.php b/src/Resources/ModerationApi.php index 8b15159..4ebb706 100644 --- a/src/Resources/ModerationApi.php +++ b/src/Resources/ModerationApi.php @@ -42,7 +42,7 @@ public function getBannedUsers(string $bearer, string $broadcasterId, array $ids * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference/#get-moderators */ - public function getModerators(string $bearer, string $broadcasterId, array $ids = [], string $after = null): ResponseInterface + public function getModerators(string $bearer, string $broadcasterId, array $ids = [], string $after = null, string $first = null): ResponseInterface { $queryParamsMap = []; @@ -56,6 +56,10 @@ public function getModerators(string $bearer, string $broadcasterId, array $ids $queryParamsMap[] = ['key' => 'after', 'value' => $after]; } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + return $this->getApi('moderation/moderators', $bearer, $queryParamsMap); } From 71ef12ec6c12cee6c217e243a38bbb2ff5b192d6 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 5 Sep 2022 12:43:46 -0300 Subject: [PATCH 3/5] Add EventSub -> drop.entitlement.grant --- src/Resources/EventSubApi.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Resources/EventSubApi.php b/src/Resources/EventSubApi.php index 715e8b4..c6e0877 100644 --- a/src/Resources/EventSubApi.php +++ b/src/Resources/EventSubApi.php @@ -443,6 +443,29 @@ public function subscribeToChannelGoalEnd(string $bearer, string $secret, string return $this->subscribeToChannelGoal($bearer, $secret, $callback, $twitchId, 'end'); } + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#dropentitlementgrant + */ + public function subscribeToDropEntitlementGrant(string $bearer, string $secret, string $callback, string $organizationId, string $categoryId = null, string $campaign_id = null): ResponseInterface + { + $condition = ['organization_id' => $organizationId]; + if ($categoryId) { + $condition['category_id'] = $categoryId; + } + if ($campaign_id) { + $condition['campaign_id'] = $campaign_id; + } + + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'drop.entitlement.grant', + '1', + $condition, + ); + } + /** * @link https://dev.twitch.tv/docs/eventsub#verify-a-signature */ From 0c36e6d47738c72a022e4c6528688fe6180a4059 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 5 Sep 2022 12:44:10 -0300 Subject: [PATCH 4/5] Allow Body Params to be Optional in updateDropEntitlements --- src/Resources/EntitlementsApi.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Resources/EntitlementsApi.php b/src/Resources/EntitlementsApi.php index 677de08..f6b5a89 100644 --- a/src/Resources/EntitlementsApi.php +++ b/src/Resources/EntitlementsApi.php @@ -78,8 +78,13 @@ public function updateDropsEntitlements(string $bearer, array $entitlement_ids = { $bodyParamsMap = []; - $bodyParamsMap[] = ['key' => 'entitlement_ids', 'value' => $entitlement_ids]; - $bodyParamsMap[] = ['key' => 'fulfillment_status', 'value' => $fulfillment_status]; + if ($entitlement_ids) { + $bodyParamsMap[] = ['key' => 'entitlement_ids', 'value' => $entitlement_ids]; + } + + if ($fulfillment_status) { + $bodyParamsMap[] = ['key' => 'fulfillment_status', 'value' => $fulfillment_status]; + } return $this->patchApi('entitlements/drops', $bearer, [], $bodyParamsMap); } From 4ff585293e739bbf13a3ecad18c699eec00f84bd Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Mon, 5 Sep 2022 12:54:34 -0300 Subject: [PATCH 5/5] Adding Missing Specs --- spec/TwitchApi/Resources/BitsApiSpec.php | 12 +++ spec/TwitchApi/Resources/ClipsApiSpec.php | 78 +++++++++++++++++++ .../Resources/EntitlementsApiSpec.php | 18 +++++ spec/TwitchApi/Resources/EventSubApiSpec.php | 12 +++ .../TwitchApi/Resources/ModerationApiSpec.php | 24 ++++++ spec/TwitchApi/Resources/SearchApiSpec.php | 42 ++++++++++ spec/TwitchApi/TwitchApiSpec.php | 22 +++++- 7 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 spec/TwitchApi/Resources/ClipsApiSpec.php create mode 100644 spec/TwitchApi/Resources/SearchApiSpec.php diff --git a/spec/TwitchApi/Resources/BitsApiSpec.php b/spec/TwitchApi/Resources/BitsApiSpec.php index aa6d952..355696e 100644 --- a/spec/TwitchApi/Resources/BitsApiSpec.php +++ b/spec/TwitchApi/Resources/BitsApiSpec.php @@ -51,4 +51,16 @@ function it_should_extension_transactions_with_after(RequestGenerator $requestGe $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'after', 'value' => '100']], [])->willReturn($request); $this->getExtensionTransactions('TEST_TOKEN', '1', [], null, 100)->shouldBe($response); } + + function it_should_get_bits_leaderboard(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'bits/leaderboard', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getBitsLeaderboard('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_bits_leaderboard_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'bits/leaderboard', 'TEST_TOKEN', [['key' => 'count', 'value' => '100'], ['key' => 'period', 'value' => 'all'], ['key' => 'started_at', 'value' => '2019-10-12T07:20:50.52Z'], ['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getBitsLeaderboard('TEST_TOKEN', 100, 'all', '2019-10-12T07:20:50.52Z', '123')->shouldBe($response); + } } diff --git a/spec/TwitchApi/Resources/ClipsApiSpec.php b/spec/TwitchApi/Resources/ClipsApiSpec.php new file mode 100644 index 0000000..f82ded6 --- /dev/null +++ b/spec/TwitchApi/Resources/ClipsApiSpec.php @@ -0,0 +1,78 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_clips_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getClips('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_clips_by_broadcaster_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getClipsByBroadcasterId('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_clips_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getClips('TEST_TOKEN', null, '123')->shouldBe($response); + } + + function it_should_get_clips_by_game_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getClipsByGameId('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_one_clip_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getClips('TEST_TOKEN', null, null, '123')->shouldBe($response); + } + + function it_should_get_one_clip_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getClipsByIds('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_multiple_clips_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123,456']], [])->willReturn($request); + $this->getClips('TEST_TOKEN', null, null, '123,456')->shouldBe($response); + } + + function it_should_get_multiple_clips_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'id', 'value' => '123,456']], [])->willReturn($request); + $this->getClipsByIds('TEST_TOKEN', '123,456')->shouldBe($response); + } + + function it_should_get_clips_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => '10'], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'started_at', 'value' => '2018-10-12T07:20:50.52Z'], ['key' => 'ended_at', 'value' => '2019-10-12T07:20:50.52Z']], [])->willReturn($request); + $this->getClips('TEST_TOKEN', '123', null, null, 10, 'abc', 'def', '2018-10-12T07:20:50.52Z', '2019-10-12T07:20:50.52Z')->shouldBe($response); + } + + function it_should_create_a_clip(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'clips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'has_delay', 'value' => 'true']], [])->willReturn($request); + $this->createClip('TEST_TOKEN', '123', true)->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/EntitlementsApiSpec.php b/spec/TwitchApi/Resources/EntitlementsApiSpec.php index f86b34b..71d7ca8 100644 --- a/spec/TwitchApi/Resources/EntitlementsApiSpec.php +++ b/spec/TwitchApi/Resources/EntitlementsApiSpec.php @@ -81,4 +81,22 @@ function it_should_redeem_codes(RequestGenerator $requestGenerator, Request $req $requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request); $this->redeemCode('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response); } + + function it_should_update_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [])->willReturn($request); + $this->updateDropsEntitlements('TEST_TOKEN')->shouldBe($response); + } + + function it_should_update_one_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [['key' => 'entitlement_ids', 'value' => ['123']], ['key' => 'fulfillment_status', 'value' => 'FULFILLED']])->willReturn($request); + $this->updateDropsEntitlements('TEST_TOKEN', ['123'], 'FULFILLED')->shouldBe($response); + } + + function it_should_update_multiple_drop_entitlements(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'entitlements/drops', 'TEST_TOKEN', [], [['key' => 'entitlement_ids', 'value' => ['123', '456']], ['key' => 'fulfillment_status', 'value' => 'FULFILLED']])->willReturn($request); + $this->updateDropsEntitlements('TEST_TOKEN', ['123', '456'], 'FULFILLED')->shouldBe($response); + } } diff --git a/spec/TwitchApi/Resources/EventSubApiSpec.php b/spec/TwitchApi/Resources/EventSubApiSpec.php index b8b5467..4c28bcc 100644 --- a/spec/TwitchApi/Resources/EventSubApiSpec.php +++ b/spec/TwitchApi/Resources/EventSubApiSpec.php @@ -288,4 +288,16 @@ function it_should_subscribe_to_channel_goal_end(RequestGenerator $requestGenera $this->createEventSubSubscription('channel.goal.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); $this->subscribeToChannelGoalEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); } + + function it_should_subscribe_to_drop_entitelement_grant(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_drop_entitelement_grant_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '123', 'category_id' => '456', 'campaign_id' => '789'], $requestGenerator)->willReturn($request); + $this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '123', '456', '789')->shouldBe($response); + } } diff --git a/spec/TwitchApi/Resources/ModerationApiSpec.php b/spec/TwitchApi/Resources/ModerationApiSpec.php index d0f3a75..78052c3 100644 --- a/spec/TwitchApi/Resources/ModerationApiSpec.php +++ b/spec/TwitchApi/Resources/ModerationApiSpec.php @@ -147,4 +147,28 @@ function it_should_remove_vip_for_a_channel(RequestGenerator $requestGenerator, $requestGenerator->generate('DELETE', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request); $this->removeChannelVip('TEST_TOKEN', '123', '456')->shouldBe($response); } + + function it_should_get_banned_users(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'moderation/banned', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getBannedUsers('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_banned_users_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'moderation/banned', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => 'abc'], ['key' => 'user_id', 'value' => 'def'], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'first', 'value' => '100']], [])->willReturn($request); + $this->getBannedUsers('TEST_TOKEN', '123', ['abc', 'def'], 'abc', 'def', '100')->shouldBe($response); + } + + function it_should_get_moderators(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getModerators('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_moderators_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => 'abc'], ['key' => 'user_id', 'value' => 'def'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => '100']], [])->willReturn($request); + $this->getModerators('TEST_TOKEN', '123', ['abc', 'def'], 'abc', '100')->shouldBe($response); + } } diff --git a/spec/TwitchApi/Resources/SearchApiSpec.php b/spec/TwitchApi/Resources/SearchApiSpec.php new file mode 100644 index 0000000..0945f33 --- /dev/null +++ b/spec/TwitchApi/Resources/SearchApiSpec.php @@ -0,0 +1,42 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_search_categories(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'search/categories', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test']], [])->willReturn($request); + $this->searchCategories('TEST_TOKEN', 'test')->shouldBe($response); + } + + function it_should_search_categories_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'search/categories', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->searchCategories('TEST_TOKEN', 'test', 100, 'abc')->shouldBe($response); + } + + function it_should_search_channels(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'search/channels', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test']], [])->willReturn($request); + $this->searchChannels('TEST_TOKEN', 'test')->shouldBe($response); + } + + function it_should_search_channels_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'search/channels', 'TEST_TOKEN', [['key' => 'query', 'value' => 'test'], ['key' => 'live_only', 'value' => true], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->searchChannels('TEST_TOKEN', 'test', true, 100, 'abc')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/TwitchApiSpec.php b/spec/TwitchApi/TwitchApiSpec.php index 94f6aa2..a9d7520 100644 --- a/spec/TwitchApi/TwitchApiSpec.php +++ b/spec/TwitchApi/TwitchApiSpec.php @@ -10,6 +10,8 @@ use TwitchApi\Resources\BitsApi; use TwitchApi\Resources\ChannelPointsApi; use TwitchApi\Resources\ChannelsApi; +use TwitchApi\Resources\ChatApi; +use TwitchApi\Resources\ClipsApi; use TwitchApi\Resources\EntitlementsApi; use TwitchApi\Resources\EventSubApi; use TwitchApi\Resources\GamesApi; @@ -19,6 +21,7 @@ use TwitchApi\Resources\PredictionsApi; use TwitchApi\Resources\RaidsApi; use TwitchApi\Resources\ScheduleApi; +use TwitchApi\Resources\SearchApi; use TwitchApi\Resources\StreamsApi; use TwitchApi\Resources\SubscriptionsApi; use TwitchApi\Resources\TagsApi; @@ -67,6 +70,16 @@ function it_should_provide_channels_api() $this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class); } + function it_should_provide_chat_api() + { + $this->getChatApi()->shouldBeAnInstanceOf(ChatApi::class); + } + + function it_should_provide_clips_api() + { + $this->getClipsApi()->shouldBeAnInstanceOf(ClipsApi::class); + } + function it_should_provide_entitlements_api() { $this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class); @@ -111,9 +124,9 @@ function it_should_provide_schedule_api() $this->getScheduleApi()->shouldBeAnInstanceOf(ScheduleApi::class); } - function it_should_provide_subscriptions_api() + function it_should_provide_search_api() { - $this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class); + $this->getSearchApi()->shouldBeAnInstanceOf(SearchApi::class); } function it_should_provide_streams_api() @@ -121,6 +134,11 @@ function it_should_provide_streams_api() $this->getStreamsApi()->shouldBeAnInstanceOf(StreamsApi::class); } + function it_should_provide_subscriptions_api() + { + $this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class); + } + function it_should_provide_tags_api() { $this->getTagsApi()->shouldBeAnInstanceOf(TagsApi::class);