-
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 #131 from nicklaw5/v5-0-5
- Loading branch information
Showing
8 changed files
with
265 additions
and
6 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
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,84 @@ | ||
<?php | ||
|
||
namespace spec\NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use NewTwitchApi\RequestGenerator; | ||
use NewTwitchApi\HelixGuzzleClient; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ScheduleApiSpec extends ObjectBehavior | ||
{ | ||
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$this->beConstructedWith($guzzleClient, $requestGenerator); | ||
$guzzleClient->send($request)->willReturn($response); | ||
} | ||
|
||
function it_should_get_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); | ||
$this->getChannelStreamSchedule('TEST_TOKEN', '123')->shouldBe($response); | ||
} | ||
|
||
function it_should_get_channel_stream_schedule_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'utc_offset', 'value' => '240'], ['key' => 'first', 'value' => 25], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); | ||
$this->getChannelStreamSchedule('TEST_TOKEN', '123', [], '2021-06-15T23:08:20+00:00', '240', 25, 'abc')->shouldBe($response); | ||
} | ||
|
||
function it_should_get_a_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); | ||
$this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456'])->shouldBe($response); | ||
} | ||
|
||
function it_should_get_multiple_channel_stream_schedules(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'id', 'value' => '789']], [])->willReturn($request); | ||
$this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response); | ||
} | ||
|
||
function it_should_get_channel_icalendar_with_no_auth(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule/icalendar', null, [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); | ||
$this->getChanneliCalendar(null, '123')->shouldBe($response); | ||
} | ||
|
||
function it_should_get_channel_icalendar_with_auth(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('GET', 'schedule/icalendar', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); | ||
$this->getChanneliCalendar('TEST_TOKEN', '123')->shouldBe($response); | ||
} | ||
|
||
function it_should_update_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('PATCH', 'schedule/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'is_vacation_enabled', 'value' => true], ['key' => 'vacation_start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'vacation_end_time', 'value' => '2021-06-22T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York']], [])->willReturn($request); | ||
$this->updateChannelStreamSchedule('TEST_TOKEN', '123', true, '2021-06-15T23:08:20+00:00', '2021-06-22T23:08:20+00:00', 'America/New_York')->shouldBe($response); | ||
} | ||
|
||
function it_should_create_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true]])->willReturn($request); | ||
$this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true)->shouldBe($response); | ||
} | ||
|
||
function it_should_create_channel_stream_schedule_segment_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); | ||
$this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true, ['duration' => '240'])->shouldBe($response); | ||
} | ||
|
||
function it_should_update_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('PATCH', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_canceled', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); | ||
$this->updateChannelStreamScheduleSegment('TEST_TOKEN', '123', '456', ['start_time' => '2021-06-15T23:08:20+00:00', 'timezone' => 'America/New_York', 'is_canceled' => true, 'duration' => '240'])->shouldBe($response); | ||
} | ||
|
||
function it_should_delete_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) | ||
{ | ||
$requestGenerator->generate('DELETE', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); | ||
$this->deleteChannelStreamScheduleSegment('TEST_TOKEN', '123', '456')->shouldBe($response); | ||
} | ||
} |
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
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,145 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ScheduleApi extends AbstractResource | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#get-channel-stream-schedule | ||
*/ | ||
public function getChannelStreamSchedule(string $bearer, string $broadcasterId, array $ids = [], string $startTime = null, string $utcOffset = null, int $first = null, string $after = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
foreach ($ids as $id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
if ($startTime) { | ||
$queryParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; | ||
} | ||
|
||
if ($utcOffset) { | ||
$queryParamsMap[] = ['key' => 'utc_offset', 'value' => $utcOffset]; | ||
} | ||
|
||
if ($first) { | ||
$queryParamsMap[] = ['key' => 'first', 'value' => $first]; | ||
} | ||
|
||
if ($after) { | ||
$queryParamsMap[] = ['key' => 'after', 'value' => $after]; | ||
} | ||
|
||
return $this->getApi('schedule', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#get-channel-icalendar | ||
*/ | ||
public function getChanneliCalendar(string $bearer = null, string $broadcasterId): ResponseInterface | ||
{ | ||
// This endpoint at the time of addition does not require any authorization, so the bearer is null. | ||
// However, to prevent a breaking update in the future, it will remain the first function parameter. | ||
// You may simple pass NULL to this to bypass authentication. | ||
|
||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
return $this->getApiWithOptionalAuth('schedule/icalendar', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule | ||
*/ | ||
public function updateChannelStreamSchedule(string $bearer, string $broadcasterId, bool $isVacationEnabled = null, $vacationStartTime = null, $vacationEndTime = null, $timezone = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
if ($isVacationEnabled) { | ||
$queryParamsMap[] = ['key' => 'is_vacation_enabled', 'value' => $isVacationEnabled]; | ||
} | ||
|
||
if ($vacationStartTime) { | ||
$queryParamsMap[] = ['key' => 'vacation_start_time', 'value' => $vacationStartTime]; | ||
} | ||
|
||
if ($vacationEndTime) { | ||
$queryParamsMap[] = ['key' => 'vacation_end_time', 'value' => $vacationEndTime]; | ||
} | ||
|
||
if ($timezone) { | ||
$queryParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; | ||
} | ||
|
||
return $this->patchApi('schedule/settings', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#create-channel-stream-schedule-segment | ||
*/ | ||
public function createChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $startTime, string $timezone, bool $isRecurring, array $additionalBodyParams = []): ResponseInterface | ||
{ | ||
// $additionalBodyParams should be a standard key => value format, eg. ['duration' => '240']; | ||
$queryParamsMap = $bodyParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
$bodyParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; | ||
$bodyParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; | ||
$bodyParamsMap[] = ['key' => 'is_recurring', 'value' => $isRecurring]; | ||
|
||
foreach ($additionalBodyParams as $key => $value) { | ||
$bodyParamsMap[] = ['key' => $key, 'value' => $value]; | ||
} | ||
|
||
return $this->postApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule-segment | ||
*/ | ||
public function updateChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId, array $updateValues = []): ResponseInterface | ||
{ | ||
// $updateValues should be a standard key => value format based on the values available on the documentation, eg. ['duration' => '240']; | ||
$queryParamsMap = $bodyParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; | ||
|
||
foreach ($updateValues as $key => $value) { | ||
$bodyParamsMap[] = ['key' => $key, 'value' => $value]; | ||
} | ||
|
||
return $this->patchApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference/#delete-channel-stream-schedule-segment | ||
*/ | ||
public function deleteChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; | ||
|
||
return $this->deleteApi('schedule/segment', $bearer, $queryParamsMap); | ||
} | ||
} |