Skip to content

Commit 201c00d

Browse files
authored
Merge pull request #148 from nicklaw5/v7.1.0
2 parents fdad08a + d5087a9 commit 201c00d

10 files changed

+280
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace spec\TwitchApi\Resources;
4+
5+
use GuzzleHttp\Psr7\Request;
6+
use GuzzleHttp\Psr7\Response;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
9+
use PhpSpec\ObjectBehavior;
10+
11+
class CharityApiSpec extends ObjectBehavior
12+
{
13+
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
14+
{
15+
$this->beConstructedWith($guzzleClient, $requestGenerator);
16+
$guzzleClient->send($request)->willReturn($response);
17+
}
18+
19+
function it_should_get_charity_campaigns(RequestGenerator $requestGenerator, Request $request, Response $response)
20+
{
21+
$requestGenerator->generate('GET', 'charity/campaigns', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
22+
$this->getCharityCampaign('TEST_TOKEN', '123')->shouldBe($response);
23+
}
24+
25+
function it_should_get_charity_campaign_donations(RequestGenerator $requestGenerator, Request $request, Response $response)
26+
{
27+
$requestGenerator->generate('GET', 'charity/donations', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
28+
$this->getCharityCampaignDonations('TEST_TOKEN', '123')->shouldBe($response);
29+
}
30+
31+
function it_should_get_charity_campaign_donations_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
32+
{
33+
$requestGenerator->generate('GET', 'charity/donations', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
34+
$this->getCharityCampaignDonations('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response);
35+
}
36+
}

spec/TwitchApi/Resources/ChatApiSpec.php

+12
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ function it_should_update_a_users_chat_color(RequestGenerator $requestGenerator,
105105
$requestGenerator->generate('PUT', 'chat/color', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'color', 'value' => 'red']], [])->willReturn($request);
106106
$this->updateUserChatColor('TEST_TOKEN', '123', 'red')->shouldBe($response);
107107
}
108+
109+
function it_should_get_chatters(RequestGenerator $requestGenerator, Request $request, Response $response)
110+
{
111+
$requestGenerator->generate('GET', 'chat/chatters', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [])->willReturn($request);
112+
$this->getChatters('TEST_TOKEN', '123', '456')->shouldBe($response);
113+
}
114+
115+
function it_should_get_chatters_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
116+
{
117+
$requestGenerator->generate('GET', 'chat/chatters', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456'],['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
118+
$this->getChatters('TEST_TOKEN', '123', '456', 100, 'abc')->shouldBe($response);
119+
}
108120
}

spec/TwitchApi/Resources/EventSubApiSpec.php

+36
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,40 @@ function it_should_subscribe_to_drop_entitelement_grant_with_opts(RequestGenerat
300300
$this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '123', 'category_id' => '456', 'campaign_id' => '789'], $requestGenerator)->willReturn($request);
301301
$this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '123', '456', '789')->shouldBe($response);
302302
}
303+
304+
function it_should_subscribe_to_channel_charity_campaign_start(RequestGenerator $requestGenerator, Request $request, Response $response)
305+
{
306+
$this->createEventSubSubscription('channel.charity_campaign.start', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
307+
$this->subscribeToChannelCharityCampaignStart($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
308+
}
309+
310+
function it_should_subscribe_to_channel_charity_campaign_progress(RequestGenerator $requestGenerator, Request $request, Response $response)
311+
{
312+
$this->createEventSubSubscription('channel.charity_campaign.progress', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
313+
$this->subscribeToChannelCharityCampaignProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
314+
}
315+
316+
function it_should_subscribe_to_channel_charity_campaign_stop(RequestGenerator $requestGenerator, Request $request, Response $response)
317+
{
318+
$this->createEventSubSubscription('channel.charity_campaign.stop', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
319+
$this->subscribeToChannelCharityCampaignStop($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
320+
}
321+
322+
function it_should_subscribe_to_channel_charity_campaign_donate(RequestGenerator $requestGenerator, Request $request, Response $response)
323+
{
324+
$this->createEventSubSubscription('channel.charity_campaign.donate', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
325+
$this->subscribeToChannelCharityCampaignDonate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
326+
}
327+
328+
function it_should_subscribe_to_channel_shield_mode_begin(RequestGenerator $requestGenerator, Request $request, Response $response)
329+
{
330+
$this->createEventSubSubscription('channel.shield_mode.begin', 'beta', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
331+
$this->subscribeToChannelShieldModeBegin($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
332+
}
333+
334+
function it_should_subscribe_to_channel_shield_mode_end(RequestGenerator $requestGenerator, Request $request, Response $response)
335+
{
336+
$this->createEventSubSubscription('channel.shield_mode.end', 'beta', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
337+
$this->subscribeToChannelShieldModeEnd($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
338+
}
303339
}

spec/TwitchApi/Resources/ModerationApiSpec.php

+12
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,16 @@ function it_should_get_moderators_with_opts(RequestGenerator $requestGenerator,
171171
$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);
172172
$this->getModerators('TEST_TOKEN', '123', ['abc', 'def'], 'abc', '100')->shouldBe($response);
173173
}
174+
175+
function it_should_get_shield_mode_status(RequestGenerator $requestGenerator, Request $request, Response $response)
176+
{
177+
$requestGenerator->generate('GET', 'moderation/shield_mode', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [])->willReturn($request);
178+
$this->getShieldModeStatus('TEST_TOKEN', '123', '456')->shouldBe($response);
179+
}
180+
181+
function it_should_update_shield_mode_status(RequestGenerator $requestGenerator, Request $request, Response $response)
182+
{
183+
$requestGenerator->generate('PUT', 'moderation/shield_mode', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456']], [['key' => 'is_active', 'value' => true]])->willReturn($request);
184+
$this->updateShieldModeStatus('TEST_TOKEN', '123', '456', true)->shouldBe($response);
185+
}
174186
}

spec/TwitchApi/TwitchApiSpec.php

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TwitchApi\Resources\BitsApi;
1111
use TwitchApi\Resources\ChannelPointsApi;
1212
use TwitchApi\Resources\ChannelsApi;
13+
use TwitchApi\Resources\CharityApi;
1314
use TwitchApi\Resources\ChatApi;
1415
use TwitchApi\Resources\ClipsApi;
1516
use TwitchApi\Resources\EntitlementsApi;
@@ -70,6 +71,11 @@ function it_should_provide_channels_api()
7071
$this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class);
7172
}
7273

74+
function it_should_provide_charity_api()
75+
{
76+
$this->getCharityApi()->shouldBeAnInstanceOf(CharityApi::class);
77+
}
78+
7379
function it_should_provide_chat_api()
7480
{
7581
$this->getChatApi()->shouldBeAnInstanceOf(ChatApi::class);

src/Resources/CharityApi.php

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TwitchApi\Resources;
6+
7+
use GuzzleHttp\Exception\GuzzleException;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class CharityApi extends AbstractResource
11+
{
12+
/**
13+
* @throws GuzzleException
14+
* @link https://dev.twitch.tv/docs/api/reference#get-charity-campaign
15+
*/
16+
public function getCharityCampaign(string $bearer, string $broadcasterId): ResponseInterface
17+
{
18+
$queryParamsMap = [];
19+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
20+
21+
return $this->getApi('charity/campaigns', $bearer, $queryParamsMap);
22+
}
23+
24+
/**
25+
* @throws GuzzleException
26+
* @link https://dev.twitch.tv/docs/api/reference#get-charity-campaign-donations
27+
*/
28+
public function getCharityCampaignDonations(string $bearer, string $broadcasterId, int $first = null, string $after = null): ResponseInterface
29+
{
30+
$queryParamsMap = [];
31+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
32+
33+
if ($first) {
34+
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
35+
}
36+
37+
if ($after) {
38+
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
39+
}
40+
41+
return $this->getApi('charity/donations', $bearer, $queryParamsMap);
42+
}
43+
}

src/Resources/ChatApi.php

+23
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,27 @@ public function updateUserChatColor(string $bearer, string $userId, string $colo
156156

157157
return $this->putApi('chat/color', $bearer, $queryParamsMap);
158158
}
159+
160+
/**
161+
* @throws GuzzleException
162+
* @link https://dev.twitch.tv/docs/api/reference#get-chatters
163+
*/
164+
public function getChatters(string $bearer, string $broadcasterId, string $moderatorId, int $first = null, string $after = null): ResponseInterface
165+
{
166+
$queryParamsMap = [];
167+
168+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
169+
170+
$queryParamsMap[] = ['key' => 'moderator_id', 'value' => $moderatorId];
171+
172+
if ($first) {
173+
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
174+
}
175+
176+
if ($after) {
177+
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
178+
}
179+
180+
return $this->getApi('chat/chatters', $bearer, $queryParamsMap);
181+
}
159182
}

src/Resources/EventSubApi.php

+75
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,54 @@ public function subscribeToChannelGoalEnd(string $bearer, string $secret, string
443443
return $this->subscribeToChannelGoal($bearer, $secret, $callback, $twitchId, 'end');
444444
}
445445

446+
/**
447+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcharity_campaignstart
448+
*/
449+
public function subscribeToChannelCharityCampaignStart(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface
450+
{
451+
return $this->subscribeToChannelCharityCampaign($bearer, $secret, $callback, $twitchId, 'start');
452+
}
453+
454+
/**
455+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcharity_campaignprogress
456+
*/
457+
public function subscribeToChannelCharityCampaignProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface
458+
{
459+
return $this->subscribeToChannelCharityCampaign($bearer, $secret, $callback, $twitchId, 'progress');
460+
}
461+
462+
/**
463+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcharity_campaignstop
464+
*/
465+
public function subscribeToChannelCharityCampaignStop(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface
466+
{
467+
return $this->subscribeToChannelCharityCampaign($bearer, $secret, $callback, $twitchId, 'stop');
468+
}
469+
470+
/**
471+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcharity_campaigndonate
472+
*/
473+
public function subscribeToChannelCharityCampaignDonate(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface
474+
{
475+
return $this->subscribeToChannelCharityCampaign($bearer, $secret, $callback, $twitchId, 'donate');
476+
}
477+
478+
/**
479+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelshield_modebegin
480+
*/
481+
public function subscribeToChannelShieldModeBegin(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId): ResponseInterface
482+
{
483+
return $this->subscribeToChannelShieldMode($bearer, $secret, $callback, $twitchId, $moderatorId, 'begin');
484+
}
485+
486+
/**
487+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelshield_modeend
488+
*/
489+
public function subscribeToChannelShieldModeEnd(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId): ResponseInterface
490+
{
491+
return $this->subscribeToChannelShieldMode($bearer, $secret, $callback, $twitchId, $moderatorId, 'end');
492+
}
493+
446494
/**
447495
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#dropentitlementgrant
448496
*/
@@ -600,4 +648,31 @@ private function subscribeToChannelGoal(string $bearer, string $secret, string $
600648
['broadcaster_user_id' => $twitchId],
601649
);
602650
}
651+
652+
private function subscribeToChannelCharityCampaign(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface
653+
{
654+
return $this->createEventSubSubscription(
655+
$bearer,
656+
$secret,
657+
$callback,
658+
sprintf('channel.charity_campaign.%s', $eventType),
659+
'beta',
660+
['broadcaster_user_id' => $twitchId],
661+
);
662+
}
663+
664+
private function subscribeToChannelShieldMode(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId, string $eventType): ResponseInterface
665+
{
666+
return $this->createEventSubSubscription(
667+
$bearer,
668+
$secret,
669+
$callback,
670+
sprintf('channel.shield_mode.%s', $eventType),
671+
'beta',
672+
[
673+
'broadcaster_user_id' => $twitchId,
674+
'moderator_user_id' => $moderatorId,
675+
],
676+
);
677+
}
603678
}

src/Resources/ModerationApi.php

+29
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,33 @@ public function removeChannelVip(string $bearer, string $broadcasterId, string $
306306

307307
return $this->deleteApi('channels/vips', $bearer, $queryParamsMap);
308308
}
309+
310+
/**
311+
* @throws GuzzleException
312+
* @link https://dev.twitch.tv/docs/api/reference#get-shield-mode-status
313+
*/
314+
public function getShieldModeStatus(string $bearer, string $broadcasterId, string $moderatorId): ResponseInterface
315+
{
316+
$queryParamsMap = [];
317+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
318+
$queryParamsMap[] = ['key' => 'moderator_id', 'value' => $moderatorId];
319+
320+
return $this->getApi('moderation/shield_mode', $bearer, $queryParamsMap);
321+
}
322+
323+
/**
324+
* @throws GuzzleException
325+
* @link https://dev.twitch.tv/docs/api/reference#update-shield-mode-status
326+
*/
327+
public function updateShieldModeStatus(string $bearer, string $broadcasterId, string $moderatorId, bool $isActive): ResponseInterface
328+
{
329+
$queryParamsMap = [];
330+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
331+
$queryParamsMap[] = ['key' => 'moderator_id', 'value' => $moderatorId];
332+
333+
$bodyParamsMap = [];
334+
$bodyParamsMap[] = ['key' => 'is_active', 'value' => $isActive];
335+
336+
return $this->putApi('moderation/shield_mode', $bearer, $queryParamsMap, $bodyParamsMap);
337+
}
309338
}

src/TwitchApi.php

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use TwitchApi\Resources\BitsApi;
1212
use TwitchApi\Resources\ChannelPointsApi;
1313
use TwitchApi\Resources\ChannelsApi;
14+
use TwitchApi\Resources\CharityApi;
1415
use TwitchApi\Resources\ChatApi;
1516
use TwitchApi\Resources\ClipsApi;
1617
use TwitchApi\Resources\EntitlementsApi;
@@ -41,6 +42,7 @@ class TwitchApi
4142
private $bitsApi;
4243
private $channelPointsApi;
4344
private $channelsApi;
45+
private $charityApi;
4446
private $chatApi;
4547
private $clipsApi;
4648
private $entitlementsApi;
@@ -72,6 +74,7 @@ public function __construct(HelixGuzzleClient $helixGuzzleClient, string $client
7274
$this->bitsApi = new BitsApi($helixGuzzleClient, $requestGenerator);
7375
$this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient, $requestGenerator);
7476
$this->channelsApi = new ChannelsApi($helixGuzzleClient, $requestGenerator);
77+
$this->charityApi = new CharityApi($helixGuzzleClient, $requestGenerator);
7578
$this->chatApi = new ChatApi($helixGuzzleClient, $requestGenerator);
7679
$this->clipsApi = new ClipsApi($helixGuzzleClient, $requestGenerator);
7780
$this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator);
@@ -125,6 +128,11 @@ public function getChannelsApi(): ChannelsApi
125128
return $this->channelsApi;
126129
}
127130

131+
public function getCharityApi(): CharityApi
132+
{
133+
return $this->charityApi;
134+
}
135+
128136
public function getChatApi(): ChatApi
129137
{
130138
return $this->chatApi;

0 commit comments

Comments
 (0)