Skip to content

Commit 730b695

Browse files
authored
Merge pull request #109 from brandinarsenault/mar-2021-update
Add Endpoints for March 2021
2 parents 8ab26c5 + a0e0956 commit 730b695

File tree

8 files changed

+215
-1
lines changed

8 files changed

+215
-1
lines changed

spec/NewTwitchApi/NewTwitchApiSpec.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use NewTwitchApi\Resources\AnalyticsApi;
88
use NewTwitchApi\Resources\BitsApi;
99
use NewTwitchApi\Resources\ChannelPointsApi;
10+
use NewTwitchApi\Resources\ChannelsApi;
1011
use NewTwitchApi\Resources\EntitlementsApi;
1112
use NewTwitchApi\Resources\GamesApi;
1213
use NewTwitchApi\Resources\ModerationApi;
@@ -15,6 +16,7 @@
1516
use NewTwitchApi\Resources\TagsApi;
1617
use NewTwitchApi\Resources\TeamsApi;
1718
use NewTwitchApi\Resources\UsersApi;
19+
use NewTwitchApi\Resources\VideosApi;
1820
use NewTwitchApi\Resources\WebhooksApi;
1921
use NewTwitchApi\Webhooks\WebhooksSubscriptionApi;
2022
use PhpSpec\ObjectBehavior;
@@ -46,6 +48,11 @@ function it_should_provide_channel_points_api()
4648
$this->getChannelPointsApi()->shouldBeAnInstanceOf(ChannelPointsApi::class);
4749
}
4850

51+
function it_should_provide_channels_api()
52+
{
53+
$this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class);
54+
}
55+
4956
function it_should_provide_entitlements_api()
5057
{
5158
$this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class);
@@ -55,7 +62,7 @@ function it_should_provide_games_api()
5562
{
5663
$this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class);
5764
}
58-
65+
5966
function it_should_provide_subscriptions_api()
6067
{
6168
$this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class);
@@ -81,6 +88,11 @@ function it_should_provide_users_api()
8188
$this->getUsersApi()->shouldBeAnInstanceOf(UsersApi::class);
8289
}
8390

