From 2c424e5b614c8c2ff5cfd7a6133feac41f488ac0 Mon Sep 17 00:00:00 2001 From: Rahmane OUSMANE Date: Fri, 18 Nov 2016 01:30:30 +0800 Subject: [PATCH 1/4] Improve the /me endpoint implementation. --- lib/Botamp/Api/ApiResource.php | 5 ++++- lib/Botamp/Api/Me.php | 27 --------------------------- lib/Botamp/Client.php | 3 +-- tests/Botamp/Api/MeTest.php | 30 ------------------------------ 4 files changed, 5 insertions(+), 60 deletions(-) delete mode 100644 lib/Botamp/Api/Me.php delete mode 100644 tests/Botamp/Api/MeTest.php diff --git a/lib/Botamp/Api/ApiResource.php b/lib/Botamp/Api/ApiResource.php index 31d2601..9c45b69 100644 --- a/lib/Botamp/Api/ApiResource.php +++ b/lib/Botamp/Api/ApiResource.php @@ -26,8 +26,11 @@ public function all(array $params = []) return new BotampObject(ApiResponse::getContent($response), $this); } - public function get($id) + public function get($id = null) { + if( $id === null) + return $this->all(); + $response = $this->apiRequestor->send('get', ['id' => $id]); return new BotampObject(ApiResponse::getContent($response), $this); } diff --git a/lib/Botamp/Api/Me.php b/lib/Botamp/Api/Me.php deleted file mode 100644 index 4f7efe4..0000000 --- a/lib/Botamp/Api/Me.php +++ /dev/null @@ -1,27 +0,0 @@ -client = $client; - } - - public function get() - { - $url = $this->client->getApiBase().'/'.$this->client->getApiVersion().'/me'; - return ApiResponse::getContent($this->client->getHttpClient()->get($url)); - } -} diff --git a/lib/Botamp/Client.php b/lib/Botamp/Client.php index 4992f6a..ee58ce1 100644 --- a/lib/Botamp/Client.php +++ b/lib/Botamp/Client.php @@ -3,7 +3,6 @@ namespace Botamp; use Botamp\Api\ApiResource; -use Botamp\Api\Me; use Botamp\Api\ApiResponse; use Botamp\Exceptions; use Http\Client\Common; @@ -95,6 +94,6 @@ private function setHttpClient(HttpClient $httpClient, MessageFactory $messageFa private function bindResources() { $this->entities = new ApiResource('entities', $this); - $this->me = new Me($this); + $this->me = new ApiResource('me', $this); } } diff --git a/tests/Botamp/Api/MeTest.php b/tests/Botamp/Api/MeTest.php deleted file mode 100644 index 5a5ad82..0000000 --- a/tests/Botamp/Api/MeTest.php +++ /dev/null @@ -1,30 +0,0 @@ - '123456', 'page_access_token' => 'A123456Z']; - - $httpClient = $this->getHttpMethodsMock(array('get')); - $httpClient - ->expects($this->any()) - ->method('get') - ->with('https://app.botamp.com/api/v1/me', array()) - ->will($this->returnValue($this->getPSR7Response($attributes))); - - $client = $this->getMock('Botamp\Client', array('getHttpClient'), array('123456789')); - $client->expects($this->any()) - ->method('getHttpClient') - ->willReturn($httpClient); - - $this->assertEquals($attributes, (new Me($client))->get()); - } -} From 2997a63708f64bba15f3196440f9e50fc2ffd62a Mon Sep 17 00:00:00 2001 From: Rahmane OUSMANE Date: Sat, 19 Nov 2016 03:09:30 +0800 Subject: [PATCH 2/4] Improve get method. --- lib/Botamp/Api/ApiRequestor.php | 2 +- lib/Botamp/Api/ApiResource.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Botamp/Api/ApiRequestor.php b/lib/Botamp/Api/ApiRequestor.php index 90b2225..e8de046 100644 --- a/lib/Botamp/Api/ApiRequestor.php +++ b/lib/Botamp/Api/ApiRequestor.php @@ -34,7 +34,7 @@ public function send($action, $params = []) case 'all': return $this->httpClient->get($this->serializeUrl($params)); case 'get': - return $this->httpClient->get($this->url."/{$params['id']}"); + return $this->httpClient->get($this->url.($id !== null ? "/{$params['id']}" : '')); case 'create': return $this->httpClient->post($this->url, [], $this->serializeBody($params)); case 'update': diff --git a/lib/Botamp/Api/ApiResource.php b/lib/Botamp/Api/ApiResource.php index 9c45b69..9569244 100644 --- a/lib/Botamp/Api/ApiResource.php +++ b/lib/Botamp/Api/ApiResource.php @@ -28,9 +28,6 @@ public function all(array $params = []) public function get($id = null) { - if( $id === null) - return $this->all(); - $response = $this->apiRequestor->send('get', ['id' => $id]); return new BotampObject(ApiResponse::getContent($response), $this); } From ff8664bca88b8c57bb1cb59bbdddc61e1edc177b Mon Sep 17 00:00:00 2001 From: Rahmane OUSMANE Date: Sun, 20 Nov 2016 12:50:40 +0800 Subject: [PATCH 3/4] Improve ApiRequestor --- lib/Botamp/Api/ApiRequestor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Botamp/Api/ApiRequestor.php b/lib/Botamp/Api/ApiRequestor.php index e8de046..335d195 100644 --- a/lib/Botamp/Api/ApiRequestor.php +++ b/lib/Botamp/Api/ApiRequestor.php @@ -34,7 +34,7 @@ public function send($action, $params = []) case 'all': return $this->httpClient->get($this->serializeUrl($params)); case 'get': - return $this->httpClient->get($this->url.($id !== null ? "/{$params['id']}" : '')); + return $this->httpClient->get($this->url.( $params['id'] !== null ? '/'.$params['id'] : '')); case 'create': return $this->httpClient->post($this->url, [], $this->serializeBody($params)); case 'update': From 17305d54091804be8caa8726537d0c823050bbe3 Mon Sep 17 00:00:00 2001 From: Rahmane OUSMANE Date: Sun, 20 Nov 2016 12:50:58 +0800 Subject: [PATCH 4/4] Add /subscriptions endpoint --- lib/Botamp/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Botamp/Client.php b/lib/Botamp/Client.php index ee58ce1..b616a53 100644 --- a/lib/Botamp/Client.php +++ b/lib/Botamp/Client.php @@ -34,6 +34,8 @@ class Client public $me; + public $subscriptions; + public function __construct($apiKey, HttpClient $httpClient = null) { $this->apiKey = $apiKey; @@ -95,5 +97,6 @@ private function bindResources() { $this->entities = new ApiResource('entities', $this); $this->me = new ApiResource('me', $this); + $this->subscriptions = new ApiResource('subscriptions', $this); } }