Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Botamp/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Botamp;

use Botamp\Api\ApiResource;
use Botamp\Api\ApiResponse;
use Botamp\Exceptions;
use Http\Client\Common;
use Http\Client\Common\Plugin;
Expand Down Expand Up @@ -78,6 +79,12 @@ public function getApiVersion()
return $this->apiVersion;
}

public function getAttributes()
{
$url = $this->getApiBase().'/'.$this->getApiVersion().'/me';
return ApiResponse::getContent($this->getHttpClient()->get($url));
}

private function setHttpClient(HttpClient $httpClient, MessageFactory $messageFactory)
{
$plugins = [
Expand Down
20 changes: 20 additions & 0 deletions tests/Botamp/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public function test_ShouldSetApiVersion($apiVersion)
$this->assertEquals(strtolower($apiVersion), $this->client->getApiVersion());
}

public function testShouldGetAttributes()
{
$attributes = ['page_id' => '123456', 'page_access_token' => 'A123456Z'];
$url = 'https://app.botamp.com/api/v1/me';

$httpClient = $this->getHttpMethodsMock(array('get'));
$httpClient
->expects($this->any())
->method('get')
->with($url, 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, $client->getAttributes());
}

/**
* @expectedException Botamp\Exceptions\Base
* @expectedExceptionMessage No valid api version provided.
Expand Down