Sample SDKs

cURL SDK

The following files are provided as part of a sample SDK that takes advantage of the rXg RESTful API. These shell scripts may be executed on any administrator device that has BASH and cURL installed on it.

00_get_account_id.sh
00_get_bandwidth_queue_id.sh
00_get_device_id.sh
00_get_plan_id.sh
00_get_quota_trigger_id.sh
00_get_time_plan_id.sh
00_set_globals.sh
00_urlencode.sed
00_xml_extract_integer.sh
01_create_account.sh
02_show_account_json.sh
02_show_account_xml.sh
02_show_device_usage.sh
02_show_pfqueuelogs_for_mac.sh
03_reset_total_utilization_counters.sh
03_update_account.sh
04_add_device_to_account.sh
04_remove_device.sh
05_suspend_account.sh
05_unsuspend_account.sh
06_delete_account.sh
07_change_bandwidth_queue.sh
07_change_quota_trigger.sh
07_change_time_plan_price.sh
Rxg_Curl_Class.php

The scripts with the 00 prefix are called from the other scripts. Make sure that all of the scripts with the 00prefix are accessible and executable before attempting to run any of the other scripts.

The 00_set_globals.sh script must be edited so that the global variables reflect the target rXg. The RXG_NAME must be set to the DNS name of the rXg that is being accessed via the RESTful API. Furthermore the RXG_API_KEY must be changed to reflect an API key that has been obtained from the administrative console.

The scripts in this SDK may be used as provided to integrate a remote portal mechanism. A remote portal application must be able to grant access to certain end-users and devices. To accomplish this the remote server would execute the 01_create_account.shscript to create an account and then run the04_add_device_to_account.sh to add the end-user device to the account.

To utilize this pattern the operator must setup Account Groups, Policies and Usage Plans for the various tiers of service. Automatic login should be enabled in the Usage Plans that are to be used with this mechanism. In the example below the operator wishes to authorize the MAC address 00:01:af:cc:38:4f to have access via a Usage Plan named Basic. Most operators choose to use the MAC address as the Account login if only a single device per Account is desired. For example:

./01_create_account.sh -a 00:01:af:cc:38:4f -p Basic

./04_add_device_to_account.sh 00:01:af:cc:38:4f 00:01:af:cc:38:4f

Changing the provisioned Usage Plan for an Account may be accomplished by running the 03_update_account.sh script. Following the above example, we would do the following if the end-user upgrades to the Premium plan:

./03_update_account.sh -a 00:01:af:cc:38:4f -p Premium

Suspending an Account for any reason (e.g., payment processing failure) is easily accomplished by using the 05_suspend_account.shscript. Following the above example:

./05_suspend_account.sh 00:01:af:cc:38:4f

Unsuspending the Account is just as easy: ./05_unsuspend_account.sh 00:01:af:cc:38:4f

The operator has numerous choices on how to instrument the data transfer consumed by an Account or Device. Use the02_show_device_usage.sh script to retrieve a simple account utilization total for a device over a period of time. For example:

./02_show_device_usage.sh 01:50:56:00:00:99 '2014-03-21 00:00:00' '2014-03-22 23:59:59'

More detailed usage information may be acquired by looking at the PF Queue Logs and the PF Connection Logs. The PF Queue Logs are stored in decreasing resolution over time. Samples are stored every 30 seconds for an hour and then reduced to once an hour for a week and finally once a day after a week has passed. The entries in PF Connection Logs are different from the PF Queue Logs in that they also contain the IP addresses of the destinations.

If multiple Devices are associated with a single Account then their total utilization is stored in the Device object. The mb_up,mb_down, pkts_up and pkts_downfields reflect the utilization of all Devices associated with the Account. The 02_show_account_xml.sh retrieves all fields including the four total utilization fields. Use the 03_reset_total_utilization_counters.sh script to reset the total utilization counters to zero at any time.

PHP SDK

Download the PHP SDK. Save it into your PHP project directory and require_once to include the library into your application.

Note: Use of this library requires that the PHP cURL extension be enabled in your php.ini file. Edit the file and uncomment the following line (remove the ; from the beginning of the line):

;extension=php_curl.dll

Examples

<?php

  require_once("Rxg_Curl_Class.php");

  # Initialize a new instance of the Rxg_Curl_Class
  $rxg = new Rxg_Curl_Class("hostname.domain.com", "apikey");

  # Create a record
  $result = $rxg->create("admins",
    array(
      "login" => "operator",
      "password" => '$uperP@ssword',
      "password_confirmation" => '$uperP@ssword',
      "admin_role" => 1
    )
  );
  var_dump($result);

  # Retrieve a record
  $result = $rxg->show("wan_targets", 1);
  var_dump($result);

  # List all records
  $result = $rxg->search("accounts");
  var_dump($result);

  # List records filtered by search params
  $result = $rxg->search("accounts", array('first_name' => 'Romeo'));
  var_dump($result);

  # Update a record
  $result = $rxg->update("accounts", 43, array("first_name" => 'George'));
  var_dump($result);

  # Delete a record
  $result = $rxg->delete("accounts", 41);
  var_dump($result);

?>

Cookies help us deliver our services. By using our services, you agree to our use of cookies.