Skip to content

Commit

Permalink
Merge pull request #109 from brandinarsenault/mar-2021-update
Browse files Browse the repository at this point in the history
Add Endpoints for March 2021
  • Loading branch information
Brandin authored Mar 23, 2021
2 parents 8ab26c5 + a0e0956 commit 730b695
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 1 deletion.
14 changes: 13 additions & 1 deletion spec/NewTwitchApi/NewTwitchApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use NewTwitchApi\Resources\AnalyticsApi;
use NewTwitchApi\Resources\BitsApi;
use NewTwitchApi\Resources\ChannelPointsApi;
use NewTwitchApi\Resources\ChannelsApi;
use NewTwitchApi\Resources\EntitlementsApi;
use NewTwitchApi\Resources\GamesApi;
use NewTwitchApi\Resources\ModerationApi;
Expand All @@ -15,6 +16,7 @@
use NewTwitchApi\Resources\TagsApi;
use NewTwitchApi\Resources\TeamsApi;
use NewTwitchApi\Resources\UsersApi;
use NewTwitchApi\Resources\VideosApi;
use NewTwitchApi\Resources\WebhooksApi;
use NewTwitchApi\Webhooks\WebhooksSubscriptionApi;
use PhpSpec\ObjectBehavior;
Expand Down Expand Up @@ -46,6 +48,11 @@ function it_should_provide_channel_points_api()
$this->getChannelPointsApi()->shouldBeAnInstanceOf(ChannelPointsApi::class);
}

function it_should_provide_channels_api()
{
$this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class);
}

function it_should_provide_entitlements_api()
{
$this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class);
Expand All @@ -55,7 +62,7 @@ function it_should_provide_games_api()
{
$this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class);
}

function it_should_provide_subscriptions_api()
{
$this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class);
Expand All @@ -81,6 +88,11 @@ function it_should_provide_users_api()
$this->getUsersApi()->shouldBeAnInstanceOf(UsersApi::class);
}

function it_should_provide_videos_api()
{
$this->getVideosApi()->shouldBeAnInstanceOf(VideosApi::class);
}

