Skip to content
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

Completed the access key and secret key functionality #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"autoload": {
"psr-4": {
"FlowrouteNumbersLib\\": "src/"
"FlowrouteNumbersLib\\": "src/FlowrouteNumbers/"
}
}
}
}
95 changes: 24 additions & 71 deletions demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
error_reporting(E_ALL);

require_once('vendor/autoload.php');
foreach (glob('src/*.php') as $filename){require_once $filename;}
foreach (glob('src/Controllers/*.php') as $filename){require_once $filename;}
foreach (glob('src/Models/*.php') as $filename){require_once $filename;}

use FlowrouteNumbersLib\Controllers\InboundRoutesController;
use FlowrouteNumbersLib\Controllers\PurchasablePhoneNumbersController;
Expand All @@ -16,9 +13,15 @@

print "Number Control Demo." . PHP_EOL;

//--- Purchasable Phone Numbers
// Create our controller
$pnc = new PurchasablePhoneNumbersController();
// Flowroute API Access Key and Secret Key
$access_key = '78675316';
$secret_key = 'i0WRu1eHXolvfTGv1RIIsrkRfVGJLn0Q';

// Create our controllers
$pnc = new PurchasablePhoneNumbersController($access_key, $secret_key);
$tnc = new TelephoneNumbersController($access_key, $secret_key);
$irc = new InboundRoutesController($access_key, $secret_key);


// Retrieve Available NPAs
print("--Retrieve Available NPAs\n");
Expand All @@ -27,87 +30,37 @@

// Retrieve Available NPA NXXs
print("--Retrieve Available NPA NXXs\n");
$response = $pnc->listAreaAndExchange();
print_r($response);
try {
$response = $pnc->listAreaAndExchange();
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}

// Search for purchasable Numbers
print("--Search for numbers in Seattle Washington\n");
$response = $pnc->search(10,206,641,null,'seattle','wa',null);
print_r($response);


//--- Telephone Numbers
// Create our controller
$tnc = new TelephoneNumbersController();

// Purchase a Phone Number
print("--Purchase a Phone Number\n");
$billing = new BillingMethod('METERED');

$number = '12066417661';

try {
$response = $tnc->purchase($billing, $number);
print_r($response);
$response = $pnc->search(10,206,641,null,'seattle','wa',null);
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}

// List Account Phone Numbers
print("--List Account Phone Numbers\n");
try {
$response = $tnc->listAccountTelephoneNumbers();
print_r($response);
$response = $tnc->listAccountTelephoneNumbers();
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}

// Retrieve Phone Number Details
print("--Retrieve Number Details\n");
try {
$response = $tnc->telephoneNumberDetails($number);
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}


//--- Inbound Routes
// Create our controller
$inbound = new InboundRoutesController();

// Retrieve Routes
print("--Retrieve Inbound Routes\n");
try {
$response = $inbound->mlist();
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}

// Create Route
print("--Create New Inbound Route\n");
try {
$routename = 'PSTNroute1';
$routetype = 'PSTN';
$routevalue = '12065551212';
$response = $inbound->createNewRoute($routename, $routetype, $routevalue);
print_r("New Inbound Route Successfully Created\n");
$response = $irc->mlist();
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}

//update routes
print("--Update TN's Primary and Failover Route\n");
try {
$rtes = '{"routes": [{"name": "PSTNroute1"}, {"name": "PSTNroute1"}]}';
$tn = "19515551212";
$response = $tnc->update($tn, $rtes);
print_r($response);
} catch(APIException $e) {
print("Error - " . strval($e->getResponseCode()) . ' ' . $e->getMessage() . PHP_EOL);
}




11 changes: 11 additions & 0 deletions src/FlowrouteNumbers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
require_once dirname(__FILE__) . '/FlowrouteNumbers/APIException.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/APIHelper.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Configuration.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/CustomAuthUtility.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Controllers/InboundRoutesController.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Controllers/PurchasablePhoneNumbersController.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Controllers/TelephoneNumbersController.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Models/BillingMethod.php';
require_once dirname(__FILE__) . '/FlowrouteNumbers/Models/Route.php';
?>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use FlowrouteNumbersLib\APIHelper;
use FlowrouteNumbersLib\Configuration;
use FlowrouteNumbersLib\CustomAuthUtility;
use Unirest\Unirest;

