-
Notifications
You must be signed in to change notification settings - Fork 48
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 #115 from brandinarsenault/predictions_polls
Add Polls and Predictions Classes & GET Endpoints
- Loading branch information
Showing
6 changed files
with
182 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,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 PollsApiSpec extends ObjectBehavior | ||
{ | ||
function let(Client $guzzleClient) | ||
{ | ||
$this->beConstructedWith($guzzleClient); | ||
} | ||
|
||
function it_should_get_polls(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'polls?broadcaster_id=12345', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPolls('TEST_TOKEN', '12345')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_polls_by_id(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'polls?broadcaster_id=12345&id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPolls('TEST_TOKEN', '12345', ['123'])->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_polls_by_ids(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'polls?broadcaster_id=12345&id=123&id=321', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPolls('TEST_TOKEN', '12345', ['123', '321'])->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_polls_with_everything(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'polls?broadcaster_id=12345&id=123&id=321&after=abc&first=20', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPolls('TEST_TOKEN', '12345', ['123', '321'], 'abc', 20)->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 PredictionsApiSpec extends ObjectBehavior | ||
{ | ||
function let(Client $guzzleClient) | ||
{ | ||
$this->beConstructedWith($guzzleClient); | ||
} | ||
|
||
function it_should_get_predictions(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'predictions?broadcaster_id=12345', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPredictions('TEST_TOKEN', '12345')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_predictions_by_id(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'predictions?broadcaster_id=12345&id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPredictions('TEST_TOKEN', '12345', ['123'])->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_predictions_by_ids(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'predictions?broadcaster_id=12345&id=123&id=321', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPredictions('TEST_TOKEN', '12345', ['123', '321'])->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_predictions_with_everything(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'predictions?broadcaster_id=12345&id=123&id=321&after=abc&first=20', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getPredictions('TEST_TOKEN', '12345', ['123', '321'], 'abc', 20)->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class PollsApi extends AbstractResource | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-polls | ||
*/ | ||
public function getPolls(string $bearer, string $broadcasterId, array $ids = [], string $after = null, int $first = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
foreach ($ids as $id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
if ($after) { | ||
$queryParamsMap[] = ['key' => 'after', 'value' => $after]; | ||
} | ||
|
||
if ($first) { | ||
$queryParamsMap[] = ['key' => 'first', 'value' => $first]; | ||
} | ||
|
||
return $this->getApi('polls', $bearer, $queryParamsMap); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class PredictionsApi extends AbstractResource | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-predictions | ||
*/ | ||
public function getPredictions(string $bearer, string $broadcasterId, array $ids = [], string $after = null, int $first = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
foreach ($ids as $id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
if ($after) { | ||
$queryParamsMap[] = ['key' => 'after', 'value' => $after]; | ||
} | ||
|
||
if ($first) { | ||
$queryParamsMap[] = ['key' => 'first', 'value' => $first]; | ||
} | ||
|
||
return $this->getApi('predictions', $bearer, $queryParamsMap); | ||
} | ||
} |