91+
function it_should_provide_videos_api()
92+
{
93+
$this->getVideosApi()->shouldBeAnInstanceOf(VideosApi::class);
94+
}
95+
8496
function it_should_provide_webhooks_api()
8597
{
8698
$this->getWebhooksApi()->shouldBeAnInstanceOf(WebhooksApi::class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace spec\NewTwitchApi\Resources;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Psr7\Request;
7+
use GuzzleHttp\Psr7\Response;
8+
use PhpSpec\ObjectBehavior;
9+
use Psr\Http\Message\ResponseInterface;
10+
11+
class ChannelsApiSpec extends ObjectBehavior
12+
{
13+
function let(Client $guzzleClient)
14+
{
15+
$this->beConstructedWith($guzzleClient);
16+
}
17+
18+
function it_should_get_channel_info(Client $guzzleClient, Response $response)
19+
{
20+
$guzzleClient->send(new Request('GET', 'channels?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
21+
$this->getChannelInfo('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
22+
}
23+
24+
function it_should_get_channel_editors(Client $guzzleClient, Response $response)
25+
{
26+
$guzzleClient->send(new Request('GET', 'channels/editors?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
27+
$this->getChannelEditors('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
28+
}
29+
}

spec/NewTwitchApi/Resources/UsersApiSpec.php

+30
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,34 @@ function it_should_update_user_description(Client $guzzleClient, Response $respo
140140
$guzzleClient->send(new Request('PUT', 'users?description=test', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
141141
$this->updateUser('TEST_TOKEN', 'test')->shouldBeAnInstanceOf(ResponseInterface::class);
142142
}
143+
144+
function it_should_get_user_block_list(Client $guzzleClient, Response $response)
145+
{
146+
$guzzleClient->send(new Request('GET', 'users/blocks?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
147+
$this->getUserBlockList('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
148+
}
149+
150+
function it_should_get_user_block_list_with_opts(Client $guzzleClient, Response $response)
151+
{
152+
$guzzleClient->send(new Request('GET', 'users/blocks?broadcaster_id=123&first=100&after=abc', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
153+
$this->getUserBlockList('TEST_TOKEN', '123', 100, 'abc')->shouldBeAnInstanceOf(ResponseInterface::class);
154+
}
155+
156+
function it_should_block_user(Client $guzzleClient, Response $response)
157+
{
158+
$guzzleClient->send(new Request('PUT', 'users/blocks?target_user_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
159+
$this->blockUser('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
160+
}
161+
162+
function it_should_block_user_with_opts(Client $guzzleClient, Response $response)
163+
{
164+
$guzzleClient->send(new Request('PUT', 'users/blocks?target_user_id=123&source_context=chat&reason=spam', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
165+
$this->blockUser('TEST_TOKEN', '123', 'chat', 'spam')->shouldBeAnInstanceOf(ResponseInterface::class);
166+
}
167+
168+
function it_should_unblock_user(Client $guzzleClient, Response $response)
169+
{
170+
$guzzleClient->send(new Request('DELETE', 'users/blocks?target_user_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
171+
$this->unblockUser('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
172+
}
143173
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace spec\NewTwitchApi\Resources;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Psr7\Request;
7+
use GuzzleHttp\Psr7\Response;
8+
use PhpSpec\ObjectBehavior;
9+
use Psr\Http\Message\ResponseInterface;
10+
11+
class VideosApiSpec extends ObjectBehavior
12+
{
13+
function let(Client $guzzleClient)
14+
{
15+
$this->beConstructedWith($guzzleClient);
16+
}
17+
18+
function it_should_delete_videos(Client $guzzleClient, Response $response)
19+
{
20+
$guzzleClient->send(new Request('DELETE', 'videos?id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
21+
$this->deleteVideos('TEST_TOKEN', ['123'])->shouldBeAnInstanceOf(ResponseInterface::class);
22+
}
23+
24+
function it_should_delete_multiple_videos(Client $guzzleClient, Response $response)
25+
{
26+
$guzzleClient->send(new Request('DELETE', 'videos?id=123&id=321', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
27+
$this->deleteVideos('TEST_TOKEN', ['123', '321'])->shouldBeAnInstanceOf(ResponseInterface::class);
28+
}
29+
}

src/NewTwitchApi/NewTwitchApi.php

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use NewTwitchApi\Resources\AnalyticsApi;
1010
use NewTwitchApi\Resources\BitsApi;
1111
use NewTwitchApi\Resources\ChannelPointsApi;
12+
use NewTwitchApi\Resources\ChannelsApi;
1213
use NewTwitchApi\Resources\ClipsApi;
1314
use NewTwitchApi\Resources\EntitlementsApi;
1415
use NewTwitchApi\Resources\GamesApi;
@@ -30,6 +31,7 @@ class NewTwitchApi
3031
private $analyticsApi;
3132
private $bitsApi;
3233
private $channelPointsApi;
34+
private $channelsApi;
3335
private $clipsApi;
3436
private $entitlementsApi;
3537
private $gamesApi;
@@ -51,6 +53,7 @@ public function __construct(Client $helixGuzzleClient, string $clientId, string
5153
$this->analyticsApi = new AnalyticsApi($helixGuzzleClient);
5254
$this->bitsApi = new BitsApi($helixGuzzleClient);
5355
$this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient);
56+
$this->channelsApi = new ChannelsApi($helixGuzzleClient);
5457
$this->clipsApi = new ClipsApi($helixGuzzleClient);
5558
$this->entitlementsApi = new EntitlementsApi($helixGuzzleClient);
5659
$this->gamesApi = new GamesApi($helixGuzzleClient);
@@ -87,6 +90,11 @@ public function getChannelPointsApi(): ChannelPointsApi
8790
return $this->channelPointsApi;
8891
}
8992

93+
public function getChannelsApi(): ChannelsApi
94+
{
95+
return $this->channelsApi;
96+
}
97+
9098
public function getClipsApi(): ClipsApi
9199
{
92100
return $this->clipsApi;
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NewTwitchApi\Resources;
6+
7+
use GuzzleHttp\Exception\GuzzleException;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class ChannelsApi extends AbstractResource
11+
{
12+
/**
13+
* @throws GuzzleException
14+
* @link https://dev.twitch.tv/docs/api/reference#get-channel-information
15+
*/
16+
public function getChannelInfo(string $bearer, string $broadcasterId): ResponseInterface
17+
{
18+
$queryParamsMap = [];
19+
20+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
21+
22+
return $this->getApi('channels', $bearer, $queryParamsMap);
23+
}
24+
25+
/**
26+
* @throws GuzzleException
27+
* @link https://dev.twitch.tv/docs/api/reference#get-channel-editors
28+
*/
29+
public function getChannelEditors(string $bearer, string $broadcasterId): ResponseInterface
30+
{
31+
$queryParamsMap = [];
32+
33+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
34+
35+
return $this->getApi('channels/editors', $bearer, $queryParamsMap);
36+
}
37+
}

src/NewTwitchApi/Resources/UsersApi.php

+54
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,58 @@ public function updateUser(string $bearer, string $description = null): Response
150150

151151
return $this->putApi('users', $bearer, $queryParamsMap);
152152
}
153+
154+
/**
155+
* @throws GuzzleException
156+
* @link https://dev.twitch.tv/docs/api/reference#get-user-block-list
157+
*/
158+
public function getUserBlockList(string $bearer, string $broadcasterId, int $first = null, string $after = null): ResponseInterface
159+
{
160+
$queryParamsMap = [];
161+
162+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
163+
164+
if ($first) {
165+
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
166+
}
167+
if ($after) {
168+
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
169+
}
170+
171+
return $this->getApi('users/blocks', $bearer, $queryParamsMap);
172+
}
173+
174+
/**
175+
* @throws GuzzleException
176+
* @link https://dev.twitch.tv/docs/api/reference#block-user
177+
*/
178+
public function blockUser(string $bearer, string $targetUserId, string $sourceContext = null, string $reason = null): ResponseInterface
179+
{
180+
$queryParamsMap = [];
181+
182+
$queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId];
183+
184+
if ($sourceContext) {
185+
$queryParamsMap[] = ['key' => 'source_context', 'value' => $sourceContext];
186+
}
187+
188+
if ($reason) {
189+
$queryParamsMap[] = ['key' => 'reason', 'value' => $reason];
190+
}
191+
192+
return $this->putApi('users/blocks', $bearer, $queryParamsMap);
193+
}
194+
195+
/**
196+
* @throws GuzzleException
197+
* @link https://dev.twitch.tv/docs/api/reference#unblock-user
198+
*/
199+
public function unblockUser(string $bearer, string $targetUserId): ResponseInterface
200+
{
201+
$queryParamsMap = [];
202+
203+
$queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId];
204+
205+
return $this->deleteApi('users/blocks', $bearer, $queryParamsMap);
206+
}
153207
}

src/NewTwitchApi/Resources/VideosApi.php

+15
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ public function getVideos(string $bearer, array $ids = [], string $userId = null
5959

6060
return $this->getApi('videos', $bearer, $queryParamsMap);
6161
}
62+
63+
/**
64+
* @throws GuzzleException
65+
* @link https://dev.twitch.tv/docs/api/reference#delete-videos
66+
*/
67+
public function deleteVideos(string $bearer, array $ids = []): ResponseInterface
68+
{
69+
$queryParamsMap = [];
70+
71+
foreach ($ids as $id) {
72+
$queryParamsMap[] = ['key' => 'id', 'value' => $id];
73+
}
74+
75+
return $this->deleteApi('videos', $bearer, $queryParamsMap);
76+
}
6277
}

0 commit comments

Comments
 (0)