diff --git a/README.md b/README.md index 2efdba9..7072316 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ For all examples it is assumed that you have a variable `$api = new GW2Api()`. /v2/characters/:id/equipment | [Character\EquipmentEndpoint][Character\EquipmentEndpoint]
`GW2Api::characters()->equipment()` | 🔒 /v2/characters/:id/inventory | [Character\InventoryEndpoint][Character\InventoryEndpoint]
`GW2Api::characters()->inventory()` | 🔒 ~~/v2/characters/:id/recipes~~ | *disabled* | 🔒🚫 - ~~/v2/characters/:id/specializations~~ | *disabled* | 🔒🚫 + /v2/characters/:id/specializations | [Character\SpecializationEndpoint][Character\SpecializationEndpoint]
`GW2Api::characters()->specializations()` | 🔒 /v2/colors | [Color\ColorEndpoint][ColorEndpoint]
`GW2Api::colors()` | 📦🌏 /v2/commerce/exchange | [Commerce\ExchangeEndpoint][Commerce\ExchangeEndpoint]
`GW2Api::commerce()->exchange()` | /v2/commerce/listings | [Commerce\ListingEndpoint][Commerce\ListingEndpoint]
`GW2Api::commerce()->listings()` | 📦 @@ -534,6 +534,25 @@ $api->characters('API_KEY')->inventory('Character Name')->get(); ``` + +#### /v2/characters/:id/specializations +[Character\SpecializationEndpoint]: #v2charactersidspecializations + +`\GW2Treasures\GW2Api\V2\Endpoint\Character\SpecializationEndpoint` +([source](src/V2/Endpoint/Character/SpecializationEndpoint.php)) + +Implements [🔒AuthenticatedEndpoint][AuthenticatedEndpoint]. + +##### Methods + - `get():array` Gets the characters specializations. + +##### Example +```php +$api->characters('API_KEY')->specializations('Character Name')->get(); +// => { pve: [ { id: 41, traits: [232, 214, 226] }, … ], … } +``` + + #### /v2/colors [ColorEndpoint]: #v2colors diff --git a/src/V2/Endpoint/Character/CharacterEndpoint.php b/src/V2/Endpoint/Character/CharacterEndpoint.php index 42c2725..f323478 100644 --- a/src/V2/Endpoint/Character/CharacterEndpoint.php +++ b/src/V2/Endpoint/Character/CharacterEndpoint.php @@ -47,4 +47,14 @@ public function equipment( $character ) { public function inventory( $character ) { return new InventoryEndpoint( $this->api, $this->apiKey, $character ); } + + /** + * Get the specializations of a character. + * + * @param string $character + * @return SpecializationEndpoint + */ + public function specializations( $character ) { + return new SpecializationEndpoint( $this->api, $this->apiKey, $character ); + } } diff --git a/src/V2/Endpoint/Character/SpecializationEndpoint.php b/src/V2/Endpoint/Character/SpecializationEndpoint.php new file mode 100644 index 0000000..371d98d --- /dev/null +++ b/src/V2/Endpoint/Character/SpecializationEndpoint.php @@ -0,0 +1,35 @@ +apiKey = $apiKey; + $this->character = $character; + } + + /** + * {@inheritdoc} + */ + public function url() { + return 'v2/characters/' . rawurlencode( $this->character ) . '/specializations'; + } + + /** + * @return mixed + */ + public function get() { + return $this->request()->json()->specializations; + } +} diff --git a/tests/V2/CharacterSpecializationEndpointTest.php b/tests/V2/CharacterSpecializationEndpointTest.php new file mode 100644 index 0000000..7a4e8ae --- /dev/null +++ b/tests/V2/CharacterSpecializationEndpointTest.php @@ -0,0 +1,23 @@ +api()->characters('test')->specializations('char'); + + $this->assertEndpointIsAuthenticated( $endpoint ); + $this->assertEndpointUrl( 'v2/characters/char/specializations', $endpoint ); + + $this->mockResponse('{"specializations":{"pve":[{"id":41,"traits":[232,214,226]}]}}'); + $this->assertEquals(41, $endpoint->get()->pve[0]->id); + } + + public function testCharacterNameEncoding() { + $endpoint = $this->api()->characters('test')->equipment('Character Namè'); + + $this->assertEndpointUrl( 'v2/characters/Character%20Nam%C3%A8/equipment', $endpoint ); + } +}