Skip to content

Commit

Permalink
Add ChatApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandin committed May 28, 2021
1 parent 58ac50a commit 77ae5dd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/NewTwitchApi/Resources/ChatApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace spec\NewTwitchApi\Resources;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use NewTwitchApi\RequestGenerator;
use PhpSpec\ObjectBehavior;

class ChatApiSpec extends ObjectBehavior
{
function let(Client $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
{
$this->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);
}
}
8 changes: 8 additions & 0 deletions src/NewTwitchApi/NewTwitchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,7 @@ class NewTwitchApi
private $bitsApi;
private $channelPointsApi;
private $channelsApi;
private $chatApi;
private $clipsApi;
private $entitlementsApi;
private $eventSubApi;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/NewTwitchApi/Resources/ChatApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace NewTwitchApi\Resources;

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

class ChatApi extends AbstractResource
{
/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-channel-chat-badges
*/
public function getChannelChatBadges(string $bearer, string $broadcasterId): ResponseInterface
{
$queryParamsMap = [];
$queryParamsMap[] = ['key' => '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);
}
}

0 comments on commit 77ae5dd

Please sign in to comment.