Skip to content

Commit

Permalink
Merge pull request #111 from GW2Treasures/endpoints/home
Browse files Browse the repository at this point in the history
Add /v2/home endpoints
  • Loading branch information
darthmaim authored Mar 20, 2019
2 parents 38186e7 + 740af10 commit c6788ab
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ For all examples it is assumed that you have a variable `$api = new GW2Api()`.
/v2/guild/:id/upgrades | [Guild\Authenticated\UpgradeEndpoint][Guild\Authenticated\UpgradeEndpoint] <br>`GW2Api::guild()->upgradesOf()` | 🔒
/v2/guild/permissions | [Guild\PermissionEndpoint][Guild\PermissionEndpoint] <br>`GW2Api::guild()->permissionsOf()` | 📦🌏
/v2/guild/upgrades | [Guild\UpgradeEndpoint][Guild\UpgradeEndpoint] <br>`GW2Api::guild()->upgradesOf()` | 📦🌏
/v2/home/cats | [Home\CatEndpoint][Home\CatEndpoint] <br>`GW2Api::home()->cats()` | 📦
/v2/home/nodes | [Home\NodeEndpoint][Home\NodeEndpoint] <br>`GW2Api::home()->nodes()` | 📦
/v2/items | [Item\ItemEndpoint][ItemEndpoint] <br>`GW2Api::items()` | 📦🌏
/v2/itemstats | [Itemstat\ItemstatEndpoint][ItemstatEndpoint] <br>`GW2Api::itemstats()` | 📦🌏
~~/v2/leaderboards~~ | *disabled* | 🚫
Expand Down Expand Up @@ -1471,6 +1473,42 @@ $api->guild()->upgrades()->get(38);
```


#### /v2/home/cats
[Home\CatEndpoint]: #v2homecats

`\GW2Treasures\GW2Api\V2\Endpoint\Home\CatEndpoint`
([source](src/V2/Endpoint/Home/CatEndpoint.php))

Implements [📦BulkEndpoint][BulkEndpoint].

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

##### Example
```php
$api->home()->cats()->get('1');
// => { id: 1, hint: "chicken", … }
```


#### /v2/home/nodes
[Home\NodeEndpoint]: #v2homenodes

`\GW2Treasures\GW2Api\V2\Endpoint\Home\NodeEndpoint`
([source](src/V2/Endpoint/Home/NodeEndpoint.php))

Implements [📦BulkEndpoint][BulkEndpoint].

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

##### Example
```php
$api->mounts()->skins()->ids();
// => [ "advanced_cloth_rack", "advanced_leather_rack", … ]
```


#### /v2/items
[ItemEndpoint]: #v2items

Expand Down
5 changes: 5 additions & 0 deletions src/GW2Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use GW2Treasures\GW2Api\V2\Endpoint\Glider\GliderEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Guild\GuildEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Guild\RestrictedGuildHandler;
use GW2Treasures\GW2Api\V2\Endpoint\Home\HomeEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Item\ItemEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Itemstat\ItemstatEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Legend\LegendEndpoint;
Expand Down Expand Up @@ -214,6 +215,10 @@ public function guild() {
return new GuildEndpoint( $this );
}

public function home() {
return new HomeEndpoint( $this );
}

public function items() {
return new ItemEndpoint( $this );
}
Expand Down
18 changes: 18 additions & 0 deletions src/V2/Endpoint/Home/CatEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Home;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class CatEndpoint extends Endpoint implements IBulkEndpoint {
use BulkEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/home/cats';
}
}
22 changes: 22 additions & 0 deletions src/V2/Endpoint/Home/HomeEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Home;

use GW2Treasures\GW2Api\V2\Endpoint;

class HomeEndpoint extends Endpoint {
/**
* {@inheritdoc}
*/
public function url() {
return 'v2/home';
}

public function cats() {
return new CatEndpoint( $this->api );
}

public function nodes() {
return new NodeEndpoint( $this->api );
}
}
18 changes: 18 additions & 0 deletions src/V2/Endpoint/Home/NodeEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Home;

use GW2Treasures\GW2Api\V2\Bulk\BulkEndpoint;
use GW2Treasures\GW2Api\V2\Bulk\IBulkEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint;

class NodeEndpoint extends Endpoint implements IBulkEndpoint {
use BulkEndpoint;

/**
* {@inheritdoc}
*/
public function url() {
return 'v2/home/nodes';
}
}
29 changes: 29 additions & 0 deletions tests/V2/HomeEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

class HomeEndpointTest extends TestCase {
public function testMounts() {
$endpoint = $this->api()->home();

$this->assertEndpointUrl( 'v2/home', $endpoint );
}

public function testHomeCats() {
$endpoint = $this->api()->home()->cats();

$this->assertEndpointIsBulk( $endpoint );
$this->assertEndpointUrl( 'v2/home/cats', $endpoint );

$this->mockResponse('{"hint":"chicken","id":1}');
$this->assertEquals('chicken', $endpoint->get(1)->hint);
}

public function testHomeNodes() {
$endpoint = $this->api()->home()->nodes();

$this->assertEndpointIsBulk( $endpoint );
$this->assertEndpointUrl( 'v2/home/nodes', $endpoint );

$this->mockResponse('{"id":"advanced_cloth_rack"}');
$this->assertEquals('advanced_cloth_rack', $endpoint->get('advanced_cloth_rack')->id);
}
}

0 comments on commit c6788ab

Please sign in to comment.