Skip to content

Lookup #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 35 additions & 0 deletions examples/lookup-hlr-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

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

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

// create a new hlr request
$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 != \MessageBird\Objects\Hlr::STATUS_SENT) {
// we have something
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());

}
20 changes: 20 additions & 0 deletions examples/lookup-view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

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

try {
$Lookup = $MessageBird->lookup->read(31624971134);
var_dump($Lookup);

$Lookup = $MessageBird->lookup->read("624971134", "NL");
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());

}
14 changes: 13 additions & 1 deletion src/MessageBird/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,6 +44,16 @@ class Client
*/
public $balance;

/**
* @var Resources\Lookup
*/
public $lookup;

/**
* @var Resources\LookupHlr
*/
public $lookupHlr;

/**
* @var Common\HttpClient
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down
153 changes: 153 additions & 0 deletions src/MessageBird/Objects/Lookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

namespace MessageBird\Objects;

/**
* Class Lookup
*
* @package MessageBird\Objects
*/
class Lookup extends Base
{
const TYPE_FIXED_LINE = "fixed line";
const TYPE_MOBILE = "mobile";
const TYPE_FIXED_LINE_OR_MOBILE = "fixed line or mobile";
const TYPE_TOLL_FREE = "toll free";
const TYPE_PREMIUM_RATE = "premium rate";
const TYPE_SHARED_COST = "shared cost";
const TYPE_VOIP = "voip";
const TYPE_PERSONAL_NUMBER = "personal number";
const TYPE_PAGER = "pager";
const TYPE_UNIVERSAL_ACCESS_NUMBER = "universal access number";
const TYPE_VOICE_MAIL = "voice mail";
const TYPE_UNKNOWN = "unknown";

/**
* The URL of the created object.
*
* @var string
*/
protected $href;
/**
* The country code for this number in ISO 3166-1 alpha-2 format.
*
* @var string
*/
protected $countryCode;

/**
* The country calling code for this number.
*
* @var integer
*/
protected $countryPrefix;

/**
* The phone number in E.164 format without the prefixed plus-sign.
*
* @var integer
*/
protected $phoneNumber;

/**
* 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*
* @var string
*/
protected $type;

/**
* An associative array containing references to this phone number in several different formats.
*
* @var array
*
* e164: The phone number in E.164 format.
* international: The phone number in international format.
* national: The phone number in national/local format.
* rfc3966: The phone number in RFC3966 format.
*/
protected $formats;

/**
* The most recent HLR object. If no such HLR objects exists, this array won't be returned.
*
* @var array
*
* id(string): An unique random ID which is created on the MessageBird platform.
* network(int): The MCCMNC code of the network provider.
* reference(string): A client reference.
* status(string): The status of the HLR request. Possible values: sent, absent, active, unknown, and failed.
* createdDatetime(datetime): The date and time of the creation of the message in RFC3339 format (Y-m-d\TH:i:sP).
* statusDatetime(datetime): The datum time of the last status in RFC3339 format (Y-m-d\TH:i:sP).
*/
protected $hlr;

/**
* Get the href
*
* @return mixed
*/
public function getHref()
{
return $this->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;
}
}
2 changes: 1 addition & 1 deletion src/MessageBird/Objects/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/MessageBird/Objects/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions src/MessageBird/Resources/Lookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace MessageBird\Resources;

use MessageBird\Objects;
use MessageBird\Common;
use InvalidArgumentException;

/**
* Class Verify
*
* @package MessageBird\Resources
*/
class Lookup extends Base
{

/**
* @param Common\HttpClient $HttpClient
*/
public function __construct(Common\HttpClient $HttpClient)
{
$this->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, $countryCode = null)
{
if(empty($phoneNumber)) {
throw new InvalidArgumentException('The phone number cannot be empty.');
}
$query = null;
if ($countryCode != null) {
$query = array("countryCode" => $countryCode);
}
$ResourceName = $this->resourceName . '/' . $phoneNumber;
list(, , $body) = $this->HttpClient->performHttpRequest(Common\HttpClient::REQUEST_GET, $ResourceName, $query);
return $this->processRequest($body);
}
}
Loading