Skip to content

Commit

Permalink
Merge pull request #59 from brandinarsenault/master
Browse files Browse the repository at this point in the history
Add Clips API
  • Loading branch information
echosa committed Jun 10, 2020
2 parents 5292acb + 8d4cae2 commit c197511
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NewTwitchApi/NewTwitchApi.php
Expand Up @@ -6,6 +6,7 @@

use GuzzleHttp\Client;
use NewTwitchApi\Auth\OauthApi;
use NewTwitchApi\Resources\ClipsApi;
use NewTwitchApi\Resources\GamesApi;
use NewTwitchApi\Resources\StreamsApi;
use NewTwitchApi\Resources\UsersApi;
Expand All @@ -18,6 +19,7 @@
class NewTwitchApi
{
private $oauthApi;
private $clipsApi;
private $gamesApi;
private $streamsApi;
private $usersApi;
Expand All @@ -30,6 +32,7 @@ class NewTwitchApi
public function __construct(Client $helixGuzzleClient, string $clientId, string $clientSecret, Client $authGuzzleClient = null)
{
$this->oauthApi = new OauthApi($clientId, $clientSecret, $authGuzzleClient);
$this->clipsApi = new ClipsApi($helixGuzzleClient);
$this->gamesApi = new GamesApi($helixGuzzleClient);
$this->streamsApi = new StreamsApi($helixGuzzleClient);
$this->usersApi = new UsersApi($helixGuzzleClient);
Expand All @@ -45,6 +48,11 @@ public function getOauthApi(): OauthApi
return $this->oauthApi;
}

public function getClipsApi(): ClipsApi
{
return $this->clipsApi;
}

public function getGamesApi(): GamesApi
{
return $this->gamesApi;
Expand Down
70 changes: 70 additions & 0 deletions src/NewTwitchApi/Resources/ClipsApi.php
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace NewTwitchApi\Resources;

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

class ClipsApi extends AbstractResource
{
/**
* @throws GuzzleException
*/
public function getClipsByBroadcasterId(string $broadcasterId, string $bearer, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface
{
return $this->getClips($bearer, $broadcasterId, NULL, NULL, $first, $before, $after, $startedAt, $endedAt);
}

/**
* @throws GuzzleException
*/
public function getClipsByGameId(string $gameId, string $bearer, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface
{
return $this->getClips($bearer, NULL, $gameId, NULL, $first, $before, $after, $startedAt, $endedAt);
}

/**
* @throws GuzzleException
*/
public function getClipsByIds(string $clipIds, string $bearer, string $startedAt = null, string $endedAt = null): ResponseInterface
{
return $this->getClips($bearer, NULL, NULL, $clipIds, NULL, NULL, NULL, $startedAt, $endedAt);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-clips
*/
public function getClips(string $bearer, string $broadcasterId = null, string $gameId = null, string $clipIds = null, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface
{
$queryParamsMap = [];
if ($broadcasterId) {
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
}
if ($gameId) {
$queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId];
}
if ($clipIds) {
$queryParamsMap[] = ['key' => 'id', 'value' => $clipIds];
}
if ($first) {
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
}
if ($before) {
$queryParamsMap[] = ['key' => 'before', 'value' => $before];
}
if ($after) {
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
}
if ($startedAt) {
$queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt];
}
if ($endedAt) {
$queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt];
}

return $this->callApi('clips', $queryParamsMap, $bearer);
}
}

0 comments on commit c197511

Please sign in to comment.