Skip to content

Commit

Permalink
Merge pull request #104 from GW2Treasures/endpoints/add-missing-endpo…
Browse files Browse the repository at this point in the history
…ints

Adds missing endpoints:
 - /v2/account/outfits
 - /v2/guild/search
 - /v2/pvp/ranks
 - /v2/wvw/ranks
 - /v2/wvw/matches/{overview,scores,stats}
 - /v2/pvp/seasons/:id/leaderboards/:board/:region
  • Loading branch information
darthmaim authored Jan 22, 2017
2 parents 436408f + 7c9ec00 commit ac7d1b9
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/V2/Endpoint/Account/AccountEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ public function minis() {
return new MiniEndpoint( $this->api, $this->apiKey );
}

/**
* Get unlocked outfits.
*
* @return MiniEndpoint
*/
public function outfits() {
return new OutfitEndpoint( $this->api, $this->apiKey );
}

/**
* Get unlocked recipes.
*
Expand Down
29 changes: 29 additions & 0 deletions src/V2/Endpoint/Account/OutfitEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Account;

use GW2Treasures\GW2Api\GW2Api;
use GW2Treasures\GW2Api\V2\Authentication\AuthenticatedEndpoint;
use GW2Treasures\GW2Api\V2\Authentication\IAuthenticatedEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class OutfitEndpoint extends Endpoint implements IAuthenticatedEndpoint {
use AuthenticatedEndpoint;

public function __construct( GW2Api $api, $apiKey ) {
parent::__construct( $api );

$this->apiKey = $apiKey;
}

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/account/outfits';
}

public function get() {
return $this->request()->json();
}
}
9 changes: 9 additions & 0 deletions src/V2/Endpoint/Guild/GuildEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public function ranksOf($apiKey, $guildId) {
return new RankEndpoint($this->api, $apiKey, $guildId);
}

/**
* Search for a guild.
*
* @return SearchEndpoint
*/
public function search() {
return new SearchEndpoint($this->api);
}

/**
* Get stash of a guild.
*
Expand Down
23 changes: 23 additions & 0 deletions src/V2/Endpoint/Guild/SearchEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Guild;

use GW2Treasures\GW2Api\V2\Endpoint;

class SearchEndpoint extends Endpoint {

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/guild/search';
}

/**
* @param int $name
* @return string[]
*/
public function name( $name ) {
return $this->request([ 'name' => $name ])->json();
}
}
42 changes: 42 additions & 0 deletions src/V2/Endpoint/Pvp/LeaderboardEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Pvp;

use GW2Treasures\GW2Api\GW2Api;
use GW2Treasures\GW2Api\V2\Endpoint;

class LeaderboardEndpoint extends Endpoint {
/** @var string $season */
private $season;

/**
* @param GW2Api $api
* @param string $season
*/
public function __construct(GW2Api $api, $season) {
parent::__construct($api);
$this->season = $season;
}

/**
* The url of this endpoint.
*
* @return string
*/
public function url() {
return 'v2/pvp/seasons/'.$this->season.'/leaderboards';
}

/**
* Get a list of available leaderboards.
*
* @return string[]
*/
public function ids() {
return $this->request()->json();
}

public function get($leaderboard, $region) {
return new LeaderboardRegionEndpoint($this->api, $this->season, $leaderboard, $region);
}
}
45 changes: 45 additions & 0 deletions src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Pvp;

use GW2Treasures\GW2Api\GW2Api;
use GW2Treasures\GW2Api\V2\Endpoint;
use GW2Treasures\GW2Api\V2\Pagination\IPaginatedEndpoint;
use GW2Treasures\GW2Api\V2\Pagination\PaginatedEndpoint;

class LeaderboardRegionEndpoint extends Endpoint implements IPaginatedEndpoint {
use PaginatedEndpoint;

/** @var string $season */
private $season;

/** @var string $leaderboard */
private $leaderboard;

/** @var string $region */
private $region;

/**
* @param GW2Api $api
* @param string $season
* @param string $leaderboard
* @param string $region
*/
public function __construct(GW2Api $api, $season, $leaderboard, $region) {
parent::__construct($api);

$this->season = $season;
$this->leaderboard = $leaderboard;
$this->region = $region;
}


/**
* The url of this endpoint.
*
* @return string
*/
public function url() {
return 'v2/pvp/seasons/'.$this->season.'/leaderboards/'.$this->leaderboard.'/'.$this->region;
}
}
7 changes: 7 additions & 0 deletions src/V2/Endpoint/Pvp/PvpEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public function games($apiKey) {
return new GameEndpoint($this->api, $apiKey);
}

/**
* @return RankEndpoint
*/
public function ranks() {
return new RankEndpoint($this->api);
}

