-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from GW2Treasures/endpoints/pvp
Add /v2/pvp/games and /v2/pvp/stats endpoints
- Loading branch information
Showing
9 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace GW2Treasures\GW2Api\V2\Endpoint\Pvp; | ||
|
||
use GW2Treasures\GW2Api\GW2Api; | ||
use GW2Treasures\GW2Api\V2\Authentication\AuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Authentication\IAuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint; | ||
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint; | ||
use GW2Treasures\GW2Api\V2\Endpoint; | ||
|
||
class GameEndpoint extends Endpoint implements IAuthenticatedEndpoint, IBulkEndpoint { | ||
use AuthenticatedEndpoint, BulkEndpoint; | ||
|
||
/** | ||
* @param GW2Api $api | ||
* @param string $apiKey | ||
*/ | ||
public function __construct(GW2Api $api, $apiKey) { | ||
$this->apiKey = $apiKey; | ||
|
||
parent::__construct($api); | ||
} | ||
|
||
/** | ||
* The url of this endpoint. | ||
* | ||
* @return string | ||
*/ | ||
public function url() { | ||
return 'v2/pvp/games'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\Authentication\AuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Authentication\IAuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Endpoint; | ||
|
||
class PvpEndpoint extends Endpoint implements IAuthenticatedEndpoint { | ||
use AuthenticatedEndpoint; | ||
|
||
/** | ||
* @param GW2Api $api | ||
* @param string $apiKey | ||
*/ | ||
public function __construct(GW2Api $api, $apiKey) { | ||
$this->apiKey = $apiKey; | ||
|
||
parent::__construct($api); | ||
} | ||
|
||
/** | ||
* The url of this endpoint. | ||
* | ||
* @return string | ||
*/ | ||
public function url() { | ||
return 'v2/pvp'; | ||
} | ||
|
||
/** | ||
* @return GameEndpoint | ||
*/ | ||
public function games() { | ||
return new GameEndpoint( $this->api, $this->apiKey ); | ||
} | ||
|
||
/** | ||
* @return StatsEndpoint | ||
*/ | ||
public function stats() { | ||
return new StatsEndpoint($this->api, $this->apiKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace GW2Treasures\GW2Api\V2\Endpoint\Pvp; | ||
|
||
use GW2Treasures\GW2Api\V2\Authentication\AuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Authentication\IAuthenticatedEndpoint; | ||
use GW2Treasures\GW2Api\V2\Endpoint; | ||
|
||
class StatsEndpoint extends Endpoint implements IAuthenticatedEndpoint { | ||
use AuthenticatedEndpoint; | ||
|
||
/** | ||
* The url of this endpoint. | ||
* | ||
* @return string | ||
*/ | ||
public function url() { | ||
return 'v2/pvp/stats'; | ||
} | ||
|
||
/** | ||
* Get pvp stats. | ||
* @return mixed | ||
*/ | ||
public function get() { | ||
return $this->request()->json(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class PvpEndpointTest extends TestCase { | ||
public function test() { | ||
$endpoint = $this->api()->pvp('API_KEY'); | ||
|
||
$this->assertEndpointUrl( 'v2/pvp', $endpoint ); | ||
$this->assertEndpointIsAuthenticated( $endpoint ); | ||
|
||
$this->assertInstanceOf( '\GW2Treasures\GW2Api\V2\Endpoint\Pvp\GameEndpoint', $endpoint->games() ); | ||
$this->assertInstanceOf( '\GW2Treasures\GW2Api\V2\Endpoint\Pvp\StatsEndpoint', $endpoint->stats() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
class PvpGameEndpointTest extends TestCase { | ||
public function test() { | ||
$endpoint = $this->api()->pvp('API_KEY')->games(); | ||
|
||
$this->assertEndpointUrl( 'v2/pvp/games', $endpoint ); | ||
$this->assertEndpointIsAuthenticated( $endpoint ); | ||
$this->assertEndpointIsBulk( $endpoint ); | ||
|
||
$this->mockResponse( '["A9F9FD97-F114-4F97-B2CA-5E814DF0340E","4FDC931F-677F-4369-B20A-9FBB6A63B2B4"]' ); | ||
$this->assertContains( '4FDC931F-677F-4369-B20A-9FBB6A63B2B4', $endpoint->ids() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class PvpStatsEndpointTest extends TestCase { | ||
public function test() { | ||
$endpoint = $this->api()->pvp('API_KEY')->stats(); | ||
|
||
$this->assertEndpointUrl( 'v2/pvp/stats', $endpoint ); | ||
$this->assertEndpointIsAuthenticated( $endpoint ); | ||
|
||
$this->mockResponse( '{"pvp_rank":57}' ); | ||
$this->assertEquals( 57, $endpoint->get()->pvp_rank ); | ||
} | ||
} |