Skip to content

Commit d2ffdd9

Browse files
author
Marcel Corso
committed
add lookup endpoints
1 parent 04d7c02 commit d2ffdd9

File tree

7 files changed

+409
-0
lines changed

7 files changed

+409
-0
lines changed

examples/lookup-hlr-view.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$MessageBird = new \MessageBird\Client('live_q2rh0rCJPmmpbNrJLE8xUtdJv'); // 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+
// curl -X POST https://rest.messagebird.com/lookup/31624971134/hlr -H 'Authorization: AccessKey ve_q2rh0rCJPmmpbNrJLE8xUtdJv' -d "msisdn=31624971134" -d "reference=NOIII"
14+
// curl -H "Accept: application/json" -H "Content-type: application/json" -H 'Authorization: AccessKey ve_q2rh0rCJPmmpbNrJLE8xUtdJv' -X POST -d '{"msisdn":"31624971134","network":null,"reference":"yoloswag3001","status":null}' https://rest.messagebird.com/lookup/31624971134/hlr
15+
16+
var_dump(json_encode($Hlr));
17+
18+
$hlr = $MessageBird->lookupHLR->create($Hlr);
19+
20+
// pool for the results
21+
$poolCount = 10;
22+
while($poolCount--) {
23+
$hlr = $MessageBird->lookupHLR->read($Hlr->msisdn);
24+
if ($hlr->status != 'sent') {
25+
var_dump($hlr);
26+
break;
27+
}
28+
sleep(0.5);
29+
}
30+
31+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
32+
// That means that your accessKey is unknown
33+
echo 'wrong login';
34+
35+
} catch (\Exception $e) {
36+
var_dump($e->getMessage());
37+
38+
}

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('live_q2rh0rCJPmmpbNrJLE8xUtdJv'); // Set your own API access key here.
6+
7+
try {
8+
9+
$phoneNumber = 31624971134;
10+
$Lookup = $MessageBird->lookup->read($phoneNumber);
11+
var_dump($Lookup);
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+
20+
}

