PHP code example of acrnogor / flowroute-sdk-v3-php

1. Go to this page and download the library: Download acrnogor/flowroute-sdk-v3-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acrnogor / flowroute-sdk-v3-php example snippets


function listE911s($client)
{
    $limit = 10;
    $offset = 0;
    $state = NULL;

    $return_list = array();
    // User the E911 Controller from our Client
    $controller = $client->getE911s();

    do
    {
        $e911_data = $controller->listE911s($limit, $offset, $state);
        // Iterate through each number item
        foreach ($e911_data as $entry)
        {
            foreach ($entry as $item) {
                echo "---------------------------\nE911 Records:\n";
                var_dump($item);
                $return_list[] = $item;
            }
        }

        // See if there is more data to process
        $links = $e911_data->links;
        if (isset($links->next))
        {
            // more data to pull
            $offset += $limit;
        }
        else
        {
            break;   // no more data
        }
    } while (true);

    return $return_list;
}

// List E911 Record Details
echo "--List detail information for an E911 Record\n";
$detail_id = $e911_list[0]->id;
$detail_record = $client->getE911s()->get_e911_details($detail_id);
var_dump($detail_record);

// Validate an E911 Address
echo "--Validate an E911 Address\n";

$body = new Models\E911Record();
$body->attributes->street_name = 'N Vassault';
$body->attributes->street_number = '3901';
$body->attributes->city = 'Tacoma';
$body->attributes->state = 'WA';
$body->attributes->country = 'US';
$body->attributes->zipcode = '98407';
$body->attributes->first_name = 'Dan';
$body->attributes->last_name = 'Smith';
$body->attributes->label = 'Home';

$result = $client->getE911s()->validate_address($body);
var_dump($result);

echo "--Create an E911 Address\n";
$result = $client->getE911s()->create_address($body);
var_dump($result);

$detail_id = $result->body->data->id;

// Update an E911 Address
echo "Update an E911 Address\n";
$body->attributes->label = 'Work';
$result = $client->getE911s()->update_address($body, $detail_id);
var_dump($result);

// Associate an E911 Address with a DID
echo "Associate an E911 Address with a DID\n";
$our_numbers = $client->getNumbers()->getAccountPhoneNumbers();
$did_id = $our_numbers->data[0]->id;
echo "Did id " . $did_id . "\n";
$result = $client->getE911s()->associate_did($did_id, $detail_id);
var_dump($result);

Un-associate an E911 Address from a DID
echo "Un-associate an E911 Address from a DID\n";
$result = $client->getE911s()->unassociate_did($did_id);
var_dump($result);

// Delete an E911 Address
echo "Delete an E911 Address\n";
$result = $client->getE911s()->delete_address($detail_id);
var_dump($result);

function GetCNAMs($client, $is_approved=False, $startsWith=NULL,
                  $endsWith=NULL, $contains=NULL, $limit=10, $offset=0)
{
    $return_list = array();
    // User the CNAM Controller from our Client
    $cnams = $client->getCNAMS();
    do
    {
        $cnam_data = $cnams->listCNAMs($limit, $offset, $is_approved,
                                       $startsWith, $contains, $endsWith);
        // Iterate through each number item
        foreach ($cnam_data as $entry)
        {
            foreach ($entry as $item) {
                echo "---------------------------\nCNAM Records:\n";
                var_dump($item);
                $return_list[] = $item;
            }
        }

        // See if there is more data to process
        $links = $cnam_data->links;
        if (isset($links->next))
        {
            // more data to pull
            $offset += $limit;
        }
        else
        {
            break;   // no more data
        }
    } while (true);

    return $return_list;
}

echo "Listing only Approved CNAM Records";
// List approved CNAM records
$our_cnams = GetCNAMs($client, True);

if (count($our_cnams) == 0)
{
    echo "No currently approved CNAM records. This is as far as the demo can run until you have some records ready for use.";
    exit();
}

// CNAM Details
echo "List CNAM Details " . $our_cnams[0]->id . "\n";
$result = $client->getCNAMS()->getCNAMdetails($our_cnams[0]->id);
var_dump($result);

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

// Create a CNAM Record
$cnam_value = 'Flowroute' . generateRandomString(4);
$new_record = $client->getCNAMS()->createCNAM($cnam_value);
var_dump($new_record);

$cnam_value = $our_cnams[0]->attributes->value;
$cnam_id =  $our_cnams[0]->id;
echo "CNAM ID " . $cnam_id . "\n";
echo "DID ID " . $did . "\n";
$result = $client->getCNAMS()->associateCNAM($cnam_id, $did);
var_dump($result);

wait_for_user("New Record Associated");

// Un-associate the new CNAM Record from our DID
$did = $ourDIDs[0]->id;
$result = $client->getCNAMS()->unassociateCNAM($did);
var_dump($result);

// Delete the CNAM Record used
$result = $client->getCNAMS()->deleteCNAM($cnam_id);
var_dump($result);