From 6a3d5fcc75f63d7569b681c4f3fbd4f37694c0f9 Mon Sep 17 00:00:00 2001 From: darthmaim Date: Wed, 10 Jun 2015 02:40:15 +0200 Subject: [PATCH] Add v2/tokeninfo endpoint support --- src/GW2Api.php | 5 +++ .../Endpoint/Tokeninfo/TokeninfoEndpoint.php | 35 +++++++++++++++++++ tests/V2/TokeninfoEndpointTest.php | 18 ++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php create mode 100644 tests/V2/TokeninfoEndpointTest.php diff --git a/src/GW2Api.php b/src/GW2Api.php index 67dd53b..df096c2 100644 --- a/src/GW2Api.php +++ b/src/GW2Api.php @@ -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; @@ -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 ); } diff --git a/src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php b/src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php new file mode 100644 index 0000000..801135b --- /dev/null +++ b/src/V2/Endpoint/Tokeninfo/TokeninfoEndpoint.php @@ -0,0 +1,35 @@ +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(); + } +} diff --git a/tests/V2/TokeninfoEndpointTest.php b/tests/V2/TokeninfoEndpointTest.php new file mode 100644 index 0000000..1904fa3 --- /dev/null +++ b/tests/V2/TokeninfoEndpointTest.php @@ -0,0 +1,18 @@ +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 ); + } +}