Skip to content

Commit

Permalink
Merge pull request #33 from GW2Treasures/endpoints/pvp
Browse files Browse the repository at this point in the history
Add /v2/pvp/games and /v2/pvp/stats endpoints
  • Loading branch information
darthmaim committed Sep 8, 2015
2 parents d4e2dc0 + 85365f6 commit a32656f
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 4 deletions.
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ For all examples it is assumed that you have a variable `$api = new GW2Api()`.
/v2/items | [Item\ItemEndpoint][ItemEndpoint] <br>`GW2Api::items()` | 📦🌏
~~/v2/leaderboards~~ | *disabled* | 🚫
/v2/maps | [Map\MapEndpoint][MapEndpoint] <br>`GW2Api::maps()` | 📦🌏
/v2/materials | [Material\MaterialEndpoint][MaterialEndpoint] <br>`GW2Api::materials()` | 📦🌏
~~/v2/pvp~~ | *disabled* | 🚫
~~/v2/pvp/games~~ | *disabled* | 🚫
~~/v2/pvp/stats~~ | *disabled* | 🚫
/v2/materials | [Material\MaterialEndpoint][MaterialEndpoint] <br>`GW2Api::materials()` | 📦🌏 | 🚫
/v2/pvp/games | [Pvp\GameEndpoint][Pvp\GameEndpoint] <br>`GW2Api::pvp()->games()` | 🔒📦
/v2/pvp/stats | [Pvp\StatsEndpoint][Pvp\StatsEndpoint] <br>`GW2Api::pvp()->stats()` | 🔒
/v2/quaggans | [Quaggan\QuagganEndpoint][QuagganEndpoint] <br>`GW2Api::quaggans()` | 📦
/v2/recipes | [Recipe\RecipeEndpoint][RecipeEndpoint] <br>`GW2Api::recipes()` | 📦
/v2/recipes/search | [Recipe\SearchEndpoint][Recipe\SearchEndpoint] <br>`GW2Api::recipes()->search()` |
Expand Down Expand Up @@ -791,6 +790,42 @@ $api->materials()->lang('es')->all();
```


#### /v2/pvp/games
[Pvp\GameEndpoint]: #v2pvpgames

`\GW2Treasures\GW2Api\V2\Endpoint\Pvp\GameEndpoint`
([source](src/V2/Endpoint/Pvp/GameEndpoint.php))

Implements [🔒AuthenticatedEndpoint][AuthenticatedEndpoint] and [📦BulkEndpoint][BulkEndpoint].

##### Methods
- Inherited from [📦BulkEndpoint][BulkEndpoint].

##### Example
```php
$api->pvp('API_KEY')->games()->get('A9F9FD97-F114-4F97-B2CA-5E814DF0340E');
// => { id: "A9F9FD97-F114-4F97-B2CA-5E814DF0340E", map_id: 795, … }
```


#### /v2/pvp/stats
[Pvp\StatsEndpoint]: #v2pvpstats

`\GW2Treasures\GW2Api\V2\Endpoint\Pvp\StatsEndpoint`
([source](src/V2/Endpoint/Pvp/StatsEndpoint.php))

Implements [🔒AuthenticatedEndpoint][AuthenticatedEndpoint].

##### Methods
- `get():mixed` Get pvp stats.

##### Example
```php
$api->pvp('API_KEY')->stats()->get();
// => { pvp_rank: 57, aggregate: { wins: 343, … }, … }
```


#### /v2/quaggans
[QuagganEndpoint]: #v2quaggans

Expand Down
5 changes: 5 additions & 0 deletions src/GW2Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use GW2Treasures\GW2Api\V2\Endpoint\Item\ItemEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Map\MapEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Material\MaterialEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Pvp\PvpEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Quaggan\QuagganEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Recipe\RecipeEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Skin\SkinEndpoint;
Expand Down Expand Up @@ -162,6 +163,10 @@ public function materials() {
return new MaterialEndpoint( $this );
}

public function pvp( $apiKey ) {
return new PvpEndpoint( $this, $apiKey );
}

public function quaggans() {
return new QuagganEndpoint( $this );
}
Expand Down
1 change: 1 addition & 0 deletions src/V2/Authentication/AuthenticatedEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace GW2Treasures\GW2Api\V2\Authentication;

trait AuthenticatedEndpoint {
/** @var string $apiKey */
protected $apiKey;

/**
Expand Down
33 changes: 33 additions & 0 deletions src/V2/Endpoint/Pvp/GameEndpoint.php
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';
}
}
45 changes: 45 additions & 0 deletions src/V2/Endpoint/Pvp/PvpEndpoint.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\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);
}
}
28 changes: 28 additions & 0 deletions src/V2/Endpoint/Pvp/StatsEndpoint.php
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();
}
}
13 changes: 13 additions & 0 deletions tests/V2/PvpEndpointTest.php
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() );
}
}
14 changes: 14 additions & 0 deletions tests/V2/PvpGameEndpointTest.php
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() );
}
}
13 changes: 13 additions & 0 deletions tests/V2/PvpStatsEndpointTest.php
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 );
}
}

0 comments on commit a32656f

Please sign in to comment.