From 7c9ec001a03a59b02e288a8e0690efe35fa9ebbb Mon Sep 17 00:00:00 2001 From: darthmaim Date: Sun, 22 Jan 2017 02:32:15 +0100 Subject: [PATCH] add /v2/pvp/seasons/:id/leaderboards/:board/:region --- src/V2/Endpoint/Pvp/LeaderboardEndpoint.php | 42 +++++++++++++++++ .../Pvp/LeaderboardRegionEndpoint.php | 45 +++++++++++++++++++ src/V2/Endpoint/Pvp/SeasonEndpoint.php | 4 ++ tests/V2/PvpEndpointTest.php | 20 +++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/V2/Endpoint/Pvp/LeaderboardEndpoint.php create mode 100644 src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php diff --git a/src/V2/Endpoint/Pvp/LeaderboardEndpoint.php b/src/V2/Endpoint/Pvp/LeaderboardEndpoint.php new file mode 100644 index 0000000..f50ac3f --- /dev/null +++ b/src/V2/Endpoint/Pvp/LeaderboardEndpoint.php @@ -0,0 +1,42 @@ +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); + } +} diff --git a/src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php b/src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php new file mode 100644 index 0000000..3f1441d --- /dev/null +++ b/src/V2/Endpoint/Pvp/LeaderboardRegionEndpoint.php @@ -0,0 +1,45 @@ +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; + } +} diff --git a/src/V2/Endpoint/Pvp/SeasonEndpoint.php b/src/V2/Endpoint/Pvp/SeasonEndpoint.php index ef44210..dbccf9f 100644 --- a/src/V2/Endpoint/Pvp/SeasonEndpoint.php +++ b/src/V2/Endpoint/Pvp/SeasonEndpoint.php @@ -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); + } } diff --git a/tests/V2/PvpEndpointTest.php b/tests/V2/PvpEndpointTest.php index f2d91cc..590a950 100644 --- a/tests/V2/PvpEndpointTest.php +++ b/tests/V2/PvpEndpointTest.php @@ -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');