Skip to content

Commit 9e9cc56

Browse files
committed
Merge pull request #14 from messagebird/lookup
Adding the new Lookup API endpoints
2 parents 04d7c02 + 77c9712 commit 9e9cc56

File tree

11 files changed

+457
-6
lines changed

11 files changed

+457
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Installation
1919
####Composer installation
2020

2121
- [Download composer](https://getcomposer.org/doc/00-intro.md#installation-nix)
22-
- Add the `"messagebird/php-rest-api": "1.2.x"` into the `require` section of your `composer.json`.
22+
- Add the `"messagebird/php-rest-api": "1.3.x"` into the `require` section of your `composer.json`.
2323
- Run `composer install`.
2424

2525
```
2626
{
2727
"require": {
28-
"messagebird/php-rest-api": "1.2.x"
28+
"messagebird/php-rest-api": "1.3.x"
2929
}
3030
}
3131
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "messagebird/php-rest-api",
33
"description": "MessageBird REST API client for PHP",
4-
"version": "1.2.0",
4+
"version": "1.3.0",
55
"type": "library",
66
"homepage": "https://github.com/messagebird/php-rest-api",
77
"license": "BSD-2-Clause",

examples/lookup-hlr-view.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
$Hlr = new \MessageBird\Objects\Hlr();
9+
$Hlr->msisdn = '31624971134';
10+
$Hlr->reference = "yoloswag3001";
11+
12+
// create a new hlr request
13+
$hlr = $MessageBird->lookupHlr->create($Hlr);
14+
var_dump($hlr);
15+
16+
// pool for the results
17+
$poolCount = 10;
18+
while($poolCount--) {
19+
$hlr = $MessageBird->lookupHlr->read($Hlr->msisdn);
20+
if ($hlr->status != \MessageBird\Objects\Hlr::STATUS_SENT) {
21+
// we have something
22+
var_dump($hlr);
23+
break;
24+
}
25+
sleep(0.5);
26+
}
27+
28+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
29+
// That means that your accessKey is unknown
30+
echo 'wrong login';
31+
32+
} catch (\Exception $e) {
33+
var_dump($e->getMessage());
34+
35+
}

examples/lookup-view.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+
try {
8+
$Lookup = $MessageBird->lookup->read(31624971134);
9+
var_dump($Lookup);
10+
11+
$Lookup = $MessageBird->lookup->read("624971134", "NL");
12+
var_dump($Lookup);
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+
20+
}

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

1313
const ENDPOINT = 'https://rest.messagebird.com';
1414

15-
const CLIENT_VERSION = '1.2.0';
15+
const CLIENT_VERSION = '1.3.0';
1616

1717
/**
1818
* @var string
@@ -44,6 +44,16 @@ class Client
4444
*/
4545
public $balance;
4646

47+
/**
48+
* @var Resources\Lookup
49+
*/
50+
public $lookup;
51+
52+
/**
53+
* @var Resources\LookupHlr
54+
*/
55+
public $lookupHlr;
56+
4757
/**
4858
* @var Common\HttpClient
4959
*/
@@ -72,6 +82,8 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n
7282
$this->verify = new Resources\Verify($this->HttpClient);
7383
$this->balance = new Resources\Balance($this->HttpClient);
7484
$this->voicemessages = new Resources\VoiceMessage($this->HttpClient);
85+
$this->lookup = new Resources\Lookup($this->HttpClient);
86+
$this->lookupHlr = new Resources\LookupHlr($this->HttpClient);
7587
}
7688

7789
/**

src/MessageBird/Objects/Lookup.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
3+
namespace MessageBird\Objects;
4+
5+
/**
6+
* Class Lookup
7+
*
8+
* @package MessageBird\Objects
9+
*/
10+
class Lookup extends Base
11+
{
12+
const TYPE_FIXED_LINE = "fixed line";
13+
const TYPE_MOBILE = "mobile";
14+
const TYPE_FIXED_LINE_OR_MOBILE = "fixed line or mobile";
15+
const TYPE_TOLL_FREE = "toll free";
16+
const TYPE_PREMIUM_RATE = "premium rate";
17+
const TYPE_SHARED_COST = "shared cost";
18+
const TYPE_VOIP = "voip";
19+
const TYPE_PERSONAL_NUMBER = "personal number";
20+
const TYPE_PAGER = "pager";
21+
const TYPE_UNIVERSAL_ACCESS_NUMBER = "universal access number";
22+
const TYPE_VOICE_MAIL = "voice mail";
23+
const TYPE_UNKNOWN = "unknown";
24+
25+
/**
26+
* The URL of the created object.
27+
*
28+
* @var string
29+
*/
30+
protected $href;
31+
/**
32+
* The country code for this number in ISO 3166-1 alpha-2 format.
33+
*
34+
* @var string
35+
*/
36+
protected $countryCode;
37+
38+
/**
39+
* The country calling code for this number.
40+
*
41+
* @var integer
42+
*/
43+
protected $countryPrefix;
44+
45+
/**
46+
* The phone number in E.164 format without the prefixed plus-sign.
47+
*
48+
* @var integer
49+
*/
50+
protected $phoneNumber;
51+
52+
/**
53+
* The type of number. This can be fixed line, mobile, fixed line or mobile, toll free, premium rate, shared cost, voip, personal number, pager, universal access number, voice mail or unknown*
54+
* @var string
55+
*/
56+
protected $type;
57+
58+
/**
59+
* An associative array containing references to this phone number in several different formats.
60+
*
61+
* @var array
62+
*
63+
* e164: The phone number in E.164 format.
64+
* international: The phone number in international format.
65+
* national: The phone number in national/local format.
66+
* rfc3966: The phone number in RFC3966 format.
67+
*/
68+
protected $formats;
69+
70+
/**
71+
* The most recent HLR object. If no such HLR objects exists, this array won't be returned.
72+
*
73+
* @var array
74+
*
75+
* id(string): An unique random ID which is created on the MessageBird platform.
76+
* network(int): The MCCMNC code of the network provider.
77+
* reference(string): A client reference.
78+
* status(string): The status of the HLR request. Possible values: sent, absent, active, unknown, and failed.
79+
* createdDatetime(datetime): The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP).
80+
* statusDatetime(datetime): The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP).
81+
*/
82+
protected $hlr;
83+
84+
/**
85+
* Get the href
86+
*
87+
* @return mixed
88+
*/
89+
public function getHref()
90+
{
91+
return $this->href;
92+
}
93+
94+
/**
95+
* Get the href
96+
*
97+
* @return mixed
98+
*/
99+
public function getCountryCode()
100+
{
101+
return $this->countryCode;
102+
}
103+
104+
/**
105+
* Get the href
106+
*
107+
* @return mixed
108+
*/
109+
public function getCountryPrefix()
110+
{
111+
return $this->countryPrefix;
112+
}
113+
114+
/**
115+
* Get the href
116+
*
117+
* @return mixed
118+
*/
119+
public function getPhoneNumber()
120+
{
121+
return $this->phoneNumber;
122+
}
123+
124+
/**
125+
* Get the href
126+
*
127+
* @return mixed
128+
*/
129+
public function getType()
130+
{
131+
return $this->type;
132+
}
133+
134+
/**
135+
* Get the href
136+
*
137+
* @return mixed
138+
*/
139+
public function getFormats()
140+
{
141+
return $this->formats;
142+
}
143+
144+
/**
145+
* Get the href
146+
*
147+
* @return mixed
148+
*/
149+
public function getHLR()
150+
{
151+
return $this->hlr;
152+
}
153+
}

src/MessageBird/Objects/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Message extends Base
8989
public $gateway;
9090

9191
/**
92-
* A hash with extra information. Is only used when a binary or premium
92+
* An associative array with extra information. Is only used when a binary or premium
9393
* message is sent.
9494
*
9595
* @var array

src/MessageBird/Objects/Verify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Verify extends Base
4646
public $reference;
4747

4848
/**
49-
* A hash containing one href entry referring to the URL of the created object.
49+
* An associative array containing one href entry referring to the URL of the created object.
5050
* The entry can either refer to either the messages or the voicemessages endpoint
5151
*
5252
* @var object

src/MessageBird/Resources/Lookup.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace MessageBird\Resources;
4+
5+
use MessageBird\Objects;
6+
use MessageBird\Common;
7+
use InvalidArgumentException;
8+
9+
/**
10+
* Class Verify
11+
*
12+
* @package MessageBird\Resources
13+
*/
14+
class Lookup extends Base
15+
{
16+
17+
/**
18+
* @param Common\HttpClient $HttpClient
19+
*/
20+
public function __construct(Common\HttpClient $HttpClient)
21+
{
22+
$this->setObject(new Objects\Lookup);
23+
$this->setResourceName('lookup');
24+
25+
parent::__construct($HttpClient);
26+
}
27+
28+
/**
29+
* @param $phoneNumber
30+
*
31+
* @return $this->Object
32+
*
33+
* @throws \MessageBird\Exceptions\HttpException
34+
* @throws \MessageBird\Exceptions\RequestException
35+
* @throws \MessageBird\Exceptions\ServerException
36+
*/
37+
public function read($phoneNumber = null, $countryCode = null)
38+
{
39+
if(empty($phoneNumber)) {
40+
throw new InvalidArgumentException('The phone number cannot be empty.');
41+
}
42+
$query = null;
43+
if ($countryCode != null) {
44+
$query = array("countryCode" => $countryCode);
45+
}
46+
$ResourceName = $this->resourceName . '/' . $phoneNumber;
47+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query);
48+
return $this->processRequest($body);
49+
}
50+
}

0 commit comments

Comments
 (0)