/** * Get Visible IP by querying freepbx.org * @return array Status of result */ public function getVisibleIP() { $ip = false; try { $pest = new \PestXML("http://myip.freepbx.org:5060"); $thing = $pest->get('/whatismyip.php'); } catch (\Exception $e) { return false; } if (!empty($thing->ipaddress) && filter_var((string) $thing->ipaddress, FILTER_VALIDATE_IP)) { return (string) $thing->ipaddress; } else { return false; } }
/** * Get Visible IP by querying freepbx.org * @return array Status of result */ public function getVisibleIP() { $ip = false; try { $pest = new \PestXML("http://myip.freepbx.org:5060"); $thing = $pest->get('/whatismyip.php'); } catch (\Exception $e) { return array("status" => false, "message" => $e->getMessage()); } if (!empty($thing->ipaddress) && filter_var((string) $thing->ipaddress, FILTER_VALIDATE_IP)) { return array("status" => true, "address" => (string) $thing->ipaddress); } else { return array("status" => false, "message" => _("Unknown Error")); } }
<?php /** * These PestXML usage examples were written for the Rollcall REST service * (see https://github.com/educoder/rollcall) **/ require_once '../PestXML.php'; $pest = new PestXML('http://localhost:3000'); // Retrieve and iterate over the list of all Users $users = $pest->get('/users.xml'); foreach ($users->user as $user) { echo $user->{'display-name'} . " (" . $user->username . ")\n"; } echo "\n"; // Create a new User $data = array('user' => array('username' => "jcricket", 'password' => "pinocchio", 'display_name' => "Jiminy Cricket", 'kind' => "Student")); $user = $pest->post('/users.xml', $data); echo "New User's ID: " . $user->id . "\n"; echo "\n"; // Update the newly created User's attributes $data = array('user' => array('kind' => "Instructor", 'metadata' => array('gender' => 'male', 'age' => 30))); $pest->put('/users/' . $user->id . '.xml', $data); // Retrieve the User $user = $pest->get('/users/' . $user->id . '.xml'); echo "User XML: \n"; echo $user->asXML(); echo "\n"; echo "Name: " . $user->{'display-name'} . "\n"; echo "Kind: " . $user->kind . "\n"; echo "Age: " . $user->metadata->age . "\n"; echo "\n";
<?php /** * This example requires the Pest REST client. * See https://github.com/educoder/pest **/ // This mkes things easier in my local dev environment... you can ignore this line // or change it to something useful for yourself set_include_path(get_include_path() . PATH_SEPARATOR . '../../../'); require 'Pest/PestXML.php'; // The base rollcall URL (don't include the trailing "/" slash) $rollcall_site_url = "http://localhost:3000"; $pest = new PestXML($rollcall_site_url); /** FETCH MULTIPLE RESOURCES IN A COLLECTION **/ // Fetch all Users $users = $pest->get('/users.xml'); // Print the display name and login for each User returned. foreach ($users->user as $user) { echo $user->{'display-name'} . " (" . $user->login . ")\n"; } // Fetch all Groups $groups = $pest->get('/groups.xml'); // Fetch all of the Groups that a specific user belongs to $groups = $pest->get('/users/15/groups.xml'); /** FETCH A SPECIFIC RESOURCE **/ // Get the ID of the first User in the set returned above $id = $users->user[0]->id; // Fetch the User resource its ID $user = $pest->get('/users/' . $id . '.xml'); echo $user->{'display-name'} . " (" . $user->login . ")\n"; // You can also fetch a User by their login
<?php /** * This PestXML usage example pulls data from the OpenStreetMap API. * (see http://wiki.openstreetmap.org/wiki/API_v0.6) **/ require_once '../PestXML.php'; $pest = new PestXML('http://api.openstreetmap.org/api/0.6'); // Retrieve map data for the University of Toronto campus $map = $pest->get('/map?bbox=-79.39997,43.65827,-79.39344,43.66903'); // Print all of the street names in the map $streets = $map->xpath('//way/tag[@k="name"]'); foreach ($streets as $s) { echo $s['v'] . "\n"; }