Skip to content

Commit

Permalink
Add v2/tokeninfo endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Jun 10, 2015
1 parent f536ae6 commit 6a3d5fc
Show file tree
Hide file tree
Showing 3 changed files with 58 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 @@ -15,6 +15,7 @@
use GW2Treasures\GW2Api\V2\Endpoint\Quaggan\QuagganEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Recipe\RecipeEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Skin\SkinEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\Tokeninfo\TokeninfoEndpoint;
use GW2Treasures\GW2Api\V2\Endpoint\World\WorldEndpoint;
use GW2Treasures\GW2Api\V2\IEndpoint;

Expand Down Expand Up @@ -124,6 +125,10 @@ public function skins() {
return new SkinEndpoint( $this );
}

public function tokeninfo( $apiKey ) {
return new TokeninfoEndpoint( $this, $apiKey );
}

public function worlds() {
return new WorldEndpoint( $this );
}
Expand Down
35 changes: 35 additions & 0 deletions src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace GW2Treasures\GW2Api\V2\Endpoint\Tokeninfo;

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

class TokeninfoEndpoint extends Endpoint implements IAuthenticatedEndpoint {
use AuthenticatedEndpoint;

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

$this->apiKey = $apiKey;
}


/**
* @inheritdoc
*/
protected function url() {
return 'v2/tokeninfo';
}

/**
* Get info about the used api key.
*
* @return mixed
*/
public function get() {
return $this->request()->json();
}
}
18 changes: 18 additions & 0 deletions tests/V2/TokeninfoEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class TokeninfoEndpointTest extends TestCase {
public function test() {
$this->mockResponse('{
"id": "017A2B0C-A6C5-CC4D-A055-680F427CE8FD",
"name": "public key",
"permissions": [
"account",
"characters"
]
}');

$tokeninfo = $this->api()->tokeninfo('api_key')->get();
$this->assertEquals( 'public key', $tokeninfo->name );
$this->assertContains( 'characters', $tokeninfo->permissions );
}
}

0 comments on commit 6a3d5fc

Please sign in to comment.