From 3d878e5914625813eeba8ed1dda3e95d77b12b94 Mon Sep 17 00:00:00 2001 From: sotiris Date: Mon, 18 Jul 2016 12:00:09 +0200 Subject: [PATCH 01/14] Created the messages and channels endpoint implementation for Chat API --- examples/chatmessages-create.php | 27 ++++++ examples/chatmessages-list.php | 24 +++++ examples/chatmessages-view.php | 20 ++++ src/MessageBird/Client.php | 9 ++ src/MessageBird/Common/HttpClient.php | 1 + src/MessageBird/Objects/ChatChannel.php | 109 ++++++++++++++++++++++ src/MessageBird/Objects/ChatMessage.php | 89 ++++++++++++++++++ src/MessageBird/Resources/Base.php | 14 ++- src/MessageBird/Resources/ChatChannel.php | 28 ++++++ src/MessageBird/Resources/ChatMessage.php | 28 ++++++ 10 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 examples/chatmessages-create.php create mode 100644 examples/chatmessages-list.php create mode 100644 examples/chatmessages-view.php create mode 100644 src/MessageBird/Objects/ChatChannel.php create mode 100644 src/MessageBird/Objects/ChatMessage.php create mode 100644 src/MessageBird/Resources/ChatChannel.php create mode 100644 src/MessageBird/Resources/ChatMessage.php diff --git a/examples/chatmessages-create.php b/examples/chatmessages-create.php new file mode 100644 index 00000000..e1954afc --- /dev/null +++ b/examples/chatmessages-create.php @@ -0,0 +1,27 @@ +contactId = '9d754dac577e3ff103cdf4n29856560'; +$ChatMessage->payload = 'This is a test message to test the Chat API'; +$ChatMessage->type = 'text'; + + +try { + $ChatMessageResult = $MessageBird->chatmessages->create($ChatMessage); + var_dump($ChatMessageResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\MessageBird\Exceptions\BalanceException $e) { + // That means that you are out of credits, so do something about it. + echo 'no balance'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatmessages-list.php b/examples/chatmessages-list.php new file mode 100644 index 00000000..ad02fc27 --- /dev/null +++ b/examples/chatmessages-list.php @@ -0,0 +1,24 @@ +chatmessages->getList(); + var_dump($ChatMessageResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\MessageBird\Exceptions\BalanceException $e) { + // That means that you are out of credits, so do something about it. + echo 'no balance'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatmessages-view.php b/examples/chatmessages-view.php new file mode 100644 index 00000000..1f0f4b2c --- /dev/null +++ b/examples/chatmessages-view.php @@ -0,0 +1,20 @@ +chatmessages->read('d6508edc578ca7641e3919n79796670'); // Set a message id here + var_dump($MessageResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + var_dump($e->getMessage()); +} diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 156dd4d8..b51cb910 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -11,6 +11,7 @@ class Client { const ENDPOINT = 'https://rest.messagebird.com'; + const CHATAPI_ENDPOINT = 'https://chat.messagebird.com/1'; const CLIENT_VERSION = '1.4.1'; @@ -59,6 +60,11 @@ class Client */ protected $HttpClient; + /** + * @var Common\HttpClient + */ + protected $ChatAPIHttpClient; + /** * @param string $accessKey * @param Common\HttpClient $httpClient @@ -66,6 +72,7 @@ class Client public function __construct($accessKey = null, Common\HttpClient $httpClient = null) { if ($httpClient == null) { + $this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); $this->HttpClient = new Common\HttpClient(self::ENDPOINT); } else { $this->HttpClient = $httpClient; @@ -84,6 +91,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->voicemessages = new Resources\VoiceMessage($this->HttpClient); $this->lookup = new Resources\Lookup($this->HttpClient); $this->lookupHlr = new Resources\LookupHlr($this->HttpClient); + $this->chatmessages = new Resources\ChatMessage($this->ChatAPIHttpClient); } /** @@ -92,6 +100,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n public function setAccessKey ($accessKey) { $Authentication = new Common\Authentication($accessKey); + $this->ChatAPIHttpClient->setAuthentication($Authentication); $this->HttpClient->setAuthentication($Authentication); } diff --git a/src/MessageBird/Common/HttpClient.php b/src/MessageBird/Common/HttpClient.php index 5db9a9ed..501dd626 100644 --- a/src/MessageBird/Common/HttpClient.php +++ b/src/MessageBird/Common/HttpClient.php @@ -15,6 +15,7 @@ class HttpClient const REQUEST_GET = "GET"; const REQUEST_POST = "POST"; const REQUEST_DELETE = "DELETE"; + const REQUEST_PUT = "PUT"; const HTTP_NO_CONTENT = 204; diff --git a/src/MessageBird/Objects/ChatChannel.php b/src/MessageBird/Objects/ChatChannel.php new file mode 100644 index 00000000..eb1fb7bb --- /dev/null +++ b/src/MessageBird/Objects/ChatChannel.php @@ -0,0 +1,109 @@ +Object + * @throws Exceptions\HttpException + * @throws Exceptions\RequestException + * @throws Exceptions\ServerException + */ + public function update($parameters = array ()) + { + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_PUT, $this->resourceName, $parameters); + return $this->processRequest($body); + } +} \ No newline at end of file diff --git a/src/MessageBird/Objects/ChatMessage.php b/src/MessageBird/Objects/ChatMessage.php new file mode 100644 index 00000000..fcecf8b6 --- /dev/null +++ b/src/MessageBird/Objects/ChatMessage.php @@ -0,0 +1,89 @@ +getErrorString()); } - + /** + * @param array $parameters + * + * @return $this->Object + * @throws Exceptions\HttpException + * @throws Exceptions\RequestException + * @throws Exceptions\ServerException + */ + public function update($parameters = array ()) + { + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_PUT, $this->resourceName, $parameters); + return $this->processRequest($body); + } } diff --git a/src/MessageBird/Resources/ChatChannel.php b/src/MessageBird/Resources/ChatChannel.php new file mode 100644 index 00000000..2e5b183d --- /dev/null +++ b/src/MessageBird/Resources/ChatChannel.php @@ -0,0 +1,28 @@ +setObject(new Objects\ChatChannel()); + $this->setResourceName('channels'); + + parent::__construct($HttpClient); + } +} diff --git a/src/MessageBird/Resources/ChatMessage.php b/src/MessageBird/Resources/ChatMessage.php new file mode 100644 index 00000000..42387177 --- /dev/null +++ b/src/MessageBird/Resources/ChatMessage.php @@ -0,0 +1,28 @@ +setObject(new Objects\ChatMessage()); + $this->setResourceName('messages'); + + parent::__construct($HttpClient); + } +} From d01f7a242d0113707bf0b3ae8018fbfd50a9432c Mon Sep 17 00:00:00 2001 From: sotiris Date: Mon, 18 Jul 2016 14:53:53 +0200 Subject: [PATCH 02/14] added Chat Channels and chat channel examples --- examples/chatchannels-create.php | 42 +++++++++++++++++++++++ examples/chatchannels-delete.php | 18 ++++++++++ examples/chatchannels-list.php | 20 +++++++++++ examples/chatchannels-view.php | 20 +++++++++++ src/MessageBird/Client.php | 3 ++ src/MessageBird/Resources/ChatChannel.php | 1 - src/MessageBird/Resources/ChatMessage.php | 1 - 7 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 examples/chatchannels-create.php create mode 100644 examples/chatchannels-delete.php create mode 100644 examples/chatchannels-list.php create mode 100644 examples/chatchannels-view.php diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php new file mode 100644 index 00000000..90b5af12 --- /dev/null +++ b/examples/chatchannels-create.php @@ -0,0 +1,42 @@ +name = 'Test Channel Telegram'; +$ChatChannel->platform_id = 'e82d332c5649a5f911e569n69040697'; + +/* + * + * Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) + * are required when creating a channel for this platform. + * Template hashes are JSON objects which contain name-value pairs that indicate the parameter names + * and respective data types which are required when creating a related object. + * The contactTemplate relates to the contactDetails parameter of a contact object. + * The channelTemplate relates to the channelDetails parameter of a channel object. + * Hash names ending in |empty denote parameters which are optional. + * + */ + +$ChatChannel->channelDetails = + array( + 'botName' => 'testBot', + 'token' => '1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA' + ); + +try { + $ChatChannelResult = $MessageBird->chatchannels->create($ChatChannel); + var_dump($ChatChannelResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatchannels-delete.php b/examples/chatchannels-delete.php new file mode 100644 index 00000000..a4053c51 --- /dev/null +++ b/examples/chatchannels-delete.php @@ -0,0 +1,18 @@ +chatchannels->delete('4affac2c577fb22e373921n52675409'); // Set a message id here + var_dump('Deleted: ' . $deleted); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatchannels-list.php b/examples/chatchannels-list.php new file mode 100644 index 00000000..344239d5 --- /dev/null +++ b/examples/chatchannels-list.php @@ -0,0 +1,20 @@ +chatchannels->getList(); + var_dump($ChatChannelResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatchannels-view.php b/examples/chatchannels-view.php new file mode 100644 index 00000000..f84bb4be --- /dev/null +++ b/examples/chatchannels-view.php @@ -0,0 +1,20 @@ +chatchannels->read('0051af4c577e3eebbc3631n95680736'); // Set a message id here + var_dump($ChatChannelResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index b51cb910..84648726 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -92,6 +92,9 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->lookup = new Resources\Lookup($this->HttpClient); $this->lookupHlr = new Resources\LookupHlr($this->HttpClient); $this->chatmessages = new Resources\ChatMessage($this->ChatAPIHttpClient); + $this->chatchannels = new Resources\ChatChannel($this->ChatAPIHttpClient); + $this->chatplatforms = new Resources\ChatPlatform($this->ChatAPIHttpClient); + } /** diff --git a/src/MessageBird/Resources/ChatChannel.php b/src/MessageBird/Resources/ChatChannel.php index 2e5b183d..1f225917 100644 --- a/src/MessageBird/Resources/ChatChannel.php +++ b/src/MessageBird/Resources/ChatChannel.php @@ -15,7 +15,6 @@ class ChatChannel extends Base /** * @param Common\HttpClient $HttpClient - * @internal param $resourceName */ public function __construct(Common\HttpClient $HttpClient) { diff --git a/src/MessageBird/Resources/ChatMessage.php b/src/MessageBird/Resources/ChatMessage.php index 42387177..64ca96c1 100644 --- a/src/MessageBird/Resources/ChatMessage.php +++ b/src/MessageBird/Resources/ChatMessage.php @@ -15,7 +15,6 @@ class ChatMessage extends Base /** * @param Common\HttpClient $HttpClient - * @internal param $resourceName */ public function __construct(Common\HttpClient $HttpClient) { From feb2fe54b64bffddbb3db0c045b34e8461cd8487 Mon Sep 17 00:00:00 2001 From: sotiris Date: Mon, 18 Jul 2016 17:22:13 +0200 Subject: [PATCH 03/14] added Chat platforms, some changes on chat messages --- examples/chatchannels-create.php | 1 + examples/chatmessages-list.php | 6 +- examples/chatmessages-view.php | 2 +- examples/chatplatforms-list.php | 20 ++++++ src/MessageBird/Client.php | 12 ++-- src/MessageBird/Objects/ChatPlatform.php | 82 ++++++++++++++++++++++ src/MessageBird/Resources/ChatPlatform.php | 27 +++++++ 7 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 examples/chatplatforms-list.php create mode 100644 src/MessageBird/Objects/ChatPlatform.php create mode 100644 src/MessageBird/Resources/ChatPlatform.php diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index 90b5af12..ad0a096a 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -15,6 +15,7 @@ * * Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) * are required when creating a channel for this platform. + * * Template hashes are JSON objects which contain name-value pairs that indicate the parameter names * and respective data types which are required when creating a related object. * The contactTemplate relates to the contactDetails parameter of a contact object. diff --git a/examples/chatmessages-list.php b/examples/chatmessages-list.php index ad02fc27..d9e902f0 100644 --- a/examples/chatmessages-list.php +++ b/examples/chatmessages-list.php @@ -14,11 +14,7 @@ } catch (\MessageBird\Exceptions\AuthenticateException $e) { // That means that your accessKey is unknown echo 'wrong login'; - -} catch (\MessageBird\Exceptions\BalanceException $e) { - // That means that you are out of credits, so do something about it. - echo 'no balance'; - + } catch (\Exception $e) { echo $e->getMessage(); } diff --git a/examples/chatmessages-view.php b/examples/chatmessages-view.php index 1f0f4b2c..6bf9500d 100644 --- a/examples/chatmessages-view.php +++ b/examples/chatmessages-view.php @@ -16,5 +16,5 @@ echo 'wrong login'; } catch (\Exception $e) { - var_dump($e->getMessage()); + echo $e->getMessage(); } diff --git a/examples/chatplatforms-list.php b/examples/chatplatforms-list.php new file mode 100644 index 00000000..adeef681 --- /dev/null +++ b/examples/chatplatforms-list.php @@ -0,0 +1,20 @@ +chatplatforms->getList(); + var_dump($ChatPlatformResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 84648726..1be3da24 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -71,12 +71,10 @@ class Client */ public function __construct($accessKey = null, Common\HttpClient $httpClient = null) { - if ($httpClient == null) { - $this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); - $this->HttpClient = new Common\HttpClient(self::ENDPOINT); - } else { - $this->HttpClient = $httpClient; - } + + $this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); + $this->HttpClient = new Common\HttpClient(self::ENDPOINT); + $this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); $this->HttpClient->addUserAgentString($this->getPhpVersion()); @@ -94,7 +92,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->chatmessages = new Resources\ChatMessage($this->ChatAPIHttpClient); $this->chatchannels = new Resources\ChatChannel($this->ChatAPIHttpClient); $this->chatplatforms = new Resources\ChatPlatform($this->ChatAPIHttpClient); - + } /** diff --git a/src/MessageBird/Objects/ChatPlatform.php b/src/MessageBird/Objects/ChatPlatform.php new file mode 100644 index 00000000..839d40f6 --- /dev/null +++ b/src/MessageBird/Objects/ChatPlatform.php @@ -0,0 +1,82 @@ +setObject(new Objects\ChatPlatform()); + $this->setResourceName('platforms'); + + parent::__construct($HttpClient); + } +} From 4c7d2af174ac0007b1830d03c1e364ed61c1b312 Mon Sep 17 00:00:00 2001 From: sotiris Date: Mon, 18 Jul 2016 17:36:14 +0200 Subject: [PATCH 04/14] fixed Client.php to do proper assignment of httpClients for both chatapi and regular --- src/MessageBird/Client.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 1be3da24..70574d9d 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -71,10 +71,14 @@ class Client */ public function __construct($accessKey = null, Common\HttpClient $httpClient = null) { - - $this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); - $this->HttpClient = new Common\HttpClient(self::ENDPOINT); - + if ($httpClient == null) { + $this->ChatAPIHttpClient = new Common\HttpClient(self::CHATAPI_ENDPOINT); + $this->HttpClient = new Common\HttpClient(self::ENDPOINT); + } else { + $this->ChatAPIHttpClient = $httpClient; + $this->HttpClient = $httpClient; + } + $this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); $this->HttpClient->addUserAgentString($this->getPhpVersion()); @@ -101,6 +105,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n public function setAccessKey ($accessKey) { $Authentication = new Common\Authentication($accessKey); + $this->ChatAPIHttpClient->setAuthentication($Authentication); $this->HttpClient->setAuthentication($Authentication); } From 5f35d27cf0b1ad73805809b29278743d5318981d Mon Sep 17 00:00:00 2001 From: sotiris Date: Tue, 19 Jul 2016 11:33:14 +0200 Subject: [PATCH 05/14] added unit tests for ChatAPI (platforms/channels/messages) --- examples/chatchannels-create.php | 14 +--- src/MessageBird/Client.php | 5 +- tests/integration/BaseTest.php | 4 ++ tests/integration/chat/ChatTest.php | 102 ++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 tests/integration/chat/ChatTest.php diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index ad0a096a..a13ac0d1 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -11,18 +11,8 @@ $ChatChannel->name = 'Test Channel Telegram'; $ChatChannel->platform_id = 'e82d332c5649a5f911e569n69040697'; -/* - * - * Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) - * are required when creating a channel for this platform. - * - * Template hashes are JSON objects which contain name-value pairs that indicate the parameter names - * and respective data types which are required when creating a related object. - * The contactTemplate relates to the contactDetails parameter of a contact object. - * The channelTemplate relates to the channelDetails parameter of a channel object. - * Hash names ending in |empty denote parameters which are optional. - * - */ +// Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) +// are required when creating a channel for this platform. $ChatChannel->channelDetails = array( diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 70574d9d..7af63f3c 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -78,10 +78,13 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->ChatAPIHttpClient = $httpClient; $this->HttpClient = $httpClient; } - + $this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); $this->HttpClient->addUserAgentString($this->getPhpVersion()); + $this->ChatAPIHttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION); + $this->ChatAPIHttpClient->addUserAgentString($this->getPhpVersion()); + if ($accessKey !== null) { $this->setAccessKey($accessKey); } diff --git a/tests/integration/BaseTest.php b/tests/integration/BaseTest.php index 4632cf2b..fbc1d5fb 100644 --- a/tests/integration/BaseTest.php +++ b/tests/integration/BaseTest.php @@ -14,6 +14,10 @@ public function testClientConstructor() $this->assertInstanceOf('MessageBird\Resources\Messages', $MessageBird->messages); $this->assertInstanceOf('MessageBird\Resources\VoiceMessage', $MessageBird->voicemessages); $this->assertInstanceOf('MessageBird\Resources\Verify', $MessageBird->verify); + $this->assertInstanceOf('MessageBird\Resources\ChatMessage', $MessageBird->chatmessages); + $this->assertInstanceOf('MessageBird\Resources\ChatPlatform', $MessageBird->chatplatforms); + $this->assertInstanceOf('MessageBird\Resources\ChatChannel', $MessageBird->chatchannels); + } public function testHttpClientMock() diff --git a/tests/integration/chat/ChatTest.php b/tests/integration/chat/ChatTest.php new file mode 100644 index 00000000..0d235e7c --- /dev/null +++ b/tests/integration/chat/ChatTest.php @@ -0,0 +1,102 @@ +client = new \MessageBird\Client('YOUR_ACCESS_KEY', $this->mockClient); + } + + public function testCreateChatMessage() + { + $ChatMessage = new \MessageBird\Objects\ChatMessage(); + $ChatMessage->contactId = '9d754dac577e3ff103cdf4n29856560'; + $ChatMessage->payload = 'This is a test message to test the Chat API'; + $ChatMessage->type = 'text'; + + $this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(200, '', '{"type":"text","payload":"This is a test message to test the Chat API","contactId":"9d754dac577e3ff103cdf4n29856560","endpoint":null}')); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'messages', null, '{"type":"text","payload":"This is a test message to test the Chat API","contactId":"9d754dac577e3ff103cdf4n29856560","endpoint":null}'); + $this->client->chatmessages->create($ChatMessage); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testListChatMessage() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'messages', array ('offset' => 100, 'limit' => 30), null); + $ChatMessageList = $this->client->chatmessages->getList(array ('offset' => 100, 'limit' => 30)); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadChatMessage() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'messages/id', null, null); + $ChatMessageList = $this->client->chatmessages->read("id"); + } + + + public function testCreateChatChannel() + { + $ChatChannel = new \MessageBird\Objects\ChatChannel(); + $ChatChannel->name = 'Test Channel Telegram'; + $ChatChannel->platform_id = 'e84f332c5649a5f911e569n69330697'; + + $ChatChannel->channelDetails = + array( + 'botName' => 'testBot', + 'token' => '1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA' + ); + + $this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(200, '', '{"name":"Test Channel Telegram","platform_id":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}')); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'channels', null, '{"name":"Test Channel Telegram","platform_id":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}'); + $this->client->chatchannels->create($ChatChannel); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testListChatChannels() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'channels', array ('offset' => 100, 'limit' => 30), null); + $ChannelList = $this->client->chatchannels->getList(array ('offset' => 100, 'limit' => 30)); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadChatChannel() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'channels/id', null, null); + $Channel = $this->client->chatchannels->read("id"); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testDeleteChannel() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("DELETE", 'channels/id', null, null); + $Channel = $this->client->chatchannels->delete("id"); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testListChatPlatforms() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'platforms', array ('offset' => 100, 'limit' => 30), null); + $ChannelList = $this->client->chatplatforms->getList(array ('offset' => 100, 'limit' => 30)); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadChatPlatform() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'platforms/id', null, null); + $Channel = $this->client->chatplatforms->read("id"); + } +} From f6ee6b884a7eee4a3bfbfc63846e0730c4f99019 Mon Sep 17 00:00:00 2001 From: sotiris Date: Tue, 19 Jul 2016 14:10:31 +0200 Subject: [PATCH 06/14] Added ChatAPI contact object --- examples/chatchannels-list.php | 3 - examples/chatchannels-view.php | 5 +- examples/chatcontacts-delete.php | 18 +++++ examples/chatcontacts-list.php | 18 +++++ examples/chatcontacts-view.php | 18 +++++ src/MessageBird/Client.php | 1 + src/MessageBird/Objects/ChatContact.php | 81 +++++++++++++++++++++++ src/MessageBird/Resources/ChatContact.php | 27 ++++++++ tests/integration/chat/ChatTest.php | 27 ++++++++ 9 files changed, 191 insertions(+), 7 deletions(-) create mode 100644 examples/chatcontacts-delete.php create mode 100644 examples/chatcontacts-list.php create mode 100644 examples/chatcontacts-view.php create mode 100644 src/MessageBird/Objects/ChatContact.php create mode 100644 src/MessageBird/Resources/ChatContact.php diff --git a/examples/chatchannels-list.php b/examples/chatchannels-list.php index 344239d5..570499f1 100644 --- a/examples/chatchannels-list.php +++ b/examples/chatchannels-list.php @@ -4,9 +4,6 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\ChatChannel(); - - try { $ChatChannelResult = $MessageBird->chatchannels->getList(); var_dump($ChatChannelResult); diff --git a/examples/chatchannels-view.php b/examples/chatchannels-view.php index f84bb4be..e0a0cfa8 100644 --- a/examples/chatchannels-view.php +++ b/examples/chatchannels-view.php @@ -4,11 +4,8 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\ChatChannel(); - - try { - $ChatChannelResult = $MessageBird->chatchannels->read('0051af4c577e3eebbc3631n95680736'); // Set a message id here + $ChatChannelResult = $MessageBird->chatchannels->read('0051af4c577e3eebbc3631n95680736'); // Set a channel id here var_dump($ChatChannelResult); } catch (\MessageBird\Exceptions\AuthenticateException $e) { diff --git a/examples/chatcontacts-delete.php b/examples/chatcontacts-delete.php new file mode 100644 index 00000000..9d7150be --- /dev/null +++ b/examples/chatcontacts-delete.php @@ -0,0 +1,18 @@ +chatcontacts->delete('4affa2345d7fb22e373921n524df5409'); // Set a message id here + var_dump('Deleted : ' . $deleted); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatcontacts-list.php b/examples/chatcontacts-list.php new file mode 100644 index 00000000..31ad8c83 --- /dev/null +++ b/examples/chatcontacts-list.php @@ -0,0 +1,18 @@ +chatcontacts->getList(); + var_dump($ChatContactResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/examples/chatcontacts-view.php b/examples/chatcontacts-view.php new file mode 100644 index 00000000..b0212c3c --- /dev/null +++ b/examples/chatcontacts-view.php @@ -0,0 +1,18 @@ +chatcontacts->read('0051af4c577e3eebbc3631n95680736'); // Set a contact id here + var_dump($ChatContactResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 7af63f3c..0f4f873f 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -99,6 +99,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->chatmessages = new Resources\ChatMessage($this->ChatAPIHttpClient); $this->chatchannels = new Resources\ChatChannel($this->ChatAPIHttpClient); $this->chatplatforms = new Resources\ChatPlatform($this->ChatAPIHttpClient); + $this->chatcontacts = new Resources\ChatContact($this->ChatAPIHttpClient); } diff --git a/src/MessageBird/Objects/ChatContact.php b/src/MessageBird/Objects/ChatContact.php new file mode 100644 index 00000000..51cd3507 --- /dev/null +++ b/src/MessageBird/Objects/ChatContact.php @@ -0,0 +1,81 @@ +setObject(new Objects\ChatContact()); + $this->setResourceName('contacts'); + + parent::__construct($HttpClient); + } +} diff --git a/tests/integration/chat/ChatTest.php b/tests/integration/chat/ChatTest.php index 0d235e7c..40c92f4a 100644 --- a/tests/integration/chat/ChatTest.php +++ b/tests/integration/chat/ChatTest.php @@ -99,4 +99,31 @@ public function testReadChatPlatform() $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'platforms/id', null, null); $Channel = $this->client->chatplatforms->read("id"); } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testListChatContacts() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'contacts', array ('offset' => 100, 'limit' => 30), null); + $ContactList = $this->client->chatcontacts->getList(array ('offset' => 100, 'limit' => 30)); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadChatContact() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'contacts/id', null, null); + $Contact = $this->client->chatcontacts->read("id"); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testDeleteContact() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("DELETE", 'contacts/id', null, null); + $contact = $this->client->chatcontacts->delete("id"); + } } From 58466870601fee2afc3f2a63029eab01b8660b94 Mon Sep 17 00:00:00 2001 From: sotiris Date: Wed, 20 Jul 2016 09:56:56 +0200 Subject: [PATCH 07/14] fixed Update (PUT request) for channels --- examples/chatchannels-update.php | 23 +++++++++++++++++++++++ src/MessageBird/Common/HttpClient.php | 3 +++ src/MessageBird/Objects/ChatChannel.php | 18 ++---------------- src/MessageBird/Resources/Base.php | 25 ++++++++++++++++++------- 4 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 examples/chatchannels-update.php diff --git a/examples/chatchannels-update.php b/examples/chatchannels-update.php new file mode 100644 index 00000000..a3b31fe2 --- /dev/null +++ b/examples/chatchannels-update.php @@ -0,0 +1,23 @@ +name = 'New name'; +$ChatChannel->callbackUrl = 'http://newurl.dev'; + + +try { + + $ChatChannelResult = $MessageBird->chatchannels->update($ChatChannel, '331af4c577e3asbbc3631455680736'); + var_dump($ChatChannelResult); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + echo $e->getMessage(); +} diff --git a/src/MessageBird/Common/HttpClient.php b/src/MessageBird/Common/HttpClient.php index 501dd626..d065d9f6 100644 --- a/src/MessageBird/Common/HttpClient.php +++ b/src/MessageBird/Common/HttpClient.php @@ -111,6 +111,9 @@ public function performHttpRequest($method, $resourceName, $query = null, $body curl_setopt($curl, CURLOPT_POSTFIELDS, $body); } elseif ($method === self::REQUEST_DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_DELETE); + } elseif ($method === self::REQUEST_PUT){ + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PUT); + curl_setopt($curl, CURLOPT_POSTFIELDS, $body); } // Some servers have outdated or incorrect certificates, Use the included CA-bundle diff --git a/src/MessageBird/Objects/ChatChannel.php b/src/MessageBird/Objects/ChatChannel.php index eb1fb7bb..6c2ac99b 100644 --- a/src/MessageBird/Objects/ChatChannel.php +++ b/src/MessageBird/Objects/ChatChannel.php @@ -22,7 +22,7 @@ class ChatChannel extends Base * * @var string */ - public $platform_id; + public $platformId; /** * A hash of values as defined in channel_template of a Platform @@ -38,7 +38,6 @@ class ChatChannel extends Base */ public $callbackUrl; - /** * The endpoint of the action (platforms, messages, channels, contacts) * @@ -92,18 +91,5 @@ public function loadFromArray ($object) return $this; } - - /** - * @param array $parameters - * - * @return $this->Object - * @throws Exceptions\HttpException - * @throws Exceptions\RequestException - * @throws Exceptions\ServerException - */ - public function update($parameters = array ()) - { - list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_PUT, $this->resourceName, $parameters); - return $this->processRequest($body); - } + } \ No newline at end of file diff --git a/src/MessageBird/Resources/Base.php b/src/MessageBird/Resources/Base.php index 5edcf6c8..05ab4086 100644 --- a/src/MessageBird/Resources/Base.php +++ b/src/MessageBird/Resources/Base.php @@ -172,16 +172,27 @@ public function processRequest($body) } /** - * @param array $parameters + * @param $object + * @param $id + * @return $this ->Object + * @internal param array $parameters * - * @return $this->Object - * @throws Exceptions\HttpException - * @throws Exceptions\RequestException - * @throws Exceptions\ServerException */ - public function update($parameters = array ()) + public function update($object, $id) { - list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_PUT, $this->resourceName, $parameters); + + $objVars = get_object_vars($object); + $body = array(); + foreach ($objVars as $key => $value) { + if (!is_null($value)) { + $body[$key] = $value; + } + } + + $ResourceName = $this->resourceName . (($id) ? '/' . $id : null); + $body = json_encode($body); + + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_PUT, $ResourceName, false, $body); return $this->processRequest($body); } } From bd6ce368fa54bc212ab259eae9644dbd02037804 Mon Sep 17 00:00:00 2001 From: sotiris Date: Wed, 20 Jul 2016 10:19:44 +0200 Subject: [PATCH 08/14] added channel update unit test --- tests/integration/chat/ChatTest.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/integration/chat/ChatTest.php b/tests/integration/chat/ChatTest.php index 40c92f4a..81830cd5 100644 --- a/tests/integration/chat/ChatTest.php +++ b/tests/integration/chat/ChatTest.php @@ -42,7 +42,7 @@ public function testCreateChatChannel() { $ChatChannel = new \MessageBird\Objects\ChatChannel(); $ChatChannel->name = 'Test Channel Telegram'; - $ChatChannel->platform_id = 'e84f332c5649a5f911e569n69330697'; + $ChatChannel->platformId = 'e84f332c5649a5f911e569n69330697'; $ChatChannel->channelDetails = array( @@ -50,8 +50,8 @@ public function testCreateChatChannel() 'token' => '1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA' ); - $this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(200, '', '{"name":"Test Channel Telegram","platform_id":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}')); - $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'channels', null, '{"name":"Test Channel Telegram","platform_id":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}'); + $this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(200, '', '{"name":"Test Channel Telegram","platformId":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}')); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'channels', null, '{"name":"Test Channel Telegram","platformId":"e84f332c5649a5f911e569n69330697","channelDetails":{"botName":"testBot","token":"1234566778:A34JT44Yr4amk234352et5hvRnHeAEHA"},"callbackUrl":null,"endpoint":null}'); $this->client->chatchannels->create($ChatChannel); } @@ -82,6 +82,17 @@ public function testDeleteChannel() $Channel = $this->client->chatchannels->delete("id"); } + public function testUpdateChatChannel() + { + $ChatChannel = new \MessageBird\Objects\ChatChannel(); + $ChatChannel->name = '9d2345ac577e4f103cd3d4529856560'; + $ChatChannel->callbackUrl = 'http://testurl.dev'; + + $this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(200, '', '{"name":"9d2345ac577e4f103cd3d4529856560","callbackUrl":"http:\/\/testurl.dev"}')); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("PUT", 'channels/234agfgADFH2974gaADFH3hudf9h', null, '{"name":"9d2345ac577e4f103cd3d4529856560","callbackUrl":"http:\/\/testurl.dev"}'); + $this->client->chatchannels->update($ChatChannel,'234agfgADFH2974gaADFH3hudf9h'); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ From 52cc8b87b005099409a435033208e51004decf4c Mon Sep 17 00:00:00 2001 From: sotiris Date: Wed, 20 Jul 2016 11:31:02 +0200 Subject: [PATCH 09/14] added _links attribute (HATEOAS links related to the objects) --- src/MessageBird/Objects/ChatChannel.php | 5 +++++ src/MessageBird/Objects/ChatMessage.php | 5 +++++ src/MessageBird/Objects/ChatPlatform.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/MessageBird/Objects/ChatChannel.php b/src/MessageBird/Objects/ChatChannel.php index 6c2ac99b..f49c0592 100644 --- a/src/MessageBird/Objects/ChatChannel.php +++ b/src/MessageBird/Objects/ChatChannel.php @@ -80,6 +80,11 @@ class ChatChannel extends Base */ protected $deletedAt; + /** + * @var array + */ + protected $_links = array(); + /** * @param $object * diff --git a/src/MessageBird/Objects/ChatMessage.php b/src/MessageBird/Objects/ChatMessage.php index fcecf8b6..3e74cde2 100644 --- a/src/MessageBird/Objects/ChatMessage.php +++ b/src/MessageBird/Objects/ChatMessage.php @@ -75,6 +75,11 @@ class ChatMessage extends Base */ protected $mediaPath; + /** + * @var array + */ + protected $_links = array(); + /** * @param $object * diff --git a/src/MessageBird/Objects/ChatPlatform.php b/src/MessageBird/Objects/ChatPlatform.php index 839d40f6..515d901a 100644 --- a/src/MessageBird/Objects/ChatPlatform.php +++ b/src/MessageBird/Objects/ChatPlatform.php @@ -67,6 +67,11 @@ class ChatPlatform extends Base */ protected $updatedAt; + /** + * @var array + */ + protected $_links; + /** * @param $object * From ef3816f68a69c8f0df0bf286f310a62bf4056d77 Mon Sep 17 00:00:00 2001 From: sotiris Date: Fri, 22 Jul 2016 11:20:17 +0200 Subject: [PATCH 10/14] added getter for id at ChatMessage --- src/MessageBird/Objects/ChatMessage.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MessageBird/Objects/ChatMessage.php b/src/MessageBird/Objects/ChatMessage.php index 3e74cde2..3a8cd135 100644 --- a/src/MessageBird/Objects/ChatMessage.php +++ b/src/MessageBird/Objects/ChatMessage.php @@ -91,4 +91,9 @@ public function loadFromArray ($object) return $this; } + + public function getId() + { + return $this->id; + } } \ No newline at end of file From 672a188c74a4d27840a11e2458f8a4bb348fd0b4 Mon Sep 17 00:00:00 2001 From: sotiris Date: Thu, 11 Aug 2016 17:41:04 +0200 Subject: [PATCH 11/14] Changed namespace for chat-api related objects/resources --- examples/chatchannels-create.php | 2 +- examples/chatchannels-update.php | 2 +- examples/chatplatforms-list.php | 2 +- src/MessageBird/Client.php | 8 ++++---- .../Objects/{ChatChannel.php => Chat/Channel.php} | 10 ++++++---- .../Objects/{ChatContact.php => Chat/Contact.php} | 10 ++++++---- .../Objects/{ChatMessage.php => Chat/Message.php} | 8 +++++--- .../Objects/{ChatPlatform.php => Chat/Platform.php} | 10 ++++++---- .../Resources/{ChatChannel.php => Chat/Channel.php} | 11 ++++++----- .../Resources/{ChatContact.php => Chat/Contact.php} | 11 ++++++----- .../Resources/{ChatMessage.php => Chat/Message.php} | 11 ++++++----- .../Resources/{ChatPlatform.php => Chat/Platform.php} | 11 ++++++----- tests/integration/BaseTest.php | 7 ++++--- tests/integration/chat/ChatTest.php | 6 +++--- 14 files changed, 61 insertions(+), 48 deletions(-) rename src/MessageBird/Objects/{ChatChannel.php => Chat/Channel.php} (91%) rename src/MessageBird/Objects/{ChatContact.php => Chat/Contact.php} (88%) rename src/MessageBird/Objects/{ChatMessage.php => Chat/Message.php} (94%) rename src/MessageBird/Objects/{ChatPlatform.php => Chat/Platform.php} (91%) rename src/MessageBird/Resources/{ChatChannel.php => Chat/Channel.php} (58%) rename src/MessageBird/Resources/{ChatContact.php => Chat/Contact.php} (58%) rename src/MessageBird/Resources/{ChatMessage.php => Chat/Message.php} (58%) rename src/MessageBird/Resources/{ChatPlatform.php => Chat/Platform.php} (58%) diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index a13ac0d1..ff5ba2eb 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\ChatChannel(); +$ChatChannel = new \MessageBird\Objects\Channel(); //Example for telegram channel diff --git a/examples/chatchannels-update.php b/examples/chatchannels-update.php index a3b31fe2..6f03c188 100644 --- a/examples/chatchannels-update.php +++ b/examples/chatchannels-update.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\ChatChannel(); +$ChatChannel = new \MessageBird\Objects\Channel(); $ChatChannel->name = 'New name'; $ChatChannel->callbackUrl = 'http://newurl.dev'; diff --git a/examples/chatplatforms-list.php b/examples/chatplatforms-list.php index adeef681..5d2e46ec 100644 --- a/examples/chatplatforms-list.php +++ b/examples/chatplatforms-list.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatPlatform = new \MessageBird\Objects\ChatChannel(); +$ChatPlatform = new \MessageBird\Objects\Channel(); try { diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 0f4f873f..2d8d10b0 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -96,10 +96,10 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->voicemessages = new Resources\VoiceMessage($this->HttpClient); $this->lookup = new Resources\Lookup($this->HttpClient); $this->lookupHlr = new Resources\LookupHlr($this->HttpClient); - $this->chatmessages = new Resources\ChatMessage($this->ChatAPIHttpClient); - $this->chatchannels = new Resources\ChatChannel($this->ChatAPIHttpClient); - $this->chatplatforms = new Resources\ChatPlatform($this->ChatAPIHttpClient); - $this->chatcontacts = new Resources\ChatContact($this->ChatAPIHttpClient); + $this->chatmessages = new Resources\Chat\Message($this->ChatAPIHttpClient); + $this->chatchannels = new Resources\Chat\Channel($this->ChatAPIHttpClient); + $this->chatplatforms = new Resources\Chat\Platform($this->ChatAPIHttpClient); + $this->chatcontacts = new Resources\Chat\Contact($this->ChatAPIHttpClient); } diff --git a/src/MessageBird/Objects/ChatChannel.php b/src/MessageBird/Objects/Chat/Channel.php similarity index 91% rename from src/MessageBird/Objects/ChatChannel.php rename to src/MessageBird/Objects/Chat/Channel.php index f49c0592..378635c5 100644 --- a/src/MessageBird/Objects/ChatChannel.php +++ b/src/MessageBird/Objects/Chat/Channel.php @@ -1,13 +1,15 @@ setObject(new Objects\ChatChannel()); + $this->setObject(new Objects\Chat\Channel()); $this->setResourceName('channels'); parent::__construct($HttpClient); diff --git a/src/MessageBird/Resources/ChatContact.php b/src/MessageBird/Resources/Chat/Contact.php similarity index 58% rename from src/MessageBird/Resources/ChatContact.php rename to src/MessageBird/Resources/Chat/Contact.php index fdd92f73..36551627 100644 --- a/src/MessageBird/Resources/ChatContact.php +++ b/src/MessageBird/Resources/Chat/Contact.php @@ -1,16 +1,17 @@ setObject(new Objects\ChatContact()); + $this->setObject(new Objects\Chat\Contact()); $this->setResourceName('contacts'); parent::__construct($HttpClient); diff --git a/src/MessageBird/Resources/ChatMessage.php b/src/MessageBird/Resources/Chat/Message.php similarity index 58% rename from src/MessageBird/Resources/ChatMessage.php rename to src/MessageBird/Resources/Chat/Message.php index 64ca96c1..b482b9ca 100644 --- a/src/MessageBird/Resources/ChatMessage.php +++ b/src/MessageBird/Resources/Chat/Message.php @@ -1,16 +1,17 @@ setObject(new Objects\ChatMessage()); + $this->setObject(new Objects\Chat\Message()); $this->setResourceName('messages'); parent::__construct($HttpClient); diff --git a/src/MessageBird/Resources/ChatPlatform.php b/src/MessageBird/Resources/Chat/Platform.php similarity index 58% rename from src/MessageBird/Resources/ChatPlatform.php rename to src/MessageBird/Resources/Chat/Platform.php index 1ce857d3..e2e626b2 100644 --- a/src/MessageBird/Resources/ChatPlatform.php +++ b/src/MessageBird/Resources/Chat/Platform.php @@ -1,16 +1,17 @@ setObject(new Objects\ChatPlatform()); + $this->setObject(new Objects\Chat\Platform()); $this->setResourceName('platforms'); parent::__construct($HttpClient); diff --git a/tests/integration/BaseTest.php b/tests/integration/BaseTest.php index fbc1d5fb..b944a193 100644 --- a/tests/integration/BaseTest.php +++ b/tests/integration/BaseTest.php @@ -14,9 +14,10 @@ public function testClientConstructor() $this->assertInstanceOf('MessageBird\Resources\Messages', $MessageBird->messages); $this->assertInstanceOf('MessageBird\Resources\VoiceMessage', $MessageBird->voicemessages); $this->assertInstanceOf('MessageBird\Resources\Verify', $MessageBird->verify); - $this->assertInstanceOf('MessageBird\Resources\ChatMessage', $MessageBird->chatmessages); - $this->assertInstanceOf('MessageBird\Resources\ChatPlatform', $MessageBird->chatplatforms); - $this->assertInstanceOf('MessageBird\Resources\ChatChannel', $MessageBird->chatchannels); + $this->assertInstanceOf('MessageBird\Resources\Chat\Message', $MessageBird->chatmessages); + $this->assertInstanceOf('MessageBird\Resources\Chat\Platform', $MessageBird->chatplatforms); + $this->assertInstanceOf('MessageBird\Resources\Chat\Channel', $MessageBird->chatchannels); + $this->assertInstanceOf('MessageBird\Resources\Chat\Contact', $MessageBird->chatcontacts); } diff --git a/tests/integration/chat/ChatTest.php b/tests/integration/chat/ChatTest.php index 81830cd5..c8b90bcf 100644 --- a/tests/integration/chat/ChatTest.php +++ b/tests/integration/chat/ChatTest.php @@ -9,7 +9,7 @@ public function setUp() public function testCreateChatMessage() { - $ChatMessage = new \MessageBird\Objects\ChatMessage(); + $ChatMessage = new \MessageBird\Objects\Chat\Message(); $ChatMessage->contactId = '9d754dac577e3ff103cdf4n29856560'; $ChatMessage->payload = 'This is a test message to test the Chat API'; $ChatMessage->type = 'text'; @@ -40,7 +40,7 @@ public function testReadChatMessage() public function testCreateChatChannel() { - $ChatChannel = new \MessageBird\Objects\ChatChannel(); + $ChatChannel = new \MessageBird\Objects\Chat\Channel(); $ChatChannel->name = 'Test Channel Telegram'; $ChatChannel->platformId = 'e84f332c5649a5f911e569n69330697'; @@ -84,7 +84,7 @@ public function testDeleteChannel() public function testUpdateChatChannel() { - $ChatChannel = new \MessageBird\Objects\ChatChannel(); + $ChatChannel = new \MessageBird\Objects\Chat\Channel(); $ChatChannel->name = '9d2345ac577e4f103cd3d4529856560'; $ChatChannel->callbackUrl = 'http://testurl.dev'; From 8e684140c38aa63a11fc96bc6674f3cdfb21ec02 Mon Sep 17 00:00:00 2001 From: sotiris Date: Fri, 12 Aug 2016 09:23:52 +0200 Subject: [PATCH 12/14] Fixed examples --- examples/chatchannels-create.php | 2 +- examples/chatchannels-update.php | 2 +- examples/chatmessages-create.php | 2 +- examples/chatmessages-list.php | 2 +- examples/chatmessages-view.php | 2 +- examples/chatplatforms-list.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index ff5ba2eb..6d5bcacf 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\Channel(); +$ChatChannel = new \MessageBird\Objects\Chat\Channel(); //Example for telegram channel diff --git a/examples/chatchannels-update.php b/examples/chatchannels-update.php index 6f03c188..5f2c9d01 100644 --- a/examples/chatchannels-update.php +++ b/examples/chatchannels-update.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. -$ChatChannel = new \MessageBird\Objects\Channel(); +$ChatChannel = new \MessageBird\Objects\Chat\Channel(); $ChatChannel->name = 'New name'; $ChatChannel->callbackUrl = 'http://newurl.dev'; diff --git a/examples/chatmessages-create.php b/examples/chatmessages-create.php index e1954afc..7c9b97c3 100644 --- a/examples/chatmessages-create.php +++ b/examples/chatmessages-create.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatMessage = new \MessageBird\Objects\ChatMessage(); +$ChatMessage = new \MessageBird\Objects\Chat\Message(); $ChatMessage->contactId = '9d754dac577e3ff103cdf4n29856560'; $ChatMessage->payload = 'This is a test message to test the Chat API'; $ChatMessage->type = 'text'; diff --git a/examples/chatmessages-list.php b/examples/chatmessages-list.php index d9e902f0..28c4b723 100644 --- a/examples/chatmessages-list.php +++ b/examples/chatmessages-list.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatMessage = new \MessageBird\Objects\ChatMessage(); +$ChatMessage = new \MessageBird\Objects\Chat\Message(); try { diff --git a/examples/chatmessages-view.php b/examples/chatmessages-view.php index 6bf9500d..7c5c854d 100644 --- a/examples/chatmessages-view.php +++ b/examples/chatmessages-view.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatMessage = new \MessageBird\Objects\ChatMessage(); +$ChatMessage = new \MessageBird\Objects\Chat\Message(); try { diff --git a/examples/chatplatforms-list.php b/examples/chatplatforms-list.php index 5d2e46ec..f235f5bb 100644 --- a/examples/chatplatforms-list.php +++ b/examples/chatplatforms-list.php @@ -4,7 +4,7 @@ $MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. -$ChatPlatform = new \MessageBird\Objects\Channel(); +$ChatPlatform = new \MessageBird\Objects\Chat\Channel(); try { From cb5181230bc1e73962c12ae8e03e5d1c1570f7ce Mon Sep 17 00:00:00 2001 From: sotiris Date: Fri, 12 Aug 2016 11:26:01 +0200 Subject: [PATCH 13/14] Removed tab character from dummy access key --- examples/chatchannels-create.php | 2 +- examples/chatchannels-delete.php | 2 +- examples/chatchannels-list.php | 2 +- examples/chatchannels-view.php | 2 +- examples/chatcontacts-list.php | 2 +- examples/chatcontacts-view.php | 2 +- examples/chatmessages-create.php | 2 +- examples/chatmessages-list.php | 2 +- examples/chatmessages-view.php | 2 +- examples/chatplatforms-list.php | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index 6d5bcacf..9e84aac8 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. $ChatChannel = new \MessageBird\Objects\Chat\Channel(); diff --git a/examples/chatchannels-delete.php b/examples/chatchannels-delete.php index a4053c51..b26ee67e 100644 --- a/examples/chatchannels-delete.php +++ b/examples/chatchannels-delete.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { diff --git a/examples/chatchannels-list.php b/examples/chatchannels-list.php index 570499f1..766b462a 100644 --- a/examples/chatchannels-list.php +++ b/examples/chatchannels-list.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { $ChatChannelResult = $MessageBird->chatchannels->getList(); diff --git a/examples/chatchannels-view.php b/examples/chatchannels-view.php index e0a0cfa8..aefd99aa 100644 --- a/examples/chatchannels-view.php +++ b/examples/chatchannels-view.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { $ChatChannelResult = $MessageBird->chatchannels->read('0051af4c577e3eebbc3631n95680736'); // Set a channel id here diff --git a/examples/chatcontacts-list.php b/examples/chatcontacts-list.php index 31ad8c83..b44ee6fd 100644 --- a/examples/chatcontacts-list.php +++ b/examples/chatcontacts-list.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { diff --git a/examples/chatcontacts-view.php b/examples/chatcontacts-view.php index b0212c3c..4f62ac3d 100644 --- a/examples/chatcontacts-view.php +++ b/examples/chatcontacts-view.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { diff --git a/examples/chatmessages-create.php b/examples/chatmessages-create.php index 7c9b97c3..55b98061 100644 --- a/examples/chatmessages-create.php +++ b/examples/chatmessages-create.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. $ChatMessage = new \MessageBird\Objects\Chat\Message(); $ChatMessage->contactId = '9d754dac577e3ff103cdf4n29856560'; diff --git a/examples/chatmessages-list.php b/examples/chatmessages-list.php index 28c4b723..fd193b2f 100644 --- a/examples/chatmessages-list.php +++ b/examples/chatmessages-list.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. $ChatMessage = new \MessageBird\Objects\Chat\Message(); diff --git a/examples/chatmessages-view.php b/examples/chatmessages-view.php index 7c5c854d..2356d0c7 100644 --- a/examples/chatmessages-view.php +++ b/examples/chatmessages-view.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. $ChatMessage = new \MessageBird\Objects\Chat\Message(); diff --git a/examples/chatplatforms-list.php b/examples/chatplatforms-list.php index f235f5bb..828f5965 100644 --- a/examples/chatplatforms-list.php +++ b/examples/chatplatforms-list.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY '); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. $ChatPlatform = new \MessageBird\Objects\Chat\Channel(); From b599d14ff5c88f8374ae75007f83276adbba85d9 Mon Sep 17 00:00:00 2001 From: sotiris Date: Mon, 15 Aug 2016 12:09:49 +0200 Subject: [PATCH 14/14] Fixed contactId and typo. --- examples/chatchannels-create.php | 2 +- examples/chatcontacts-delete.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/chatchannels-create.php b/examples/chatchannels-create.php index 9e84aac8..9d825b92 100644 --- a/examples/chatchannels-create.php +++ b/examples/chatchannels-create.php @@ -9,7 +9,7 @@ //Example for telegram channel $ChatChannel->name = 'Test Channel Telegram'; -$ChatChannel->platform_id = 'e82d332c5649a5f911e569n69040697'; +$ChatChannel->platformId = 'e82d332c5649a5f911e569n69040697'; // Channel details is a hash with name-value pairs indicating which channel details (and their respective data types) // are required when creating a channel for this platform. diff --git a/examples/chatcontacts-delete.php b/examples/chatcontacts-delete.php index 9d7150be..acedb94c 100644 --- a/examples/chatcontacts-delete.php +++ b/examples/chatcontacts-delete.php @@ -6,7 +6,7 @@ try { - $deleted = $MessageBird->chatcontacts->delete('4affa2345d7fb22e373921n524df5409'); // Set a message id here + $deleted = $MessageBird->chatcontacts->delete('4affa2345d7fb22e373921n524df5409'); // Set a contact id var_dump('Deleted : ' . $deleted); } catch (\MessageBird\Exceptions\AuthenticateException $e) {