Skip to content

Commit

Permalink
Merge pull request #149 from radiojoe/feature/goals
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandin authored Jun 10, 2023
2 parents 0ccd0b3 + e32fb3a commit 4ed365e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/TwitchApi/Resources/GoalsApiSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace spec\TwitchApi\Resources;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TwitchApi\RequestGenerator;
use TwitchApi\HelixGuzzleClient;
use PhpSpec\ObjectBehavior;

class GoalsApiSpec 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_goals_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'goals', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getGoals('TEST_TOKEN', ['123'])->shouldBe($response);
}

}
6 changes: 6 additions & 0 deletions spec/TwitchApi/TwitchApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TwitchApi\Resources\EntitlementsApi;
use TwitchApi\Resources\EventSubApi;
use TwitchApi\Resources\GamesApi;
use TwitchApi\Resources\GoalsApi;
use TwitchApi\Resources\HypeTrainApi;
use TwitchApi\Resources\ModerationApi;
use TwitchApi\Resources\PollsApi;
Expand Down Expand Up @@ -101,6 +102,11 @@ function it_should_provide_games_api()
$this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class);
}

function it_should_provide_goals_api()
{
$this->getGoalsApi()->shouldBeAnInstanceOf(GoalsApi::class);
}

function it_should_provide_hype_train_api() {
$this->getHypeTrainApi()->shouldBeAnInstanceOf(HypeTrainApi::class);
}
Expand Down
23 changes: 23 additions & 0 deletions src/Resources/GoalsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace TwitchApi\Resources;

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

class GoalsApi extends AbstractResource
{
/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference/#get-creator-goals
*/
public function getGoals(string $bearer, string $broadcasterId): ResponseInterface
{
$queryParamsMap = [];
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];

return $this->getApi('goals', $bearer, $queryParamsMap);
}
}
8 changes: 8 additions & 0 deletions src/TwitchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use TwitchApi\Resources\EntitlementsApi;
use TwitchApi\Resources\EventSubApi;
use TwitchApi\Resources\GamesApi;
use TwitchApi\Resources\GoalsApi;
use TwitchApi\Resources\HypeTrainApi;
use TwitchApi\Resources\ModerationApi;
use TwitchApi\Resources\PollsApi;
Expand Down Expand Up @@ -48,6 +49,7 @@ class TwitchApi
private $entitlementsApi;
private $eventSubApi;
private $gamesApi;
private $goalsApi;
private $hypeTrainApi;
private $moderationApi;
private $pollsApi;
Expand Down Expand Up @@ -80,6 +82,7 @@ public function __construct(HelixGuzzleClient $helixGuzzleClient, string $client
$this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator);
$this->eventSubApi = new EventSubApi($helixGuzzleClient, $requestGenerator);
$this->gamesApi = new GamesApi($helixGuzzleClient, $requestGenerator);
$this->goalsApi = new GoalsApi($helixGuzzleClient, $requestGenerator);
$this->hypeTrainApi = new HypeTrainApi($helixGuzzleClient, $requestGenerator);
$this->moderationApi = new ModerationApi($helixGuzzleClient, $requestGenerator);
$this->pollsApi = new PollsApi($helixGuzzleClient, $requestGenerator);
Expand Down Expand Up @@ -158,6 +161,11 @@ public function getGamesApi(): GamesApi
return $this->gamesApi;
}

public function getGoalsApi(): GoalsApi
{
return $this->goalsApi;
}

public function getHypeTrainApi(): HypeTrainApi
{
return $this->hypeTrainApi;
Expand Down

0 comments on commit 4ed365e

Please sign in to comment.