function it_should_provide_webhooks_api()
{
$this->getWebhooksApi()->shouldBeAnInstanceOf(WebhooksApi::class);
Expand Down
29 changes: 29 additions & 0 deletions spec/NewTwitchApi/Resources/ChannelsApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace spec\NewTwitchApi\Resources;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\ResponseInterface;

class ChannelsApiSpec extends ObjectBehavior
{
function let(Client $guzzleClient)
{
$this->beConstructedWith($guzzleClient);
}

function it_should_get_channel_info(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'channels?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getChannelInfo('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_get_channel_editors(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'channels/editors?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getChannelEditors('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}
}
30 changes: 30 additions & 0 deletions spec/NewTwitchApi/Resources/UsersApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,34 @@ function it_should_update_user_description(Client $guzzleClient, Response $respo
$guzzleClient->send(new Request('PUT', 'users?description=test', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->updateUser('TEST_TOKEN', 'test')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_get_user_block_list(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'users/blocks?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getUserBlockList('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_get_user_block_list_with_opts(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('GET', 'users/blocks?broadcaster_id=123&first=100&after=abc', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->getUserBlockList('TEST_TOKEN', '123', 100, 'abc')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_block_user(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('PUT', 'users/blocks?target_user_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->blockUser('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_block_user_with_opts(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('PUT', 'users/blocks?target_user_id=123&source_context=chat&reason=spam', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->blockUser('TEST_TOKEN', '123', 'chat', 'spam')->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_unblock_user(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('DELETE', 'users/blocks?target_user_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->unblockUser('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class);
}
}
29 changes: 29 additions & 0 deletions spec/NewTwitchApi/Resources/VideosApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace spec\NewTwitchApi\Resources;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\ResponseInterface;

class VideosApiSpec extends ObjectBehavior
{
function let(Client $guzzleClient)
{
$this->beConstructedWith($guzzleClient);
}

function it_should_delete_videos(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('DELETE', 'videos?id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->deleteVideos('TEST_TOKEN', ['123'])->shouldBeAnInstanceOf(ResponseInterface::class);
}

function it_should_delete_multiple_videos(Client $guzzleClient, Response $response)
{
$guzzleClient->send(new Request('DELETE', 'videos?id=123&id=321', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response);
$this->deleteVideos('TEST_TOKEN', ['123', '321'])->shouldBeAnInstanceOf(ResponseInterface::class);
}
}
8 changes: 8 additions & 0 deletions src/NewTwitchApi/NewTwitchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use NewTwitchApi\Resources\AnalyticsApi;
use NewTwitchApi\Resources\BitsApi;
use NewTwitchApi\Resources\ChannelPointsApi;
use NewTwitchApi\Resources\ChannelsApi;
use NewTwitchApi\Resources\ClipsApi;
use NewTwitchApi\Resources\EntitlementsApi;
use NewTwitchApi\Resources\GamesApi;
Expand All @@ -30,6 +31,7 @@ class NewTwitchApi
private $analyticsApi;
private $bitsApi;
private $channelPointsApi;
private $channelsApi;
private $clipsApi;
private $entitlementsApi;
private $gamesApi;
Expand All @@ -51,6 +53,7 @@ public function __construct(Client $helixGuzzleClient, string $clientId, string
$this->analyticsApi = new AnalyticsApi($helixGuzzleClient);
$this->bitsApi = new BitsApi($helixGuzzleClient);
$this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient);
$this->channelsApi = new ChannelsApi($helixGuzzleClient);
$this->clipsApi = new ClipsApi($helixGuzzleClient);
$this->entitlementsApi = new EntitlementsApi($helixGuzzleClient);
$this->gamesApi = new GamesApi($helixGuzzleClient);
Expand Down Expand Up @@ -87,6 +90,11 @@ public function getChannelPointsApi(): ChannelPointsApi
return $this->channelPointsApi;
}

public function getChannelsApi(): ChannelsApi
{
return $this->channelsApi;
}

public function getClipsApi(): ClipsApi
{
return $this->clipsApi;
Expand Down
37 changes: 37 additions & 0 deletions src/NewTwitchApi/Resources/ChannelsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace NewTwitchApi\Resources;

use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;

class ChannelsApi extends AbstractResource
{
/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-channel-information
*/
public function getChannelInfo(string $bearer, string $broadcasterId): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];

return $this->getApi('channels', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-channel-editors
*/
public function getChannelEditors(string $bearer, string $broadcasterId): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];

return $this->getApi('channels/editors', $bearer, $queryParamsMap);
}
}
54 changes: 54 additions & 0 deletions src/NewTwitchApi/Resources/UsersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,58 @@ public function updateUser(string $bearer, string $description = null): Response

return $this->putApi('users', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-user-block-list
*/
public function getUserBlockList(string $bearer, string $broadcasterId, int $first = null, string $after = null): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];

if ($first) {
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
}
if ($after) {
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
}

return $this->getApi('users/blocks', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#block-user
*/
public function blockUser(string $bearer, string $targetUserId, string $sourceContext = null, string $reason = null): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId];

if ($sourceContext) {
$queryParamsMap[] = ['key' => 'source_context', 'value' => $sourceContext];
}

if ($reason) {
$queryParamsMap[] = ['key' => 'reason', 'value' => $reason];
}

return $this->putApi('users/blocks', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#unblock-user
*/
public function unblockUser(string $bearer, string $targetUserId): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId];

return $this->deleteApi('users/blocks', $bearer, $queryParamsMap);
}
}
15 changes: 15 additions & 0 deletions src/NewTwitchApi/Resources/VideosApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ public function getVideos(string $bearer, array $ids = [], string $userId = null

return $this->getApi('videos', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#delete-videos
*/
public function deleteVideos(string $bearer, array $ids = []): ResponseInterface
{
$queryParamsMap = [];

foreach ($ids as $id) {
$queryParamsMap[] = ['key' => 'id', 'value' => $id];
}

return $this->deleteApi('videos', $bearer, $queryParamsMap);
}
}

0 comments on commit 730b695

Please sign in to comment.