Skip to content

Commit

Permalink
add /v2/pvp/seasons/:id/leaderboards/:board/:region
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Jan 22, 2017
1 parent 7bdbd9b commit 7c9ec00
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
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;
}
}
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);
}
}
20 changes: 20 additions & 0 deletions tests/V2/PvpEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public function testSeasons() {
$this->assertEquals('PvP League Season One', $endpoint->get("44B85826-B5ED-4890-8C77-82DDF9F2CF2B")->name);
}

public function testSeasonLeaderboardsList() {
$endpoint = $this->api()->pvp()->seasons()->leaderboardsOf('44B85826-B5ED-4890-8C77-82DDF9F2CF2B');

$this->assertEndpointUrl('v2/pvp/seasons/44B85826-B5ED-4890-8C77-82DDF9F2CF2B/leaderboards', $endpoint);

$this->mockResponse('["legendary","guild"]');
$this->assertEquals('legendary', $endpoint->ids()[0]);
}

public function testSeasonLeaderboardsGet() {
$endpoint = $this->api()->pvp()->seasons()->leaderboardsOf('44B85826-B5ED-4890-8C77-82DDF9F2CF2B')
->get('legendary', 'na');

$this->assertEndpointUrl('v2/pvp/seasons/44B85826-B5ED-4890-8C77-82DDF9F2CF2B/leaderboards/legendary/na', $endpoint);
$this->assertEndpointIsPaginated($endpoint);

$this->mockResponse('[{"name":"darthmaim.6017", "rank":1}]');
$this->assertEquals('darthmaim.6017', $endpoint->page(0, 1)[0]->name);
}

public function testStanding() {
$endpoint = $this->api()->pvp()->standings('API_KEY');

Expand Down

0 comments on commit 7c9ec00

Please sign in to comment.