/**
* @return SeasonEndpoint
*/
Expand Down
20 changes: 20 additions & 0 deletions src/V2/Endpoint/Pvp/RankEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Pvp;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;
use GW2Treasures\GW2Api\V2\Localization\ILocalizedEndpoint;
use GW2Treasures\GW2Api\V2\Localization\LocalizedEndpoint;

class RankEndpoint extends Endpoint implements IBulkEndpoint, ILocalizedEndpoint {
use BulkEndpoint, LocalizedEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/pvp/ranks';
}
}
4 changes: 4 additions & 0 deletions src/V2/Endpoint/Pvp/SeasonEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ class SeasonEndpoint extends Endpoint implements IBulkEndpoint, ILocalizedEndpoi
public function url() {
return 'v2/pvp/seasons';
}

public function leaderboardsOf($season) {
return new LeaderboardEndpoint($this->api, $season);
}
}
12 changes: 12 additions & 0 deletions src/V2/Endpoint/WvW/MatchEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ public function url() {
public function world($id) {
return $this->request(['world' => $id])->json();
}

public function overview() {
return new OverviewEndpoint($this->api);
}

public function scores() {
return new ScoreEndpoint($this->api);
}

public function stats() {
return new StatEndpoint($this->api);
}
}
28 changes: 28 additions & 0 deletions src/V2/Endpoint/WvW/OverviewEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\WvW;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class OverviewEndpoint extends Endpoint implements IBulkEndpoint {
use BulkEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/wvw/matches/overview';
}

/**
* Get the current match of a world.
*
* @param int $id
* @return mixed
*/
public function world($id) {
return $this->request(['world' => $id])->json();
}
}
20 changes: 20 additions & 0 deletions src/V2/Endpoint/WvW/RankEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\WvW;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;
use GW2Treasures\GW2Api\V2\Localization\ILocalizedEndpoint;
use GW2Treasures\GW2Api\V2\Localization\LocalizedEndpoint;

class RankEndpoint extends Endpoint implements IBulkEndpoint, ILocalizedEndpoint {
use BulkEndpoint, LocalizedEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/wvw/ranks';
}
}
28 changes: 28 additions & 0 deletions src/V2/Endpoint/WvW/ScoreEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\WvW;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class ScoreEndpoint extends Endpoint implements IBulkEndpoint {
use BulkEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/wvw/matches/scores';
}

/**
* Get the current match of a world.
*
* @param int $id
* @return mixed
*/
public function world($id) {
return $this->request(['world' => $id])->json();
}
}
28 changes: 28 additions & 0 deletions src/V2/Endpoint/WvW/StatEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\WvW;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class StatEndpoint extends Endpoint implements IBulkEndpoint {
use BulkEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/wvw/matches/stats';
}

/**
* Get the current match of a world.
*
* @param int $id
* @return mixed
*/
public function world($id) {
return $this->request(['world' => $id])->json();
}
}
4 changes: 4 additions & 0 deletions src/V2/Endpoint/WvW/WvWEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public function matches() {
public function objectives() {
return new ObjectiveEndpoint( $this->api );
}

public function ranks() {
return new RankEndpoint( $this->api );
}
}
10 changes: 10 additions & 0 deletions tests/V2/AccountEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public function testMinis() {
$this->assertEquals([1,2,3,4,5,6], $endpoint->get());
}

public function testOutfits() {
$endpoint = $this->api()->account('test')->outfits();

$this->assertEndpointIsAuthenticated( $endpoint );
$this->assertEndpointUrl( 'v2/account/outfits', $endpoint );

$this->mockResponse('[1,2,3]');
$this->assertEquals([1,2,3], $endpoint->get());
}

public function testRecipes() {
$endpoint = $this->api()->account('test')->recipes();

Expand Down
11 changes: 11 additions & 0 deletions tests/V2/GuildEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public function testRanks() {
$this->assertEquals('Leader', $endpoint->get()[0]->id);
}

public function testSearch() {
$endpoint = $this->api()->guild()->search();

$this->assertEndpointUrl('v2/guild/search', $endpoint);

$this->mockResponse('["335C4BB3-5CA3-E511-80D3-E4115BD7186D"]');
$this->assertEquals('335C4BB3-5CA3-E511-80D3-E4115BD7186D', $endpoint->name("API Test")[0]);

$this->assertEquals('name=API%20Test', $this->getLastRequest()->getUri()->getQuery());
}

public function testStash() {
$endpoint = $this->api()->guild()->stashOf('API_KEY', 'GUILD_ID');

Expand Down
Loading

0 comments on commit ac7d1b9

Please sign in to comment.