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
require the RxgPhpClient.php file into your project and initialize an instance.
require_once("RxgPhpClient.php");
# Initialize a new instance of the Rxg_Curl_Class
$rxg = new Rxg_Php_Client("hostname.domain.com", "apikey");
API methods take as their first parameter the scaffold name that you wish to query.
If you are unsure, hover over a hyperlink in the rXg's admin console and look at the URL.
The scaffold name is listed after "scaffolds" such as https://rxg.domain.com/admin/scaffolds/{admins}
- param1: scaffold (string)
- param2: record attributes (array)
$result = $rxg->create("admins",
array(
"login" => "operator",
"password" => '$uperP@ssword',
"password_confirmation" => '$uperP@ssword',
"admin_role" => 1
)
);
- param1: scaffold (string)
- param2: record_id (integer)
$result = $rxg->show("wan_targets", 1);
- param1: scaffold (string)
- param2: search filter (array - optional)
$result = $rxg->search("accounts");
- param1: scaffold (string)
- param2: search filter (array - optional)
$result = $rxg->search("accounts", array('first_name' => 'Romeo'));
- param1: scaffold (string)
- param2: record_id (integer)
- param2: updated attributes (array)
$result = $rxg->update("accounts", 43, array("first_name" => 'George'));
- param1: scaffold (string)
- param2: record_id (integer)
$result = $rxg->delete("accounts", 41);
Wrap API calls in try/catch blocks to catch Rxg_Exception
.
The response code and message are available as methods of the exception object.
try {
$result = $rxg->create("accounts",
array(
"login" => "jsmith",
"password" => 'a',
"password_confirmation" => 'a'
)
);
print_r($result);
} catch (Rxg_Exception $e) {
print $e->getCode() + "<br>";
print $e->getMessage();
}
=> 422
=> {"email":["can't be blank","is too short (minimum is 3 characters)","is invalid"],"first_name":["can't be blank","is too short (minimum is 1 character)"],"last_name":["can't be blank","is too short (minimum is 1 character)"]}