Skip to content

Commit 660cf90

Browse files
authored
Merge pull request #45 from sotoz/contacts-groups
Added support for Contacts and Groups
2 parents c96fa90 + 2c6b10c commit 660cf90

24 files changed

+1027
-1
lines changed

examples/contact-create.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Contact = new \MessageBird\Objects\Contact();
8+
$Contact->msisdn = "31123456780";
9+
$Contact->firstName = "FirstName";
10+
$Contact->lastName = "LastName";
11+
$Contact->custom1 = "test_custom1";
12+
$Contact->custom2 = "test_custom2";
13+
$Contact->custom3 = "test_custom3";
14+
$Contact->custom4 = "test_custom4";
15+
16+
17+
try {
18+
$ContactResult = $MessageBird->contacts->create($Contact);
19+
var_dump($ContactResult);
20+
21+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
22+
// That means that your accessKey is unknown
23+
echo 'Wrong login';
24+
25+
} catch (\Exception $e) {
26+
echo $e->getMessage();
27+
}

examples/contact-delete.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$deleted = $MessageBird->contacts->delete('123_contact_id'); // Set a contact id here
9+
var_dump('Deleted: ' . $deleted);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
18+
}

examples/contact-get-groups.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$ContactGroupsList = $MessageBird->contacts->getGroups('contact_id');
9+
var_dump($ContactGroupsList);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}

examples/contact-get-messages.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$ContactMessageList = $MessageBird->contacts->getMessages('contact_id');
9+
var_dump($ContactMessageList);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}

examples/contact-list.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$ContactList = $MessageBird->contacts->getList(array ());
9+
var_dump($ContactList);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}

examples/contact-update.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Contact = new \MessageBird\Objects\Contact();
8+
$Contact->msisdn = '31123456789';
9+
$Contact->firstName = 'ChangedFirst';
10+
$Contact->lastName = "ChangedLast";
11+
$Contact->custom1 = "custom-1b";
12+
$Contact->custom2 = "custom-2b";
13+
$Contact->custom3 = "custom-3b";
14+
$Contact->custom4 = "custom-4b";
15+
16+
17+
try {
18+
$GroupResult = $MessageBird->contacts->update($Contact, 'contact_id');
19+
var_dump($GroupResult);
20+
21+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
22+
// That means that your accessKey is unknown
23+
echo 'Wrong login';
24+
25+
} catch (\Exception $e) {
26+
echo $e->getMessage();
27+
}

examples/contact-view.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$ContactResult = $MessageBird->contacts->read('123_contact_id'); // Set a contact id here
9+
var_dump($ContactResult);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$contacts['ids'] = array(
9+
'contact_id_1',
10+
'contact_id_2',
11+
);
12+
$group_id = 'group_id';
13+
$GroupAddContact = $MessageBird->groups->addContacts($contacts, $group_id);
14+
var_dump($GroupAddContact);
15+
16+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
17+
// That means that your accessKey is unknown
18+
echo 'Wrong login';
19+
20+
} catch (\Exception $e) {
21+
var_dump($e->getMessage());
22+
}

examples/group-create.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Group = new \MessageBird\Objects\Group();
8+
$Group->name = "group_name";
9+
10+
try {
11+
$GroupResult = $MessageBird->groups->create($Group);
12+
var_dump($GroupResult);
13+
14+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
15+
// That means that your accessKey is unknown
16+
echo 'Wrong login';
17+
18+
} catch (\Exception $e) {
19+
echo $e->getMessage();
20+
}

examples/group-delete.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$deleted = $MessageBird->groups->delete('group_id'); // Set a group id here
9+
var_dump('Deleted: ' . $deleted);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
18+
}

examples/group-get-contacts.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$GroupsContactList = $MessageBird->groups->getContacts('group_id');
9+
var_dump($GroupsContactList);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}

examples/group-list.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$GroupsList = $MessageBird->groups->getList(array ());
9+
var_dump($GroupsList);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$contact_id = 'contact_id';
9+
$group_id = 'group_id';
10+
$GroupAddContact = $MessageBird->groups->removeContact($contact_id, $group_id);
11+
var_dump($GroupAddContact);
12+
13+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
14+
// That means that your accessKey is unknown
15+
echo 'Wrong login';
16+
17+
} catch (\Exception $e) {
18+
var_dump($e->getMessage());
19+
}

examples/group-update.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$Group = new \MessageBird\Objects\Group();
8+
$Group->name = 'New group name';
9+
10+
try {
11+
$GroupResult = $MessageBird->groups->update($Group, 'group_id');
12+
var_dump($GroupResult);
13+
14+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
15+
// That means that your accessKey is unknown
16+
echo 'Wrong login';
17+
18+
} catch (\Exception $e) {
19+
echo $e->getMessage();
20+
}

examples/group-view.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
try {
8+
$GroupResult = $MessageBird->groups->read('group_id'); // Set a group id here
9+
var_dump($GroupResult);
10+
11+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
12+
// That means that your accessKey is unknown
13+
echo 'Wrong login';
14+
15+
} catch (\Exception $e) {
16+
var_dump($e->getMessage());
17+
}

src/MessageBird/Client.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Client
1212
const ENDPOINT = 'https://rest.messagebird.com';
1313
const CHATAPI_ENDPOINT = 'https://chat.messagebird.com/1';
1414

15-
const CLIENT_VERSION = '1.6.6';
15+
const CLIENT_VERSION = '1.7.0';
1616

1717
/**
1818
* @var string
@@ -24,6 +24,16 @@ class Client
2424
*/
2525
public $messages;
2626

27+
/**
28+
* @var Resources\Contacts
29+
*/
30+
public $contacts;
31+
32+
/**
33+
* @var Resources\Groups
34+
*/
35+
public $groups;
36+
2737
/**
2838
* @var Resources\VoiceMessage
2939
*/
@@ -115,6 +125,8 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
115125
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
116126
$this->lookup = new Resources\Lookup($this->HttpClient);
117127
$this->lookupHlr = new Resources\LookupHlr($this->HttpClient);
128+
$this->contacts = new Resources\Contacts($this->HttpClient);
129+
$this->groups = new Resources\Groups($this->HttpClient);
118130
$this->chatMessages = new Resources\Chat\Message($this->ChatAPIHttpClient);
119131
$this->chatChannels = new Resources\Chat\Channel($this->ChatAPIHttpClient);
120132
$this->chatPlatforms = new Resources\Chat\Platform($this->ChatAPIHttpClient);

src/MessageBird/Common/HttpClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class HttpClient
1616
const REQUEST_POST = 'POST';
1717
const REQUEST_DELETE = 'DELETE';
1818
const REQUEST_PUT = 'PUT';
19+
const REQUEST_PATCH = "PATCH";
1920

2021
const HTTP_NO_CONTENT = 204;
2122

@@ -153,6 +154,9 @@ public function performHttpRequest($method, $resourceName, $query = null, $body
153154
} elseif ($method === self::REQUEST_PUT){
154155
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PUT);
155156
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
157+
} elseif ($method === self::REQUEST_PATCH){
158+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_PATCH);
159+
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
156160
}
157161

158162
// Some servers have outdated or incorrect certificates, Use the included CA-bundle

0 commit comments

Comments
 (0)