From d2ffdd99170d32f1186cb0ca4217ea7000936c33 Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Tue, 15 Dec 2015 10:35:18 +0100 Subject: [PATCH 1/9] add lookup endpoints --- examples/lookup-hlr-view.php | 38 ++++++ examples/lookup-view.php | 20 +++ src/MessageBird/Client.php | 12 ++ src/MessageBird/Objects/Lookup.php | 159 ++++++++++++++++++++++++ src/MessageBird/Resources/Lookup.php | 78 ++++++++++++ src/MessageBird/Resources/LookupHLR.php | 60 +++++++++ tests/integration/lookup/LookupTest.php | 42 +++++++ 7 files changed, 409 insertions(+) create mode 100644 examples/lookup-hlr-view.php create mode 100644 examples/lookup-view.php create mode 100644 src/MessageBird/Objects/Lookup.php create mode 100644 src/MessageBird/Resources/Lookup.php create mode 100644 src/MessageBird/Resources/LookupHLR.php create mode 100644 tests/integration/lookup/LookupTest.php diff --git a/examples/lookup-hlr-view.php b/examples/lookup-hlr-view.php new file mode 100644 index 00000000..a783e144 --- /dev/null +++ b/examples/lookup-hlr-view.php @@ -0,0 +1,38 @@ +msisdn = '31624971134'; + $Hlr->reference = "yoloswag3001"; + + // create a new hlr request + // curl -X POST https://rest.messagebird.com/lookup/31624971134/hlr -H 'Authorization: AccessKey ve_q2rh0rCJPmmpbNrJLE8xUtdJv' -d "msisdn=31624971134" -d "reference=NOIII" + // 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 + + var_dump(json_encode($Hlr)); + + $hlr = $MessageBird->lookupHLR->create($Hlr); + + // pool for the results + $poolCount = 10; + while($poolCount--) { + $hlr = $MessageBird->lookupHLR->read($Hlr->msisdn); + if ($hlr->status != 'sent') { + var_dump($hlr); + break; + } + sleep(0.5); + } + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + var_dump($e->getMessage()); + +} diff --git a/examples/lookup-view.php b/examples/lookup-view.php new file mode 100644 index 00000000..10c2b3f0 --- /dev/null +++ b/examples/lookup-view.php @@ -0,0 +1,20 @@ +lookup->read($phoneNumber); + var_dump($Lookup); + +} catch (\MessageBird\Exceptions\AuthenticateException $e) { + // That means that your accessKey is unknown + echo 'wrong login'; + +} catch (\Exception $e) { + var_dump($e->getMessage()); + +} diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index d20516d2..aed25d43 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -44,6 +44,16 @@ class Client */ public $balance; + /** + * @var Resources\Lookup + */ + public $lookup; + + /** + * @var Resources\LookupHLR + */ + public $lookupHLR; + /** * @var Common\HttpClient */ @@ -72,6 +82,8 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->verify = new Resources\Verify($this->HttpClient); $this->balance = new Resources\Balance($this->HttpClient); $this->voicemessages = new Resources\VoiceMessage($this->HttpClient); + $this->lookup = new Resources\Lookup($this->HttpClient); + $this->lookupHLR = new Resources\LookupHLR($this->HttpClient); } /** diff --git a/src/MessageBird/Objects/Lookup.php b/src/MessageBird/Objects/Lookup.php new file mode 100644 index 00000000..5e7c8327 --- /dev/null +++ b/src/MessageBird/Objects/Lookup.php @@ -0,0 +1,159 @@ +href; + } + + /** + * Get the href + * + * @return mixed + */ + public function getCountryCode() + { + return $this->countryCode; + } + + /** + * Get the href + * + * @return mixed + */ + public function getCountryPrefix() + { + return $this->countryPrefix; + } + + /** + * Get the href + * + * @return mixed + */ + public function getPhoneNumber() + { + return $this->phoneNumber; + } + + /** + * Get the href + * + * @return mixed + */ + public function getType() + { + return $this->type; + } + + /** + * Get the href + * + * @return mixed + */ + public function getFormats() + { + return $this->formats; + } + + /** + * Get the href + * + * @return mixed + */ + public function getHLR() + { + return $this->hlr; + } +} diff --git a/src/MessageBird/Resources/Lookup.php b/src/MessageBird/Resources/Lookup.php new file mode 100644 index 00000000..1bf2ded8 --- /dev/null +++ b/src/MessageBird/Resources/Lookup.php @@ -0,0 +1,78 @@ +setObject(new Objects\Lookup); + $this->setResourceName('lookup'); + + parent::__construct($HttpClient); + } + + /** + * @param $phoneNumber + * + * @return $this->Object + * + * @throws \MessageBird\Exceptions\HttpException + * @throws \MessageBird\Exceptions\RequestException + * @throws \MessageBird\Exceptions\ServerException + */ + public function read($phoneNumber = null) + { + $ResourceName = $this->resourceName . '/' . $phoneNumber; + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName); + return $this->processRequest($body); + } + + private function hlr($phoneNumber, $method) + { + $ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ; + list(, , $body) = $this->HttpClient->performHttpRequest($method, $ResourceName); + return $this->processRequest($body); + } + + /** + * @param $phoneNumber + * + * @return $this->Object + * + * @throws \MessageBird\Exceptions\HttpException + * @throws \MessageBird\Exceptions\RequestException + * @throws \MessageBird\Exceptions\ServerException + */ + public function readHLR($phoneNumber) + { + return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_GET); + } + + /** + * @param $phoneNumber + * + * @return $this->Object + * + * @throws \MessageBird\Exceptions\HttpException + * @throws \MessageBird\Exceptions\RequestException + * @throws \MessageBird\Exceptions\ServerException + */ + public function requestHLR($phoneNumber) + { + return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_POST); + } + +} diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHLR.php new file mode 100644 index 00000000..2bf33ef1 --- /dev/null +++ b/src/MessageBird/Resources/LookupHLR.php @@ -0,0 +1,60 @@ +setObject(new Objects\HLR); + $this->setResourceName('lookup'); + + parent::__construct($HttpClient); + } + + /** + * @param $phoneNumber + * + * @return $this->Object + * + * @throws \MessageBird\Exceptions\HttpException + * @throws \MessageBird\Exceptions\RequestException + * @throws \MessageBird\Exceptions\ServerException + */ + public function create($hlr, $query = null) + { + $ResourceName = $this->resourceName . '/' . ($hlr->msisdn) . '/hlr' ; + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $ResourceName, $query, json_encode($hlr)); + return $this->processRequest($body); + } + + /** + * @param $phoneNumber + * + * @return $this->Object + * + * @throws \MessageBird\Exceptions\HttpException + * @throws \MessageBird\Exceptions\RequestException + * @throws \MessageBird\Exceptions\ServerException + */ + public function read($phoneNumber = null, $query = null) + { + $ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ; + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query, null); + return $this->processRequest($body); + } + + +} diff --git a/tests/integration/lookup/LookupTest.php b/tests/integration/lookup/LookupTest.php new file mode 100644 index 00000000..cd7e363f --- /dev/null +++ b/tests/integration/lookup/LookupTest.php @@ -0,0 +1,42 @@ +client = new \MessageBird\Client('YOUR_ACCESS_KEY', $this->mockClient); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadLookup() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/31612345678', null, null); + $this->client->lookup->read(31612345678); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testCreateLookupHLR() + { + $Hlr = new \MessageBird\Objects\Hlr(); + $Hlr->msisdn = 31612345678; + $Hlr->reference = 'Yoloswag3007'; + + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'lookup/'.$Hlr->msisdn.'/hlr', null, json_encode($Hlr)); + + $this->client->lookupHLR->create($Hlr); + } + + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadLookupHLR() + { + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/31612345678/hlr', null, null); + $this->client->lookupHLR->read(31612345678); + } + +} From ca8e4b57dd9c4ab3e7116d10944fc099283e5343 Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Wed, 16 Dec 2015 09:47:50 +0100 Subject: [PATCH 2/9] new lookup endpoints now working --- examples/lookup-hlr-view.php | 9 ++--- examples/lookup-view.php | 7 ++-- src/MessageBird/Objects/Lookup.php | 6 ---- src/MessageBird/Resources/Lookup.php | 44 ++++--------------------- src/MessageBird/Resources/LookupHLR.php | 12 +++++-- tests/integration/lookup/LookupTest.php | 36 ++++++++++++++++++++ 6 files changed, 59 insertions(+), 55 deletions(-) diff --git a/examples/lookup-hlr-view.php b/examples/lookup-hlr-view.php index a783e144..200dddbe 100644 --- a/examples/lookup-hlr-view.php +++ b/examples/lookup-hlr-view.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('live_q2rh0rCJPmmpbNrJLE8xUtdJv'); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { $Hlr = new \MessageBird\Objects\Hlr(); @@ -10,18 +10,15 @@ $Hlr->reference = "yoloswag3001"; // create a new hlr request - // curl -X POST https://rest.messagebird.com/lookup/31624971134/hlr -H 'Authorization: AccessKey ve_q2rh0rCJPmmpbNrJLE8xUtdJv' -d "msisdn=31624971134" -d "reference=NOIII" - // 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 - - var_dump(json_encode($Hlr)); - $hlr = $MessageBird->lookupHLR->create($Hlr); + var_dump($hlr); // pool for the results $poolCount = 10; while($poolCount--) { $hlr = $MessageBird->lookupHLR->read($Hlr->msisdn); if ($hlr->status != 'sent') { + // we have something var_dump($hlr); break; } diff --git a/examples/lookup-view.php b/examples/lookup-view.php index 10c2b3f0..1ec7e504 100644 --- a/examples/lookup-view.php +++ b/examples/lookup-view.php @@ -2,12 +2,13 @@ require_once(__DIR__ . '/../autoload.php'); -$MessageBird = new \MessageBird\Client('live_q2rh0rCJPmmpbNrJLE8xUtdJv'); // Set your own API access key here. +$MessageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here. try { + $Lookup = $MessageBird->lookup->read(31624971134); + var_dump($Lookup); - $phoneNumber = 31624971134; - $Lookup = $MessageBird->lookup->read($phoneNumber); + $Lookup = $MessageBird->lookup->read("624971134", "NL"); var_dump($Lookup); } catch (\MessageBird\Exceptions\AuthenticateException $e) { diff --git a/src/MessageBird/Objects/Lookup.php b/src/MessageBird/Objects/Lookup.php index 5e7c8327..7b3d8047 100644 --- a/src/MessageBird/Objects/Lookup.php +++ b/src/MessageBird/Objects/Lookup.php @@ -22,12 +22,6 @@ class Lookup extends Base const TYPE_VOICE_MAIL = "voice mail"; const TYPE_UNKNOWN = "unknown"; - const HRL_STATUS_SENT = "sent"; - const HRL_STATUS_ABSENT = "absent"; - const HRL_STATUS_ACTIVE = "active"; - const HRL_STATUS_UNKNOWN = "unknown"; - const HRL_STATUS_FALIED = "failed"; - /** * The URL of the created object. * diff --git a/src/MessageBird/Resources/Lookup.php b/src/MessageBird/Resources/Lookup.php index 1bf2ded8..67234326 100644 --- a/src/MessageBird/Resources/Lookup.php +++ b/src/MessageBird/Resources/Lookup.php @@ -33,46 +33,14 @@ public function __construct(Common\HttpClient $HttpClient) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber = null) + public function read($phoneNumber = null, $countryCode = null) { + $query = null; + if ($countryCode != null) { + $query = array("countryCode" => $countryCode); + } $ResourceName = $this->resourceName . '/' . $phoneNumber; - list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName); + list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query); return $this->processRequest($body); } - - private function hlr($phoneNumber, $method) - { - $ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ; - list(, , $body) = $this->HttpClient->performHttpRequest($method, $ResourceName); - return $this->processRequest($body); - } - - /** - * @param $phoneNumber - * - * @return $this->Object - * - * @throws \MessageBird\Exceptions\HttpException - * @throws \MessageBird\Exceptions\RequestException - * @throws \MessageBird\Exceptions\ServerException - */ - public function readHLR($phoneNumber) - { - return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_GET); - } - - /** - * @param $phoneNumber - * - * @return $this->Object - * - * @throws \MessageBird\Exceptions\HttpException - * @throws \MessageBird\Exceptions\RequestException - * @throws \MessageBird\Exceptions\ServerException - */ - public function requestHLR($phoneNumber) - { - return $this->hlr($phoneNumber, Common\HttpClient::REQUEST_POST); - } - } diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHLR.php index 2bf33ef1..94201103 100644 --- a/src/MessageBird/Resources/LookupHLR.php +++ b/src/MessageBird/Resources/LookupHLR.php @@ -33,8 +33,12 @@ public function __construct(Common\HttpClient $HttpClient) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function create($hlr, $query = null) + public function create($hlr, $countryCode = null) { + $query = null; + if ($countryCode != null) { + $query = array("countryCode" => $countryCode); + } $ResourceName = $this->resourceName . '/' . ($hlr->msisdn) . '/hlr' ; list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_POST, $ResourceName, $query, json_encode($hlr)); return $this->processRequest($body); @@ -49,8 +53,12 @@ public function create($hlr, $query = null) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber = null, $query = null) + public function read($phoneNumber = null, $countryCode = null) { + $query = null; + if ($countryCode != null) { + $query = array("countryCode" => $countryCode); + } $ResourceName = $this->resourceName . '/' . $phoneNumber . '/hlr' ; list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query, null); return $this->processRequest($body); diff --git a/tests/integration/lookup/LookupTest.php b/tests/integration/lookup/LookupTest.php index cd7e363f..3dd0f93e 100644 --- a/tests/integration/lookup/LookupTest.php +++ b/tests/integration/lookup/LookupTest.php @@ -16,6 +16,16 @@ public function testReadLookup() $this->client->lookup->read(31612345678); } + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadLookupWithCountryCode() + { + $params = array("countryCode" => "NL"); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/612345678', $params, null); + $this->client->lookup->read(612345678, $params["countryCode"]); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ @@ -30,6 +40,22 @@ public function testCreateLookupHLR() $this->client->lookupHLR->create($Hlr); } + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testCreateLookupHLRWithCountryCode() + { + $Hlr = new \MessageBird\Objects\Hlr(); + $Hlr->msisdn = 612345678; + $Hlr->reference = "CoolReference"; + + $params = array("countryCode" => "NL"); + + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'lookup/'.$Hlr->msisdn.'/hlr', $params, json_encode($Hlr)); + + $this->client->lookupHLR->create($Hlr, $params["countryCode"]); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ @@ -39,4 +65,14 @@ public function testReadLookupHLR() $this->client->lookupHLR->read(31612345678); } + /** + * @expectedException MessageBird\Exceptions\ServerException + */ + public function testReadLookupHLRWithCountryCode() + { + $params = array("countryCode" => "NL"); + $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/612345678/hlr', $params, null); + $this->client->lookupHLR->read(612345678, $params["countryCode"]); + } + } From e95025068169f823d706e0663c0e504d09093372 Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Wed, 16 Dec 2015 10:17:17 +0100 Subject: [PATCH 3/9] lookup endpoints: use a constant on the example, it's prettier --- examples/lookup-hlr-view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lookup-hlr-view.php b/examples/lookup-hlr-view.php index 200dddbe..2b97af45 100644 --- a/examples/lookup-hlr-view.php +++ b/examples/lookup-hlr-view.php @@ -17,7 +17,7 @@ $poolCount = 10; while($poolCount--) { $hlr = $MessageBird->lookupHLR->read($Hlr->msisdn); - if ($hlr->status != 'sent') { + if ($hlr->status != \MessageBird\Objects\Hlr::STATUS_SENT) { // we have something var_dump($hlr); break; From fdf31d6bd0cb5ca4dad3ccab40bd7904c2792294 Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Wed, 16 Dec 2015 10:23:25 +0100 Subject: [PATCH 4/9] php doesn't have 'hashes'. Replace for 'associative array'. --- src/MessageBird/Objects/Lookup.php | 8 ++++---- src/MessageBird/Objects/Message.php | 2 +- src/MessageBird/Objects/Verify.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MessageBird/Objects/Lookup.php b/src/MessageBird/Objects/Lookup.php index 7b3d8047..34c8429a 100644 --- a/src/MessageBird/Objects/Lookup.php +++ b/src/MessageBird/Objects/Lookup.php @@ -56,9 +56,9 @@ class Lookup extends Base protected $type; /** - * A hash containing references to this phone number in several different formats. + * An associative array containing references to this phone number in several different formats. * - * @var hash + * @var array * * e164: The phone number in E.164 format. * international: The phone number in international format. @@ -68,9 +68,9 @@ class Lookup extends Base protected $formats; /** - * The most recent HLR object. If no such HLR objects exists, this hash won't be returned. + * The most recent HLR object. If no such HLR objects exists, this array won't be returned. * - * @var hash + * @var array * * id(string): An unique random ID which is created on the MessageBird platform. * network(int): The MCCMNC code of the network provider. diff --git a/src/MessageBird/Objects/Message.php b/src/MessageBird/Objects/Message.php index b5c3c2c1..47663f18 100644 --- a/src/MessageBird/Objects/Message.php +++ b/src/MessageBird/Objects/Message.php @@ -89,7 +89,7 @@ class Message extends Base public $gateway; /** - * A hash with extra information. Is only used when a binary or premium + * An associative array with extra information. Is only used when a binary or premium * message is sent. * * @var array diff --git a/src/MessageBird/Objects/Verify.php b/src/MessageBird/Objects/Verify.php index a43db6fc..6467f4ca 100644 --- a/src/MessageBird/Objects/Verify.php +++ b/src/MessageBird/Objects/Verify.php @@ -46,7 +46,7 @@ class Verify extends Base public $reference; /** - * A hash containing one href entry referring to the URL of the created object. + * An associative array containing one href entry referring to the URL of the created object. * The entry can either refer to either the messages or the voicemessages endpoint * * @var object From 129cff828800ec63c87325d2d58ad87d46cd5a4c Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Wed, 16 Dec 2015 16:16:20 +0100 Subject: [PATCH 5/9] new lookup endpoints: prevent user to call methods without a phone number --- examples/lookup-view.php | 1 - src/MessageBird/Resources/Lookup.php | 6 +++++- src/MessageBird/Resources/LookupHLR.php | 11 ++++++++++- tests/integration/lookup/LookupTest.php | 26 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/examples/lookup-view.php b/examples/lookup-view.php index 1ec7e504..ea9c9db1 100644 --- a/examples/lookup-view.php +++ b/examples/lookup-view.php @@ -10,7 +10,6 @@ $Lookup = $MessageBird->lookup->read("624971134", "NL"); var_dump($Lookup); - } catch (\MessageBird\Exceptions\AuthenticateException $e) { // That means that your accessKey is unknown echo 'wrong login'; diff --git a/src/MessageBird/Resources/Lookup.php b/src/MessageBird/Resources/Lookup.php index 67234326..46e469e3 100644 --- a/src/MessageBird/Resources/Lookup.php +++ b/src/MessageBird/Resources/Lookup.php @@ -4,6 +4,7 @@ use MessageBird\Objects; use MessageBird\Common; +use InvalidArgumentException; /** * Class Verify @@ -33,8 +34,11 @@ public function __construct(Common\HttpClient $HttpClient) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber = null, $countryCode = null) + public function read($phoneNumber, $countryCode = null) { + if(empty($phoneNumber)) { + throw new InvalidArgumentException('The phone number cannot be empty.'); + } $query = null; if ($countryCode != null) { $query = array("countryCode" => $countryCode); diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHLR.php index 94201103..16a4a25c 100644 --- a/src/MessageBird/Resources/LookupHLR.php +++ b/src/MessageBird/Resources/LookupHLR.php @@ -4,6 +4,7 @@ use MessageBird\Objects; use MessageBird\Common; +use InvalidArgumentException; /** * Class LookupHLR @@ -35,6 +36,10 @@ public function __construct(Common\HttpClient $HttpClient) */ public function create($hlr, $countryCode = null) { + if(empty($hlr->msisdn)) { + throw new InvalidArgumentException('The phone number ($hlr->msisdn) cannot be empty.'); + } + $query = null; if ($countryCode != null) { $query = array("countryCode" => $countryCode); @@ -53,8 +58,12 @@ public function create($hlr, $countryCode = null) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber = null, $countryCode = null) + public function read($phoneNumber, $countryCode = null) { + if(empty($phoneNumber)) { + throw new InvalidArgumentException('The phone number cannot be empty.'); + } + $query = null; if ($countryCode != null) { $query = array("countryCode" => $countryCode); diff --git a/tests/integration/lookup/LookupTest.php b/tests/integration/lookup/LookupTest.php index 3dd0f93e..0140fc43 100644 --- a/tests/integration/lookup/LookupTest.php +++ b/tests/integration/lookup/LookupTest.php @@ -16,6 +16,14 @@ public function testReadLookup() $this->client->lookup->read(31612345678); } + /** + * @expectedException InvalidArgumentException + */ + public function testReadLookupWithEmptyNumber() + { + $this->client->lookup->read(null); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ @@ -40,6 +48,16 @@ public function testCreateLookupHLR() $this->client->lookupHLR->create($Hlr); } + /** + * @expectedException InvalidArgumentException + */ + public function testCreateLookupHLRWithEmptyNumber() + { + $Hlr = new \MessageBird\Objects\Hlr(); + $Hlr->msisdn = null; + $this->client->lookupHLR->create($Hlr); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ @@ -65,6 +83,14 @@ public function testReadLookupHLR() $this->client->lookupHLR->read(31612345678); } + /** + * @expectedException InvalidArgumentException + */ + public function testReadLookupHLRWithEmptyNumber() + { + $this->client->lookupHLR->read(null); + } + /** * @expectedException MessageBird\Exceptions\ServerException */ From 3159933d1e8a53d7689957301801b88d04b30cc2 Mon Sep 17 00:00:00 2001 From: Marcel Corso Date: Wed, 16 Dec 2015 16:38:16 +0100 Subject: [PATCH 6/9] new lookup endpoints: non-null first param of read() fails because it can be null on the parent method --- src/MessageBird/Resources/Lookup.php | 2 +- src/MessageBird/Resources/LookupHLR.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MessageBird/Resources/Lookup.php b/src/MessageBird/Resources/Lookup.php index 46e469e3..906a05f5 100644 --- a/src/MessageBird/Resources/Lookup.php +++ b/src/MessageBird/Resources/Lookup.php @@ -34,7 +34,7 @@ public function __construct(Common\HttpClient $HttpClient) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber, $countryCode = null) + public function read($phoneNumber = null, $countryCode = null) { if(empty($phoneNumber)) { throw new InvalidArgumentException('The phone number cannot be empty.'); diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHLR.php index 16a4a25c..7242518d 100644 --- a/src/MessageBird/Resources/LookupHLR.php +++ b/src/MessageBird/Resources/LookupHLR.php @@ -58,7 +58,7 @@ public function create($hlr, $countryCode = null) * @throws \MessageBird\Exceptions\RequestException * @throws \MessageBird\Exceptions\ServerException */ - public function read($phoneNumber, $countryCode = null) + public function read($phoneNumber = null, $countryCode = null) { if(empty($phoneNumber)) { throw new InvalidArgumentException('The phone number cannot be empty.'); From d1ac318c59f3fe952cfca6da7a051c128c2549cb Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Wed, 16 Dec 2015 16:51:35 +0100 Subject: [PATCH 7/9] Change the HLR part in LookupHLR to camel-casing --- examples/lookup-hlr-view.php | 4 ++-- src/MessageBird/Client.php | 6 +++--- src/MessageBird/Resources/LookupHLR.php | 4 ++-- tests/integration/lookup/LookupTest.php | 24 ++++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/lookup-hlr-view.php b/examples/lookup-hlr-view.php index 2b97af45..db0e774e 100644 --- a/examples/lookup-hlr-view.php +++ b/examples/lookup-hlr-view.php @@ -10,13 +10,13 @@ $Hlr->reference = "yoloswag3001"; // create a new hlr request - $hlr = $MessageBird->lookupHLR->create($Hlr); + $hlr = $MessageBird->lookupHlr->create($Hlr); var_dump($hlr); // pool for the results $poolCount = 10; while($poolCount--) { - $hlr = $MessageBird->lookupHLR->read($Hlr->msisdn); + $hlr = $MessageBird->lookupHlr->read($Hlr->msisdn); if ($hlr->status != \MessageBird\Objects\Hlr::STATUS_SENT) { // we have something var_dump($hlr); diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index aed25d43..5e22806c 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -50,9 +50,9 @@ class Client public $lookup; /** - * @var Resources\LookupHLR + * @var Resources\LookupHlr */ - public $lookupHLR; + public $lookupHlr; /** * @var Common\HttpClient @@ -83,7 +83,7 @@ public function __construct($accessKey = null, Common\HttpClient $httpClient = n $this->balance = new Resources\Balance($this->HttpClient); $this->voicemessages = new Resources\VoiceMessage($this->HttpClient); $this->lookup = new Resources\Lookup($this->HttpClient); - $this->lookupHLR = new Resources\LookupHLR($this->HttpClient); + $this->lookupHlr = new Resources\LookupHlr($this->HttpClient); } /** diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHLR.php index 7242518d..9b2a13ac 100644 --- a/src/MessageBird/Resources/LookupHLR.php +++ b/src/MessageBird/Resources/LookupHLR.php @@ -7,11 +7,11 @@ use InvalidArgumentException; /** - * Class LookupHLR + * Class LookupHlr * * @package MessageBird\Resources */ -class LookupHLR extends Base +class LookupHlr extends Base { /** diff --git a/tests/integration/lookup/LookupTest.php b/tests/integration/lookup/LookupTest.php index 0140fc43..4e14685c 100644 --- a/tests/integration/lookup/LookupTest.php +++ b/tests/integration/lookup/LookupTest.php @@ -37,7 +37,7 @@ public function testReadLookupWithCountryCode() /** * @expectedException MessageBird\Exceptions\ServerException */ - public function testCreateLookupHLR() + public function testCreateLookupHlr() { $Hlr = new \MessageBird\Objects\Hlr(); $Hlr->msisdn = 31612345678; @@ -45,23 +45,23 @@ public function testCreateLookupHLR() $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'lookup/'.$Hlr->msisdn.'/hlr', null, json_encode($Hlr)); - $this->client->lookupHLR->create($Hlr); + $this->client->lookupHlr->create($Hlr); } /** * @expectedException InvalidArgumentException */ - public function testCreateLookupHLRWithEmptyNumber() + public function testCreateLookupHlrWithEmptyNumber() { $Hlr = new \MessageBird\Objects\Hlr(); $Hlr->msisdn = null; - $this->client->lookupHLR->create($Hlr); + $this->client->lookupHlr->create($Hlr); } /** * @expectedException MessageBird\Exceptions\ServerException */ - public function testCreateLookupHLRWithCountryCode() + public function testCreateLookupHlrWithCountryCode() { $Hlr = new \MessageBird\Objects\Hlr(); $Hlr->msisdn = 612345678; @@ -71,34 +71,34 @@ public function testCreateLookupHLRWithCountryCode() $this->mockClient->expects($this->once())->method('performHttpRequest')->with("POST", 'lookup/'.$Hlr->msisdn.'/hlr', $params, json_encode($Hlr)); - $this->client->lookupHLR->create($Hlr, $params["countryCode"]); + $this->client->lookupHlr->create($Hlr, $params["countryCode"]); } /** * @expectedException MessageBird\Exceptions\ServerException */ - public function testReadLookupHLR() + public function testReadLookupHlr() { $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/31612345678/hlr', null, null); - $this->client->lookupHLR->read(31612345678); + $this->client->lookupHlr->read(31612345678); } /** * @expectedException InvalidArgumentException */ - public function testReadLookupHLRWithEmptyNumber() + public function testReadLookupHlrWithEmptyNumber() { - $this->client->lookupHLR->read(null); + $this->client->lookupHlr->read(null); } /** * @expectedException MessageBird\Exceptions\ServerException */ - public function testReadLookupHLRWithCountryCode() + public function testReadLookupHlrWithCountryCode() { $params = array("countryCode" => "NL"); $this->mockClient->expects($this->once())->method('performHttpRequest')->with("GET", 'lookup/612345678/hlr', $params, null); - $this->client->lookupHLR->read(612345678, $params["countryCode"]); + $this->client->lookupHlr->read(612345678, $params["countryCode"]); } } From f605aec318325df0c0cb1ae06fd474126be66b4c Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Wed, 16 Dec 2015 16:56:44 +0100 Subject: [PATCH 8/9] Bump the version to 1.3.0 --- README.md | 4 ++-- composer.json | 2 +- src/MessageBird/Client.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c0019939..2d28dc4b 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ Installation ####Composer installation - [Download composer](https://getcomposer.org/doc/00-intro.md#installation-nix) -- Add the `"messagebird/php-rest-api": "1.2.x"` into the `require` section of your `composer.json`. +- Add the `"messagebird/php-rest-api": "1.3.x"` into the `require` section of your `composer.json`. - Run `composer install`. ``` { "require": { - "messagebird/php-rest-api": "1.2.x" + "messagebird/php-rest-api": "1.3.x" } } ``` diff --git a/composer.json b/composer.json index 8c94f531..162085af 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "messagebird/php-rest-api", "description": "MessageBird REST API client for PHP", - "version": "1.2.0", + "version": "1.3.0", "type": "library", "homepage": "https://github.com/messagebird/php-rest-api", "license": "BSD-2-Clause", diff --git a/src/MessageBird/Client.php b/src/MessageBird/Client.php index 5e22806c..1397ba4f 100644 --- a/src/MessageBird/Client.php +++ b/src/MessageBird/Client.php @@ -12,7 +12,7 @@ class Client const ENDPOINT = 'https://rest.messagebird.com'; - const CLIENT_VERSION = '1.2.0'; + const CLIENT_VERSION = '1.3.0'; /** * @var string From 77c9712d3ff40746ab35275179931f229828a745 Mon Sep 17 00:00:00 2001 From: Sam Wierema Date: Wed, 16 Dec 2015 17:01:42 +0100 Subject: [PATCH 9/9] Rename LookupHLR.php to LookupHlr.php --- src/MessageBird/Resources/{LookupHLR.php => LookupHlr.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/MessageBird/Resources/{LookupHLR.php => LookupHlr.php} (100%) diff --git a/src/MessageBird/Resources/LookupHLR.php b/src/MessageBird/Resources/LookupHlr.php similarity index 100% rename from src/MessageBird/Resources/LookupHLR.php rename to src/MessageBird/Resources/LookupHlr.php