Skip to content

Commit ca8e4b5

Browse files
author
Marcel Corso
committed
new lookup endpoints now working
1 parent d2ffdd9 commit ca8e4b5

File tree

6 files changed

+59
-55
lines changed

6 files changed

+59
-55
lines changed

examples/lookup-hlr-view.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22

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

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

77
try {
88
$Hlr = new \MessageBird\Objects\Hlr();
99
$Hlr->msisdn = '31624971134';
1010
$Hlr->reference = "yoloswag3001";
1111

1212
// 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-
1813
$hlr = $MessageBird->lookupHLR->create($Hlr);
14+
var_dump($hlr);
1915

2016
// pool for the results
2117
$poolCount = 10;
2218
while($poolCount--) {
2319
$hlr = $MessageBird->lookupHLR->read($Hlr->msisdn);
2420
if ($hlr->status != 'sent') {
21+
// we have something
2522
var_dump($hlr);
2623
break;
2724
}

examples/lookup-view.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

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

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

77
try {
8+
$Lookup = $MessageBird->lookup->read(31624971134);
9+
var_dump($Lookup);
810

9-
$phoneNumber = 31624971134;
10-
$Lookup = $MessageBird->lookup->read($phoneNumber);
11+
$Lookup = $MessageBird->lookup->read("624971134", "NL");
1112
var_dump($Lookup);
1213

1314
} catch (\MessageBird\Exceptions\AuthenticateException $e) {

src/MessageBird/Objects/Lookup.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ class Lookup extends Base
2222
const TYPE_VOICE_MAIL = "voice mail";
2323
const TYPE_UNKNOWN = "unknown";
2424

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-
3125
/**
3226
* The URL of the created object.
3327
*

src/MessageBird/Resources/Lookup.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,14 @@ public function __construct(Common\HttpClient $HttpClient)
3333
* @throws \MessageBird\Exceptions\RequestException
3434
* @throws \MessageBird\Exceptions\ServerException
3535
*/
36-
public function read($phoneNumber = null)
36+
public function read($phoneNumber = null, $countryCode = null)
3737
{
38+
$query = null;
39+
if ($countryCode != null) {
40+
$query = array("countryCode" => $countryCode);
41+
}
3842
$ResourceName = $this->resourceName . '/' . $phoneNumber;
39-
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName);
43+
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query);
4044
return $this->processRequest($body);
4145
}
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-
7846
}

src/MessageBird/Resources/LookupHLR.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ public function __construct(Common\HttpClient $HttpClient)
3333
* @throws \MessageBird\Exceptions\RequestException
3434
* @throws \MessageBird\Exceptions\ServerException
3535
*/
36-
public function create($hlr, $query = null)
36+
public function create($hlr, $countryCode = null)
3737
{
38+
$query = null;
39+
if ($countryCode != null) {
40+
$query = array("countryCode" => $countryCode);
41+
}
3842
$ResourceName = $this->resourceName . '/' . ($hlr->msisdn) . '/hlr' ;
3943
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $ResourceName, $query, json_encode($hlr));
4044
return $this->processRequest($body);
@@ -49,8 +53,12 @@ public function create($hlr, $query = null)
4953
* @throws \MessageBird\Exceptions\RequestException
5054
* @throws \MessageBird\Exceptions\ServerException
5155
*/
52-
public function read($phoneNumber = null, $query = null)
56+
public function read($phoneNumber = null, $countryCode = null)
5357
{
58+
$query = null;
59+
if ($countryCode != null) {
60+
$query = array("countryCode" => $countryCode);
61+
}
5462
$ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ;
5563
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query, null);
5664
return $this->processRequest($body);

tests/integration/lookup/LookupTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public function testReadLookup()
1616
$this->client->lookup->read(31612345678);
1717
}
1818

19+
/**
20+
* @expectedException MessageBird\Exceptions\ServerException
21+
*/
22+
public function testReadLookupWithCountryCode()
23+
{
24+
$params = array("countryCode" => "NL");
25+
$this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/612345678', $params, null);
26+
$this->client->lookup->read(612345678, $params["countryCode"]);
27+
}
28+
1929
/**
2030
* @expectedException MessageBird\Exceptions\ServerException
2131
*/
@@ -30,6 +40,22 @@ public function testCreateLookupHLR()
3040
$this->client->lookupHLR->create($Hlr);
3141
}
3242

43+
/**
44+
* @expectedException MessageBird\Exceptions\ServerException
45+
*/
46+
public function testCreateLookupHLRWithCountryCode()
47+
{
48+
$Hlr = new \MessageBird\Objects\Hlr();
49+
$Hlr->msisdn = 612345678;
50+
$Hlr->reference = "CoolReference";
51+
52+
$params = array("countryCode" => "NL");
53+
54+
$this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'lookup/'.$Hlr->msisdn.'/hlr', $params, json_encode($Hlr));
55+
56+
$this->client->lookupHLR->create($Hlr, $params["countryCode"]);
57+
}
58+
3359
/**
3460
* @expectedException MessageBird\Exceptions\ServerException
3561
*/
@@ -39,4 +65,14 @@ public function testReadLookupHLR()
3965
$this->client->lookupHLR->read(31612345678);
4066
}
4167

68+
/**
69+
* @expectedException MessageBird\Exceptions\ServerException
70+
*/
71+
public function testReadLookupHLRWithCountryCode()
72+
{
73+
$params = array("countryCode" => "NL");
74+
$this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/612345678/hlr', $params, null);
75+
$this->client->lookupHLR->read(612345678, $params["countryCode"]);
76+
}
77+
4278
}

0 commit comments

Comments
 (0)