Skip to content

Commit

Permalink
Merge pull request #109 from GW2Treasures/endpoints/mailcarrier-pvp-h…
Browse files Browse the repository at this point in the history
…eroes

Add mailcarrier and pvp/heroes endpoints
  • Loading branch information
darthmaim authored May 9, 2017
2 parents 4885923 + 0e66253 commit 9b226ef
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/GW2Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use GW2Treasures\GW2Api\V2\Endpoint\Item\ItemEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Itemstat\ItemstatEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Legend\LegendEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Mailcarrier\MailcarrierEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Map\MapEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Mastery\MasteryEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Material\MaterialEndpoint;
Expand Down Expand Up @@ -224,6 +225,10 @@ public function legends() {
return new LegendEndpoint( $this );
}

public function mailcarriers() {
return new MailcarrierEndpoint($this);
}

public function maps() {
return new MapEndpoint( $this );
}
Expand Down
19 changes: 19 additions & 0 deletions src/V2/Endpoint/Account/AccountEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GW2Treasures\GW2Api\V2\Authentication\IAuthenticatedEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Account\Home\HomeEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Account\Pvp\PvpEndpoint;

class AccountEndpoint extends Endpoint implements IAuthenticatedEndpoint {
use AuthenticatedEndpoint;
Expand Down Expand Up @@ -105,6 +106,15 @@ public function inventory() {
return new InventoryEndpoint( $this->api, $this->apiKey );
}

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

/**
* Get unlocked masteries.
*
Expand Down Expand Up @@ -141,6 +151,15 @@ public function outfits() {
return new OutfitEndpoint( $this->api, $this->apiKey );
}

/**
* Get the pvp subendpoint.
*
* @return PvpEndpoint
*/
public function pvp() {
return new PvpEndpoint( $this->api, $this->apiKey );
}

/**
* Get weekly raid completion.
*
Expand Down
29 changes: 29 additions & 0 deletions src/V2/Endpoint/Account/MailcarrierEndpoint.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 MailcarrierEndpoint 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/mailcarriers';
}

public function get() {
return $this->request()->json();
}
}
29 changes: 29 additions & 0 deletions src/V2/Endpoint/Account/Pvp/HeroEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Account\Pvp;

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

class HeroEndpoint 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/pvp/heroes';
}

public function get() {
return $this->request()->json();
}
}
31 changes: 31 additions & 0 deletions src/V2/Endpoint/Account/Pvp/PvpEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Account\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;

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

$this->apiKey = $apiKey;
}

/**
* The url of this endpoint.
*
* @return string
*/
public function url() {
return 'v2/account/pvp';
}

public function heroes() {
return new HeroEndpoint($this->api, $this->apiKey);
}
}
22 changes: 22 additions & 0 deletions src/V2/Endpoint/Mailcarrier/MailcarrierEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Mailcarrier;

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 MailcarrierEndpoint extends Endpoint implements IBulkEndpoint, ILocalizedEndpoint {
use BulkEndpoint, LocalizedEndpoint;

/**
* The url of this endpoint.
*
* @return string
*/
public function url() {
return 'v2/mailcarriers';
}
}
20 changes: 20 additions & 0 deletions src/V2/Endpoint/Pvp/HeroEndpoint.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 HeroEndpoint extends Endpoint implements IBulkEndpoint, ILocalizedEndpoint {
use BulkEndpoint, LocalizedEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/pvp/heroes';
}
}
8 changes: 8 additions & 0 deletions src/V2/Endpoint/Pvp/PvpEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public function games($apiKey) {
return new GameEndpoint($this->api, $apiKey);
}

/**
* @param string $apiKey
* @return HeroEndpoint
*/
public function heroes($apiKey) {
return new HeroEndpoint($this->api, $apiKey);
}

/**
* @return RankEndpoint
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/V2/AccountEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ public function testInventory() {
$this->assertEquals(12138, $endpoint->get()[1]->id);
}

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

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

$this->mockResponse('[15,4]');
$this->assertEquals([15,4], $endpoint->get());
}

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

Expand Down Expand Up @@ -170,6 +180,23 @@ public function testOutfits() {
$this->assertEquals([1,2,3], $endpoint->get());
}

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

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

public function testPvpHeroes() {
$endpoint = $this->api()->account('test')->pvp()->heroes();

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

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

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

Expand Down
14 changes: 14 additions & 0 deletions tests/V2/MailcarrierEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class MailcarrierEndpointTest extends TestCase {
public function test() {
$endpoint = $this->api()->mailcarriers();

$this->assertEndpointIsBulk( $endpoint );
$this->assertEndpointIsLocalized( $endpoint );
$this->assertEndpointUrl( 'v2/mailcarriers', $endpoint );

$this->mockResponse('[1,2,3,4,5,6,8,12,13]');
$this->assertEquals( [1,2,3,4,5,6,8,12,13], $endpoint->ids() );
}
}
10 changes: 10 additions & 0 deletions tests/V2/PvpEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function testGames() {
$this->assertContains('4FDC931F-677F-4369-B20A-9FBB6A63B2B4', $endpoint->ids());
}

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

$this->assertEndpointUrl('v2/pvp/heroes', $endpoint);
$this->assertEndpointIsBulk($endpoint);

$this->mockResponse('{"id":"115C140F-C2F5-40EB-8EA2-C3773F2AE468","name":"Nika"}');
$this->assertContains('Nika', $endpoint->get('115C140F-C2F5-40EB-8EA2-C3773F2AE468')->name);
}

public function testRanks() {
$endpoint = $this->api()->pvp()->ranks();

Expand Down

0 comments on commit 9b226ef

Please sign in to comment.