Skip to content

Add client implementation for Numbers API, support 7.0 #111

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 9 commits into from
Jan 14, 2020
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendor/
composer.lock
composer*.lock
composer.phar
.DS_Store
.idea/
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
language: php
dist: xenial
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

before_script:
- if [[ ${TRAVIS_PHP_VERSION} == 7.0 ]]; then export COMPOSER=composer-7-0.json; fi
- composer install

script: phpunit --verbose
script: php ./vendor/bin/phpunit --verbose
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Requirements

- [Sign up](https://www.messagebird.com/en/signup) for a free MessageBird account
- Create a new access_key in the developers sections
- MessageBird API client for PHP requires PHP >= 5.4.
- MessageBird API client for PHP requires PHP >= 7.0.

Installation
-----
Expand Down
25 changes: 25 additions & 0 deletions composer-7-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "messagebird/php-rest-api",
"description": "MessageBird REST API client for PHP",
"type": "library",
"homepage": "https://github.com/messagebird/php-rest-api",
"license": "BSD-2-Clause",
"authors": [
{
"name": "MessageBird",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.0",
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "^6"
},
"autoload": {
"psr-4": {
"MessageBird\\": "src/MessageBird/"
}
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
}
],
"require": {
"php": ">=7.2.0",
"php": ">=7.0",
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "^8"
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 20 additions & 0 deletions examples/available-phone-numbers-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

$MessageBird = new \MessageBird\Client(getenv('MESSAGEBIRD_API_KEY'));

try {
$phoneNumbers = $MessageBird->availablePhoneNumbers->getList("nl", array());
var_dump($phoneNumbers);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
var_dump($e->getMessage());
// That means that your accessKey is unknown
print("wrong login\n");

} catch (\Exception $e) {
var_dump($e->getMessage());

}
?>
20 changes: 20 additions & 0 deletions examples/phone-numbers-create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

$MessageBird = new \MessageBird\Client(getenv('MESSAGEBIRD_API_KEY')); // Set your own API access key here.
$NumberPurchaseRequest = new \MessageBird\Objects\NumberPurchaseRequest();
$NumberPurchaseRequest->number = '31612345678';
$NumberPurchaseRequest->countryCode = 'NL';
$NumberPurchaseRequest->billingIntervalMonths = 1;

try {
$NumberPurchaseRequestResult = $MessageBird->phoneNumbers->create($NumberPurchaseRequest);
var_dump($NumberPurchaseRequestResult);
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
print("wrong login\n");

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

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

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

try {
$deleted = $MessageBird->phoneNumbers->delete('31612345678');
var_dump('Deleted: ' . $deleted);
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
print("wrong login\n");

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

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

$MessageBird = new \MessageBird\Client(getenv('MESSAGEBIRD_API_KEY')); // Set your own API access key here.
$Number = new \MessageBird\Objects\Number();
$Number->tags = array('tag1');

try {
$NumberResult = $MessageBird->phoneNumbers->update($Number, '31612345678');
var_dump($NumberResult);
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
print("wrong login\n");

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

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

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

try {
$phoneNumbers = $MessageBird->phoneNumbers->getList();
var_dump($phoneNumbers);

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

} catch (\Exception $e) {
var_dump($e->getMessage());

}
?>
68 changes: 46 additions & 22 deletions src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Client
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 NUMBERSAPI_ENDPOINT = 'https://numbers.messagebird.com/v1';

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

/**
* @var Resources\AvailableNumbers
*/
public $availableNumbers;

/**
* @var Resources\LookupHlr
*/
Expand Down Expand Up @@ -120,6 +126,16 @@ class Client
*/
public $voiceTranscriptions;

/**
* @var Resources\PhoneNumbers
*/
public $phoneNumbers;

/**
* @var Resources\AvailablePhoneNumbers
*/
public $availablePhoneNumbers;

/**
* @var Resources\Voice\Webhooks
*/
Expand Down Expand Up @@ -184,12 +200,14 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
'X-MessageBird-Version' => '20170314',
));
$this->partnerAccountClient = new Common\HttpClient(self::PARTNER_ACCOUNT_ENDPOINT);
$this->numbersAPIClient = new Common\HttpClient(self::NUMBERSAPI_ENDPOINT);
} else {
$this->ChatAPIHttpClient = $httpClient;
$this->ConversationsAPIHttpClient = $httpClient;
$this->HttpClient = $httpClient;
$this->VoiceAPIHttpClient = $httpClient;
$this->partnerAccountClient = $httpClient;
$this->numbersAPIClient = $httpClient;
}

$this->HttpClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION);
Expand All @@ -207,34 +225,39 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
$this->partnerAccountClient->addUserAgentString('MessageBird/ApiClient/' . self::CLIENT_VERSION);
$this->partnerAccountClient->addUserAgentString($this->getPhpVersion());

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

if ($accessKey !== null) {
$this->setAccessKey($accessKey);
}

$this->messages = new Resources\Messages($this->HttpClient);
$this->hlr = new Resources\Hlr($this->HttpClient);
$this->verify = new Resources\Verify($this->HttpClient);
$this->balance = new Resources\Balance($this->HttpClient);
$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\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);
$this->voiceCallFlows = new Resources\Voice\CallFlows($this->VoiceAPIHttpClient);
$this->voiceCalls = new Resources\Voice\Calls($this->VoiceAPIHttpClient);
$this->voiceLegs = new Resources\Voice\Legs($this->VoiceAPIHttpClient);
$this->voiceRecordings = new Resources\Voice\Recordings($this->VoiceAPIHttpClient);
$this->voiceTranscriptions = new Resources\Voice\Transcriptions($this->VoiceAPIHttpClient);
$this->voiceWebhooks = new Resources\Voice\Webhooks($this->VoiceAPIHttpClient);
$this->mmsMessages = new Resources\MmsMessages($this->HttpClient);
$this->contacts = new Resources\Contacts($this->HttpClient);
$this->groups = new Resources\Groups($this->HttpClient);
$this->conversations = new Resources\Conversation\Conversations($this->ConversationsAPIHttpClient);
$this->messages = new Resources\Messages($this->HttpClient);
$this->hlr = new Resources\Hlr($this->HttpClient);
$this->verify = new Resources\Verify($this->HttpClient);
$this->balance = new Resources\Balance($this->HttpClient);
$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\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);
$this->voiceCallFlows = new Resources\Voice\CallFlows($this->VoiceAPIHttpClient);
$this->voiceCalls = new Resources\Voice\Calls($this->VoiceAPIHttpClient);
$this->voiceLegs = new Resources\Voice\Legs($this->VoiceAPIHttpClient);
$this->voiceRecordings = new Resources\Voice\Recordings($this->VoiceAPIHttpClient);
$this->voiceTranscriptions = new Resources\Voice\Transcriptions($this->VoiceAPIHttpClient);
$this->voiceWebhooks = new Resources\Voice\Webhooks($this->VoiceAPIHttpClient);
$this->mmsMessages = new Resources\MmsMessages($this->HttpClient);
$this->contacts = new Resources\Contacts($this->HttpClient);
$this->groups = new Resources\Groups($this->HttpClient);
$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);
$this->partnerAccounts = new Resources\PartnerAccount\Accounts($this->partnerAccountClient);
$this->phoneNumbers = new Resources\PhoneNumbers($this->numbersAPIClient);
$this->availablePhoneNumbers = new Resources\AvailablePhoneNumbers($this->numbersAPIClient);
}

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

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


