Skip to content

Sync #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2019
Merged
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
21 changes: 21 additions & 0 deletions examples/partner-account-create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

$account = new \MessageBird\Objects\PartnerAccount\Account();
$account->name = 'Name Test';
$account->email = '[email protected]';

try {
$partnerAccountResult = $messageBird->partnerAccounts->create($account);
var_dump($partnerAccountResult);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';

} catch (\Exception $e) {
echo $e->getMessage();
}
17 changes: 17 additions & 0 deletions examples/partner-account-delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$partnerAccountResult = $messageBird->partnerAccounts->delete(1);
var_dump($partnerAccountResult);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';

} catch (\Exception $e) {
echo $e->getMessage();
}
17 changes: 17 additions & 0 deletions examples/partner-account-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$partnerAccountResult = $messageBird->partnerAccounts->getList();
var_dump($partnerAccountResult);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';

} catch (\Exception $e) {
echo $e->getMessage();
}
17 changes: 17 additions & 0 deletions examples/partner-account-read.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$partnerAccountResult = $messageBird->partnerAccounts->read(1);
var_dump($partnerAccountResult);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';

} catch (\Exception $e) {
echo $e->getMessage();
}
18 changes: 18 additions & 0 deletions src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Client
const CHATAPI_ENDPOINT = 'https://chat.messagebird.com/1';
const CONVERSATIONSAPI_ENDPOINT = 'https://conversations.messagebird.com/v1';
const VOICEAPI_ENDPOINT = 'https://voice.messagebird.com';
const PARTNER_ACCOUNT_ENDPOINT = 'https://partner-accounts.messagebird.com';

const ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX = 'ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX';
const CONVERSATIONSAPI_WHATSAPP_SANDBOX_ENDPOINT = 'https://whatsapp-sandbox.messagebird.com/v1';
Expand Down Expand Up @@ -139,6 +140,11 @@ class Client
*/
public $conversationWebhooks;

/**
* @var Resources\PartnerAccount\Accounts;
*/
public $partnerAccounts;

/**
* @var Common\HttpClient
*/
Expand All @@ -159,6 +165,11 @@ class Client
*/
protected $VoiceAPIHttpClient;

/**
* @var Common\HttpClient
*/
protected $partnerAccountClient;

/**
* @param string $accessKey
* @param Common\HttpClient $httpClient
Expand All @@ -172,11 +183,13 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
$this->VoiceAPIHttpClient = new Common\HttpClient(self::VOICEAPI_ENDPOINT, 10, 2, array(
'X-MessageBird-Version' => '20170314',
));
$this->partnerAccountClient = new Common\HttpClient(self::PARTNER_ACCOUNT_ENDPOINT);
} else {
$this->ChatAPIHttpClient = $httpClient;
$this->ConversationsAPIHttpClient = $httpClient;
$this->HttpClient = $httpClient;
$this->VoiceAPIHttpClient = $httpClient;
$this->partnerAccountClient = $httpClient;
}

$this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION);
Expand All @@ -191,6 +204,9 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
$this->VoiceAPIHttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION);
$this->VoiceAPIHttpClient->addUserAgentString($this->getPhpVersion());

$this->partnerAccountClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION);
$this->partnerAccountClient->addUserAgentString($this->getPhpVersion());

if ($accessKey !== null) {
$this->setAccessKey($accessKey);
}
Expand Down Expand Up @@ -218,6 +234,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
$this->conversations = new Resources\Conversation\Conversations($this->ConversationsAPIHttpClient);
$this->conversationMessages = new Resources\Conversation\Messages($this->ConversationsAPIHttpClient);
$this->conversationWebhooks = new Resources\Conversation\Webhooks($this->ConversationsAPIHttpClient);
$this->partnerAccounts = new Resources\PartnerAccount\Accounts($this->partnerAccountClient);
}

/**
Expand All @@ -231,6 +248,7 @@ public function setAccessKey ($accessKey)
$this->ConversationsAPIHttpClient->setAuthentication($Authentication);
$this->HttpClient->setAuthentication($Authentication);
$this->VoiceAPIHttpClient->setAuthentication($Authentication);
$this->partnerAccountClient->setAuthentication($Authentication);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/MessageBird/Objects/PartnerAccount/AccessKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace MessageBird\Objects\PartnerAccount;

use MessageBird\Objects\Base;

class AccessKey extends Base
{
public $id;

public $key;

public $mode;
}
47 changes: 47 additions & 0 deletions src/MessageBird/Objects/PartnerAccount/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace MessageBird\Objects\PartnerAccount;

use MessageBird\Objects\Base;

class Account extends Base
{
public $id;

public $name;

public $email;

public $accessKeys = [];

public $signingKey;

public function loadToJson()
{
return json_encode([
'name' => $this->name,
'email' => $this->email,
]);
}

/**
* @param $object
*
* @return $this|void
*/
public function loadFromArray($object)
{
parent::loadFromArray($object);

if (empty($this->accessKeys)) {
return $this;
}

foreach($this->accessKeys as &$item) {
$accessKey = new AccessKey();
$item = $accessKey->loadFromArray($item);
}

return $this;
}
}
58 changes: 58 additions & 0 deletions src/MessageBird/Resources/PartnerAccount/Accounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace MessageBird\Resources\PartnerAccount;

use MessageBird\Common\HttpClient;
use MessageBird\Objects\PartnerAccount\Account;
use MessageBird\Resources\Base;

class Accounts extends Base
{
const RESOURCE_NAME = 'child-accounts';

public function __construct(HttpClient $httpClient)
{
parent::__construct($httpClient);

$this->setObject(new Account());
$this->setResourceName(self::RESOURCE_NAME);
}

public function create($object, $query = null)
{

list($status, , $body) = $this->HttpClient->performHttpRequest(
HttpClient::REQUEST_POST,
self::RESOURCE_NAME,
null,
$object->loadToJson()
);

var_dump($status);
var_dump($body);

return $this->processRequest($body);
}

public function getList($parameters = [])
{
list($status, , $body) = $this->HttpClient->performHttpRequest(
HttpClient::REQUEST_GET,
self::RESOURCE_NAME,
$parameters
);

if ($status !== 200) {
return $this->processRequest($body);
}


$response = json_decode($body, true);

foreach ($response as &$item) {
$item = $this->getObject()->loadFromArray($item);
}

return $response;
}
}
Loading