Skip to content
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

Added support for Contacts and Groups #45

Merged
merged 19 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: php
dist: precise
php:
- 5.3
- 5.4
Expand All @@ -13,6 +14,7 @@ matrix:
allow_failures:
- php: 7.0
- php: 7.1
- php: hhvm
- php: hhvm-nightly

script: phpunit --verbose
27 changes: 27 additions & 0 deletions examples/contact-create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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

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

$Contact = new \MessageBird\Objects\Contact();
$Contact->msisdn = "31123456780";
$Contact->firstName = "FirstName";
$Contact->lastName = "LastName";
$Contact->custom1 = "test_custom1";
$Contact->custom2 = "test_custom2";
$Contact->custom3 = "test_custom3";
$Contact->custom4 = "test_custom4";


try {
$ContactResult = $MessageBird->contacts->create($Contact);
var_dump($ContactResult);

} 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 examples/contact-delete.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('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$deleted = $MessageBird->contacts->delete('123_contact_id'); // Set a contact id here
var_dump('Deleted: ' . $deleted);

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

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

}
17 changes: 17 additions & 0 deletions examples/contact-get-groups.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 {
$ContactGroupsList = $MessageBird->contacts->getGroups('contact_id');
var_dump($ContactGroupsList);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
17 changes: 17 additions & 0 deletions examples/contact-get-messages.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 {
$ContactMessageList = $MessageBird->contacts->getMessages('contact_id');
var_dump($ContactMessageList);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
17 changes: 17 additions & 0 deletions examples/contact-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 {
$ContactList = $MessageBird->contacts->getList(array ());
var_dump($ContactList);

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

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

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

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

$Contact = new \MessageBird\Objects\Contact();
$Contact->msisdn = '31123456789';
$Contact->firstName = 'ChangedFirst';
$Contact->lastName = "ChangedLast";
$Contact->custom1 = "custom-1b";
$Contact->custom2 = "custom-2b";
$Contact->custom3 = "custom-3b";
$Contact->custom4 = "custom-4b";


try {
$GroupResult = $MessageBird->contacts->update($Contact, 'contact_id');
var_dump($GroupResult);

} 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/contact-view.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 {
$ContactResult = $MessageBird->contacts->read('123_contact_id'); // Set a contact id here
var_dump($ContactResult);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
22 changes: 22 additions & 0 deletions examples/group-add-contact-to-group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

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

try {
$contacts['ids'] = array(
'contact_id_1',
'contact_id_2',
);
$group_id = 'group_id';
$GroupAddContact = $MessageBird->groups->addContacts($contacts, $group_id);
var_dump($GroupAddContact);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
20 changes: 20 additions & 0 deletions examples/group-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('YOUR_ACCESS_KEY'); // Set your own API access key here.

$Group = new \MessageBird\Objects\Group();
$Group->name = "group_name";

try {
$GroupResult = $MessageBird->groups->create($Group);
var_dump($GroupResult);

} 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 examples/group-delete.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('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$deleted = $MessageBird->groups->delete('group_id'); // Set a group id here
var_dump('Deleted: ' . $deleted);

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

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

}
17 changes: 17 additions & 0 deletions examples/group-get-contacts.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 {
$GroupsContactList = $MessageBird->groups->getContacts('group_id');
var_dump($GroupsContactList);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
17 changes: 17 additions & 0 deletions examples/group-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 {
$GroupsList = $MessageBird->groups->getList(array ());
var_dump($GroupsList);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
19 changes: 19 additions & 0 deletions examples/group-remove-contact-from-group.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('YOUR_ACCESS_KEY'); // Set your own API access key here.

try {
$contact_id = 'contact_id';
$group_id = 'group_id';
$GroupAddContact = $MessageBird->groups->removeContact($contact_id, $group_id);
var_dump($GroupAddContact);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
20 changes: 20 additions & 0 deletions examples/group-update.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('YOUR_ACCESS_KEY'); // Set your own API access key here.

$Group = new \MessageBird\Objects\Group();
$Group->name = 'New group name';

try {
$GroupResult = $MessageBird->groups->update($Group, 'group_id');
var_dump($GroupResult);

} 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/group-view.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 {
$GroupResult = $MessageBird->groups->read('group_id'); // Set a group id here
var_dump($GroupResult);

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

} catch (\Exception $e) {
var_dump($e->getMessage());
}
14 changes: 13 additions & 1 deletion src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Client
const ENDPOINT = 'https://rest.messagebird.com';
const CHATAPI_ENDPOINT = 'https://chat.messagebird.com/1';

const CLIENT_VERSION = '1.6.6';
const CLIENT_VERSION = '1.7.0';

/**
* @var string
Expand All @@ -24,6 +24,16 @@ class Client
*/
public $messages;

/**
* @var Resources\Contacts
*/
public $contacts;

/**
* @var Resources\Groups
*/
public $groups;

/**
* @var Resources\VoiceMessage
*/
Expand Down Expand Up @@ -115,6 +125,8 @@ 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->contacts = new Resources\Contacts($this->HttpClient);
$this->groups = new Resources\Groups($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);
Expand Down
4 changes: 4 additions & 0 deletions src/MessageBird/Common/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class HttpClient
const REQUEST_POST = 'POST';
const REQUEST_DELETE = 'DELETE';
const REQUEST_PUT = 'PUT';
const REQUEST_PATCH = "PATCH";

const HTTP_NO_CONTENT = 204;

Expand Down Expand Up @@ -153,6 +154,9 @@ public function performHttpRequest($method, $resourceName, $query = null, $body
} elseif ($method === self::REQUEST_PUT){
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PUT);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
} elseif ($method === self::REQUEST_PATCH){
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PATCH);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
}

// Some servers have outdated or incorrect certificates, Use the included CA-bundle
Expand Down
Loading