namespace MessageBird\Objects;

/**
* Class Number
*
* Represents a specific phone number
*
* @package MessageBird\Objects
*/
class Number extends Base
{
/**
* The phone number in E.164 format without the prefixed plus-sign.
* @var string
*/
public $number;

/**
* The Number's country
* @var string
*/
public $country;

/**
* The country code for this number in ISO 3166-1 alpha-2 format.
* @var string
*/
public $region;

/**
* Finer-grained locality for this Number
* @var string
*/
public $locality;

/**
* The available features for this Number
* @var array
*/
public $features;

/**
* Additional user-provided tags for this Number
* @var array
*/
public $tags = [];

/**
* Number type (example: landline, mobile).
* @var string
*/
public $type;

/**
* Number availability and current activated status
* @var string
*/
public $status;
}
32 changes: 32 additions & 0 deletions src/MessageBird/Objects/NumberPurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


namespace MessageBird\Objects;

/**
* Class NumberPurchaseRequest
*
* Represents a specific phone number
*
* @package MessageBird\Objects
*/
class NumberPurchaseRequest extends Base
{
/**
* The phone number in E.164 format without the prefixed plus-sign.
* @var string
*/
public $number;

/**
* The country code for this number in ISO 3166-1 alpha-2 format.
*
* @var string
*/
public $countryCode;

/**
* The interval in months that this number will be billed by
*/
public $billingIntervalMonths;
}
Loading