class InboundRoutesController {

Expand All @@ -34,8 +33,8 @@ class InboundRoutesController {
*/
function __construct($username=null, $password=null)
{
$this->username = $username ? $username : Configuration::$username;
$this->password = $password ? $password : Configuration::$password;
$this->username = $username;
$this->password = $password;
}

/**
Expand Down Expand Up @@ -72,7 +71,7 @@ public function mlist (

//append custom auth authorization headers
$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 401) {
Expand Down Expand Up @@ -126,7 +125,7 @@ public function createNewRoute (

//and invoke the API call request to fetch the response
$response = CustomAuthUtility::appendCustomAuthParams('PUT',
$queryUrl, $headers, $body);
$queryUrl, $headers, $body, $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand All @@ -144,4 +143,4 @@ public function createNewRoute (
return $response->body;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use FlowrouteNumbersLib\APIHelper;
use FlowrouteNumbersLib\Configuration;
use FlowrouteNumbersLib\CustomAuthUtility;
use Unirest\Unirest;

class PurchasablePhoneNumbersController {

Expand All @@ -34,8 +33,8 @@ class PurchasablePhoneNumbersController {
*/
function __construct($username=null, $password=null)
{
$this->username = $username ? $username : Configuration::$username;
$this->password = $password ? $password : Configuration::$password;
$this->username = $username;
$this->password = $password;
}

/**
Expand Down Expand Up @@ -74,7 +73,7 @@ public function listAreaAndExchange (
);

$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand Down Expand Up @@ -120,9 +119,8 @@ public function listAvailableNPAs (
'user-agent' => 'Flowroute SDK 1.0',
'Accept' => 'application/json'
);

$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand Down Expand Up @@ -188,7 +186,7 @@ public function search (
);

$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand All @@ -206,4 +204,4 @@ public function search (
return $response->body;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use FlowrouteNumbersLib\Configuration;
use FlowrouteNumbersLib\CustomAuthUtility;
use FlowrouteNumbersLib\Models\BillingMethod;
use Unirest\Unirest;

class TelephoneNumbersController {

Expand All @@ -35,8 +34,8 @@ class TelephoneNumbersController {
*/
function __construct($username=null, $password=null)
{
$this->username = $username ? $username : Configuration::$username;
$this->password = $password ? $password : Configuration::$password;
$this->username = $username;
$this->password = $password;
}

/**
Expand Down Expand Up @@ -68,7 +67,7 @@ public function telephoneNumberDetails (
);

$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand Down Expand Up @@ -118,7 +117,7 @@ public function purchase (
);

$response = CustomAuthUtility::appendCustomAuthParams('PUT',
$queryUrl, $headers, $billing->jsonSerialize());
$queryUrl, $headers, $billing->jsonSerialize(), $this->username, $this->password);

print_r($response);

Expand Down Expand Up @@ -174,7 +173,7 @@ public function listAccountTelephoneNumbers (
);

$response = CustomAuthUtility::appendCustomAuthParams('GET',
$queryUrl, $headers);
$queryUrl, $headers, '', $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand All @@ -194,14 +193,16 @@ public function listAccountTelephoneNumbers (

/**
* Updates the routing information for a telephone number on your account, as indicated by the specified URI. The body of the request requires two routes listed in order of preference (primary first and fail over second).
* @param string $number Required parameter: The telephone number who's routing you wish to update
* @param array $routes Required parameter: JSON string containing the The routes obtained from the routes resource that you would like to point your telephone number to.
* @param string $number Required parameter: The telephone number who's routing you wish to update
* @param string $primary_route Required parameter: Name of the preffered primary route
* @param string $secondary_route Required parameter: Name of the preffered failover route
* @return string response from the API call
* @throws APIException
**/
public function update (
$number,
$routes)
$primary_route,
$secondary_route)
{
//the base uri for api requests
$queryBuilder = Configuration::$BASEURI;
Expand All @@ -222,9 +223,11 @@ public function update (
'user-agent' => 'Flowroute SDK 1.0',
'content-type' => 'application/json; charset=utf-8'
);


$body = '{"routes": [{"name": "' . $primary_route . '"}, {"name": "' . $secondary_route . '"}]}';

$response = CustomAuthUtility::appendCustomAuthParams('PATCH',
$queryUrl, $headers, $routes);
$queryUrl, $headers, $body, $this->username, $this->password);

//Error handling using HTTP status codes
if ($response->code == 400) {
Expand All @@ -241,5 +244,4 @@ public function update (

return $response->body;
}

}
}
Loading