-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from ThibaultVlacich/new-endpoints
Add new endpoints (teams and check user sub)
- Loading branch information
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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 SubscriptionsApiSpec extends ObjectBehavior | ||
{ | ||
function let(Client $guzzleClient) | ||
{ | ||
$this->beConstructedWith($guzzleClient); | ||
} | ||
|
||
function it_should_check_user_subscriptions(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'subscriptions/user?broadcaster_id=123&user_id=456', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->checkUserSubscription('TEST_TOKEN', '123', '456')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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 TeamsApiSpec extends ObjectBehavior | ||
{ | ||
function let(Client $guzzleClient) | ||
{ | ||
$this->beConstructedWith($guzzleClient); | ||
} | ||
|
||
function it_should_get_channel_teams(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'teams/channel?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getChannelTeams('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_teams(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'teams', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getTeams('TEST_TOKEN')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_teams_by_name(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'teams?name=abc', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getTeamsByName('TEST_TOKEN', 'abc')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_teams_by_id(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'teams?id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getTeamsById('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class TeamsApi extends AbstractResource | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-channel-teams | ||
*/ | ||
public function getChannelTeams(string $bearer, string $broadcasterId): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
return $this->getApi('teams/channel', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-teams | ||
*/ | ||
public function getTeams(string $bearer, string $name = null, string $id = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
if ($name) { | ||
$queryParamsMap[] = ['key' => 'name', 'value' => $name]; | ||
} | ||
|
||
if ($id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
return $this->getApi('teams', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
*/ | ||
public function getTeamsByName(string $bearer, string $name): ResponseInterface | ||
{ | ||
return $this->getTeams($bearer, $name, null); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
*/ | ||
public function getTeamsById(string $bearer, string $id): ResponseInterface | ||
{ | ||
return $this->getTeams($bearer, null, $id); | ||
} | ||
} |