diff --git a/lib/Botamp/Api/ApiRequestor.php b/lib/Botamp/Api/ApiRequestor.php index 90b2225..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."/{$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': diff --git a/lib/Botamp/Api/ApiResource.php b/lib/Botamp/Api/ApiResource.php index 31d2601..9569244 100644 --- a/lib/Botamp/Api/ApiResource.php +++ b/lib/Botamp/Api/ApiResource.php @@ -26,7 +26,7 @@ public function all(array $params = []) return new BotampObject(ApiResponse::getContent($response), $this); } - public function get($id) + public function get($id = null) { $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..b616a53 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; @@ -35,6 +34,8 @@ class Client public $me; + public $subscriptions; + public function __construct($apiKey, HttpClient $httpClient = null) { $this->apiKey = $apiKey; @@ -95,6 +96,7 @@ 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); + $this->subscriptions = new ApiResource('subscriptions', $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()); - } -}