From 393da3f9942b50e0ea62c682b3a80f8fffc0a32f Mon Sep 17 00:00:00 2001 From: darthmaim Date: Tue, 9 May 2017 11:42:35 +0200 Subject: [PATCH 1/2] add mailcarrier endpoints --- src/GW2Api.php | 5 ++++ src/V2/Endpoint/Account/AccountEndpoint.php | 9 ++++++ .../Endpoint/Account/MailcarrierEndpoint.php | 29 +++++++++++++++++++ .../Mailcarrier/MailcarrierEndpoint.php | 22 ++++++++++++++ tests/V2/AccountEndpointTest.php | 10 +++++++ tests/V2/MailcarrierEndpointTest.php | 14 +++++++++ 6 files changed, 89 insertions(+) create mode 100644 src/V2/Endpoint/Account/MailcarrierEndpoint.php create mode 100644 src/V2/Endpoint/Mailcarrier/MailcarrierEndpoint.php create mode 100644 tests/V2/MailcarrierEndpointTest.php diff --git a/src/GW2Api.php b/src/GW2Api.php index 99a2436..05c443c 100644 --- a/src/GW2Api.php +++ b/src/GW2Api.php @@ -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; @@ -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 ); } diff --git a/src/V2/Endpoint/Account/AccountEndpoint.php b/src/V2/Endpoint/Account/AccountEndpoint.php index a18f7e0..8c37ec2 100644 --- a/src/V2/Endpoint/Account/AccountEndpoint.php +++ b/src/V2/Endpoint/Account/AccountEndpoint.php @@ -105,6 +105,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. * diff --git a/src/V2/Endpoint/Account/MailcarrierEndpoint.php b/src/V2/Endpoint/Account/MailcarrierEndpoint.php new file mode 100644 index 0000000..3ae6569 --- /dev/null +++ b/src/V2/Endpoint/Account/MailcarrierEndpoint.php @@ -0,0 +1,29 @@ +apiKey = $apiKey; + } + + /** + * {@inheritdoc} + */ + public function url() { + return 'v2/account/mailcarriers'; + } + + public function get() { + return $this->request()->json(); + } +} diff --git a/src/V2/Endpoint/Mailcarrier/MailcarrierEndpoint.php b/src/V2/Endpoint/Mailcarrier/MailcarrierEndpoint.php new file mode 100644 index 0000000..5124a73 --- /dev/null +++ b/src/V2/Endpoint/Mailcarrier/MailcarrierEndpoint.php @@ -0,0 +1,22 @@ +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(); diff --git a/tests/V2/MailcarrierEndpointTest.php b/tests/V2/MailcarrierEndpointTest.php new file mode 100644 index 0000000..e5eee01 --- /dev/null +++ b/tests/V2/MailcarrierEndpointTest.php @@ -0,0 +1,14 @@ +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() ); + } +} From 0e66253154f90b4f8ea778a3c2f71c4b88f4db36 Mon Sep 17 00:00:00 2001 From: darthmaim Date: Tue, 9 May 2017 11:43:20 +0200 Subject: [PATCH 2/2] add pvp/heroes endpoint --- src/V2/Endpoint/Account/AccountEndpoint.php | 10 +++++++ src/V2/Endpoint/Account/Pvp/HeroEndpoint.php | 29 ++++++++++++++++++ src/V2/Endpoint/Account/Pvp/PvpEndpoint.php | 31 ++++++++++++++++++++ src/V2/Endpoint/Pvp/HeroEndpoint.php | 20 +++++++++++++ src/V2/Endpoint/Pvp/PvpEndpoint.php | 8 +++++ tests/V2/AccountEndpointTest.php | 17 +++++++++++ tests/V2/PvpEndpointTest.php | 10 +++++++ 7 files changed, 125 insertions(+) create mode 100644 src/V2/Endpoint/Account/Pvp/HeroEndpoint.php create mode 100644 src/V2/Endpoint/Account/Pvp/PvpEndpoint.php create mode 100644 src/V2/Endpoint/Pvp/HeroEndpoint.php diff --git a/src/V2/Endpoint/Account/AccountEndpoint.php b/src/V2/Endpoint/Account/AccountEndpoint.php index 8c37ec2..0d8e193 100644 --- a/src/V2/Endpoint/Account/AccountEndpoint.php +++ b/src/V2/Endpoint/Account/AccountEndpoint.php @@ -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; @@ -150,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. * diff --git a/src/V2/Endpoint/Account/Pvp/HeroEndpoint.php b/src/V2/Endpoint/Account/Pvp/HeroEndpoint.php new file mode 100644 index 0000000..dba641a --- /dev/null +++ b/src/V2/Endpoint/Account/Pvp/HeroEndpoint.php @@ -0,0 +1,29 @@ +apiKey = $apiKey; + } + + /** + * {@inheritdoc} + */ + public function url() { + return 'v2/account/pvp/heroes'; + } + + public function get() { + return $this->request()->json(); + } +} diff --git a/src/V2/Endpoint/Account/Pvp/PvpEndpoint.php b/src/V2/Endpoint/Account/Pvp/PvpEndpoint.php new file mode 100644 index 0000000..f3bfbf7 --- /dev/null +++ b/src/V2/Endpoint/Account/Pvp/PvpEndpoint.php @@ -0,0 +1,31 @@ +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); + } +} diff --git a/src/V2/Endpoint/Pvp/HeroEndpoint.php b/src/V2/Endpoint/Pvp/HeroEndpoint.php new file mode 100644 index 0000000..4e15a1f --- /dev/null +++ b/src/V2/Endpoint/Pvp/HeroEndpoint.php @@ -0,0 +1,20 @@ +api, $apiKey); } + /** + * @param string $apiKey + * @return HeroEndpoint + */ + public function heroes($apiKey) { + return new HeroEndpoint($this->api, $apiKey); + } + /** * @return RankEndpoint */ diff --git a/tests/V2/AccountEndpointTest.php b/tests/V2/AccountEndpointTest.php index 1036321..3965645 100644 --- a/tests/V2/AccountEndpointTest.php +++ b/tests/V2/AccountEndpointTest.php @@ -180,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(); diff --git a/tests/V2/PvpEndpointTest.php b/tests/V2/PvpEndpointTest.php index 590a950..86cd108 100644 --- a/tests/V2/PvpEndpointTest.php +++ b/tests/V2/PvpEndpointTest.php @@ -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();