Skip to content

Commit

Permalink
Merge pull request #34 from GW2Treasures/endpoints/character-speciali…
Browse files Browse the repository at this point in the history
…zations

Add /v2/characters/:id/specializations endpoint
  • Loading branch information
darthmaim committed Sep 18, 2015
2 parents a32656f + 24e39ba commit c410b90
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] <br>`GW2Api::characters()->equipment()` | 🔒
/v2/characters/:id/inventory | [Character\InventoryEndpoint][Character\InventoryEndpoint] <br>`GW2Api::characters()->inventory()` | 🔒
~~/v2/characters/:id/recipes~~ | *disabled* | 🔒🚫
~~/v2/characters/:id/specializations~~ | *disabled* | 🔒🚫
/v2/characters/:id/specializations | [Character\SpecializationEndpoint][Character\SpecializationEndpoint] <br>`GW2Api::characters()->specializations()` | 🔒
/v2/colors | [Color\ColorEndpoint][ColorEndpoint] <br>`GW2Api::colors()` | 📦🌏
/v2/commerce/exchange | [Commerce\ExchangeEndpoint][Commerce\ExchangeEndpoint] <br>`GW2Api::commerce()->exchange()` |
/v2/commerce/listings | [Commerce\ListingEndpoint][Commerce\ListingEndpoint] <br>`GW2Api::commerce()->listings()` | 📦
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions src/V2/Endpoint/Character/CharacterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
35 changes: 35 additions & 0 deletions src/V2/Endpoint/Character/SpecializationEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Character;

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

class SpecializationEndpoint extends Endpoint implements IAuthenticatedEndpoint {
use AuthenticatedEndpoint;

protected $character;

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

$this->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;
}
}
23 changes: 23 additions & 0 deletions tests/V2/CharacterSpecializationEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace V2;

use TestCase;

class SpecializationEquipmentEndpointTest extends TestCase {
public function test() {
$endpoint = $this->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 );
}
}

0 comments on commit c410b90

Please sign in to comment.