src/MessageBird/Client.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
const HRL_STATUS_SENT = "sent";
26+
const HRL_STATUS_ABSENT = "absent";
27+
const HRL_STATUS_ACTIVE = "active";
28+
const HRL_STATUS_UNKNOWN = "unknown";
29+
const HRL_STATUS_FALIED = "failed";
30+
31+
/**
32+
* The URL of the created object.
33+
*
34+
* @var string
35+
*/
36+
protected $href;
37+
/**
38+
* The country code for this number in ISO 3166-1 alpha-2 format.
39+
*
40+
* @var string
41+
*/
42+
protected $countryCode;
43+
44+
/**
45+
* The country calling code for this number.
46+
*
47+
* @var integer
48+
*/
49+
protected $countryPrefix;
50+
51+
/**
52+
* The phone number in E.164 format without the prefixed plus-sign.
53+
*
54+
* @var integer
55+
*/
56+
protected $phoneNumber;
57+
58+
/**
59+
* 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*
60+
* @var string
61+
*/
62+
protected $type;
63+
64+
/**
65+
* A hash containing references to this phone number in several different formats.
66+
*
67+
* @var hash
68+
*
69+
* e164: The phone number in E.164 format.
70+
* international: The phone number in international format.
71+
* national: The phone number in national/local format.
72+
* rfc3966: The phone number in RFC3966 format.
73+
*/
74+
protected $formats;
75+
76+
/**
77+
* The most recent HLR object. If no such HLR objects exists, this hash won't be returned.
78+
*
79+
* @var hash
80+
*
81+
* id(string): An unique random ID which is created on the MessageBird platform.
82+
* network(int): The MCCMNC code of the network provider.
83+
* reference(string): A client reference.
84+
* status(string): The status of the HLR request. Possible values: sent, absent, active, unknown, and failed.
85+
* createdDatetime(datetime): The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP).
86+
* statusDatetime(datetime): The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP).
87+
*/
88+
protected $hlr;
89+
90+
/**
91+
* Get the href
92+
*
93+
* @return mixed
94+
*/
95+
public function getHref()
96+
{
97+
return $this->href;
98+
}
99+
100+
/**
101+
* Get the href
102+
*
103+
* @return mixed
104+
*/
105+
public function getCountryCode()
106+
{
107+
return $this->countryCode;
108+
}
109+
110+
/**
111+
* Get the href
112+
*
113+
* @return mixed
114+
*/
115+
public function getCountryPrefix()
116+
{
117+
return $this->countryPrefix;
118+
}
119+
120+
/**
121+
* Get the href
122+
*
123+
* @return mixed
124+
*/
125+
public function getPhoneNumber()
126+
{
127+
return $this->phoneNumber;
128+
}
129+
130+
/**
131+
* Get the href
132+
*
133+
* @return mixed
134+
*/
135+
public function getType()
136+
{
137+
return $this->type;
138+
}
139+
140+
/**
141+
* Get the href
142+
*
143+
* @return mixed
144+
*/
145+
public function getFormats()
146+
{
147+
return $this->formats;
148+
}
149+
150+
/**
151+
* Get the href
152+
*
153+
* @return mixed
154+
*/
155+
public function getHLR()
156+
{
157+
return $this->hlr;
158+
}
159+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace MessageBird\Resources;
4+
5+
use MessageBird\Objects;
6+
use MessageBird\Common;
7+
8+
/**
9+
* Class Verify
10+
*
11+
* @package MessageBird\Resources
12+
*/
13+
class Lookup extends Base
14+
{
15+
16+
/**
17+
* @param Common\HttpClient $HttpClient
18+
*/
19+
public function __construct(Common\HttpClient $HttpClient)
20+
{
21+
$this->setObject(new Objects\Lookup);
22+
$this->setResourceName('lookup');
23+
24+
parent::__construct($HttpClient);
25+
}
26+
27+
/**
28+
* @param $phoneNumber
29+
*
30+
* @return $this->Object
31+
*
32+
* @throws \MessageBird\Exceptions\HttpException
33+
* @throws \MessageBird\Exceptions\RequestException
34+
* @throws \MessageBird\Exceptions\ServerException
35+
*/
36+
public function read($phoneNumber = null)
37+
{
38+
$ResourceName = $this->resourceName . '/' . $phoneNumber;
39+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName);
40+
return $this->processRequest($body);
41+
}
42+
43+
private function hlr($phoneNumber, $method)
44+
{
45+
$ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ;
46+
list(, , $body) = $this->HttpClient->performHttpRequest($method, $ResourceName);
47+
return $this->processRequest($body);
48+
}
49+
50+
/**
51+
* @param $phoneNumber
52+
*
53+
* @return $this->Object
54+
*
55+
* @throws \MessageBird\Exceptions\HttpException
56+
* @throws \MessageBird\Exceptions\RequestException
57+
* @throws \MessageBird\Exceptions\ServerException
58+
*/
59+
public function readHLR($phoneNumber)
60+
{
61+
return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_GET);
62+
}
63+
64+
/**
65+
* @param $phoneNumber
66+
*
67+
* @return $this->Object
68+
*
69+
* @throws \MessageBird\Exceptions\HttpException
70+
* @throws \MessageBird\Exceptions\RequestException
71+
* @throws \MessageBird\Exceptions\ServerException
72+
*/
73+
public function requestHLR($phoneNumber)
74+
{
75+
return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_POST);
76+
}
77+
78+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace MessageBird\Resources;
4+
5+
use MessageBird\Objects;
6+
use MessageBird\Common;
7+
8+
/**
9+
* Class LookupHLR
10+
*
11+
* @package MessageBird\Resources
12+
*/
13+
class LookupHLR extends Base
14+
{
15+
16+
/**
17+
* @param Common\HttpClient $HttpClient
18+
*/
19+
public function __construct(Common\HttpClient $HttpClient)
20+
{
21+
$this->setObject(new Objects\HLR);
22+
$this->setResourceName('lookup');
23+
24+
parent::__construct($HttpClient);
25+
}
26+
27+
/**
28+
* @param $phoneNumber
29+
*
30+
* @return $this->Object
31+
*
32+
* @throws \MessageBird\Exceptions\HttpException
33+
* @throws \MessageBird\Exceptions\RequestException
34+
* @throws \MessageBird\Exceptions\ServerException
35+
*/
36+
public function create($hlr, $query = null)
37+
{
38+
$ResourceName = $this->resourceName . '/' . ($hlr->msisdn) . '/hlr' ;
39+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $ResourceName, $query, json_encode($hlr));
40+
return $this->processRequest($body);
41+
}
42+
43+
/**
44+
* @param $phoneNumber
45+
*
46+
* @return $this->Object
47+
*
48+
* @throws \MessageBird\Exceptions\HttpException
49+
* @throws \MessageBird\Exceptions\RequestException
50+
* @throws \MessageBird\Exceptions\ServerException
51+
*/
52+
public function read($phoneNumber = null, $query = null)
53+
{
54+
$ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ;
55+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query, null);
56+
return $this->processRequest($body);
57+
}
58+
59+
60+
}

0 commit comments

Comments
 (0)