Skip to content

Commit e32fb3a

Browse files
committed
Add in Goals API
1 parent 201c00d commit e32fb3a

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace spec\TwitchApi\Resources;
4+
5+
use GuzzleHttp\Psr7\Request;
6+
use GuzzleHttp\Psr7\Response;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
9+
use PhpSpec\ObjectBehavior;
10+
11+
class GoalsApiSpec extends ObjectBehavior
12+
{
13+
function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response)
14+
{
15+
$this->beConstructedWith($guzzleClient, $requestGenerator);
16+
$guzzleClient->send($request)->willReturn($response);
17+
}
18+
19+
function it_should_get_goals_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response)
20+
{
21+
$requestGenerator->generate('GET', 'goals', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
22+
$this->getGoals('TEST_TOKEN', ['123'])->shouldBe($response);
23+
}
24+
25+
}

spec/TwitchApi/TwitchApiSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use TwitchApi\Resources\EntitlementsApi;
1717
use TwitchApi\Resources\EventSubApi;
1818
use TwitchApi\Resources\GamesApi;
19+
use TwitchApi\Resources\GoalsApi;
1920
use TwitchApi\Resources\HypeTrainApi;
2021
use TwitchApi\Resources\ModerationApi;
2122
use TwitchApi\Resources\PollsApi;
@@ -101,6 +102,11 @@ function it_should_provide_games_api()
101102
$this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class);
102103
}
103104

105+
function it_should_provide_goals_api()
106+
{
107+
$this->getGoalsApi()->shouldBeAnInstanceOf(GoalsApi::class);
108+
}
109+
104110
function it_should_provide_hype_train_api() {
105111
$this->getHypeTrainApi()->shouldBeAnInstanceOf(HypeTrainApi::class);
106112
}

src/Resources/GoalsApi.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TwitchApi\Resources;
6+
7+
use GuzzleHttp\Exception\GuzzleException;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class GoalsApi extends AbstractResource
11+
{
12+
/**
13+
* @throws GuzzleException
14+
* @link https://dev.twitch.tv/docs/api/reference/#get-creator-goals
15+
*/
16+
public function getGoals(string $bearer, string $broadcasterId): ResponseInterface
17+
{
18+
$queryParamsMap = [];
19+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
20+
21+
return $this->getApi('goals', $bearer, $queryParamsMap);
22+
}
23+
}

src/TwitchApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use TwitchApi\Resources\EntitlementsApi;
1818
use TwitchApi\Resources\EventSubApi;
1919
use TwitchApi\Resources\GamesApi;
20+
use TwitchApi\Resources\GoalsApi;
2021
use TwitchApi\Resources\HypeTrainApi;
2122
use TwitchApi\Resources\ModerationApi;
2223
use TwitchApi\Resources\PollsApi;
@@ -48,6 +49,7 @@ class TwitchApi
4849
private $entitlementsApi;
4950
private $eventSubApi;
5051
private $gamesApi;
52+
private $goalsApi;
5153
private $hypeTrainApi;
5254
private $moderationApi;
5355
private $pollsApi;
@@ -80,6 +82,7 @@ public function __construct(HelixGuzzleClient $helixGuzzleClient, string $client
8082
$this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator);
8183
$this->eventSubApi = new EventSubApi($helixGuzzleClient, $requestGenerator);
8284
$this->gamesApi = new GamesApi($helixGuzzleClient, $requestGenerator);
85+
$this->goalsApi = new GoalsApi($helixGuzzleClient, $requestGenerator);
8386
$this->hypeTrainApi = new HypeTrainApi($helixGuzzleClient, $requestGenerator);
8487
$this->moderationApi = new ModerationApi($helixGuzzleClient, $requestGenerator);
8588
$this->pollsApi = new PollsApi($helixGuzzleClient, $requestGenerator);
@@ -158,6 +161,11 @@ public function getGamesApi(): GamesApi
158161
return $this->gamesApi;
159162
}
160163

164+
public function getGoalsApi(): GoalsApi
165+
{
166+
return $this->goalsApi;
167+
}
168+
161169
public function getHypeTrainApi(): HypeTrainApi
162170
{
163171
return $this->hypeTrainApi;

0 commit comments

Comments
 (0)