Skip to content

Instantly share code, notes, and snippets.

@urlsangel
Last active December 17, 2015 03:59
Show Gist options
  • Save urlsangel/5547522 to your computer and use it in GitHub Desktop.
Save urlsangel/5547522 to your computer and use it in GitHub Desktop.
Citrix API Helper - some functionality to call the API, and a speicalised webinar call to get webinars, optionally filtered by keyword and optionally limited to a max number to return.
// create a webinar interface
$interface = new WebinarInterface();
// get the webinar data, pass filter and limit (null if not required)
$data = $interface->getWebinars('aCloud', 3);
<?php
/**
* Webinar interface
*
* @author Russell Kirkland, fffunction
*
* Interface with the Citrix API
*/
class WebinarInterface
{
// Access Token - will expire on 16.4.2014
private $organizer_key = 'xxxxxxxxxxxxxxxxxx';
private $access_token = 'xxxxxxxxxxxxxxxxx';
// get webinars
public function getWebinars($filter = null, $limit = null)
{
$webinars = null;
$filtered_webinars = null;
$url = 'https://api.citrixonline.com/G2W/rest/organizers/' . $this->organizer_key . '/upcomingWebinars';
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Authorization: OAuth oauth_token=' . $this->access_token
);
// get the data, catch exceptions if thrown
try {
$webinars = $this->callAPI($url, $headers);
}
catch (Exception $e) {
error_log('Caught exception: ' . $e->getMessage() . "\n");
return null;
}
// filter the data if filter passed
if ($filter)
{
foreach ($webinars as $webinar) {
if (stripos($webinar['subject'], $filter) !== false) {
$filtered_webinars[] = $webinar;
}
}
}
else $filtered_webinars = $webinars;
// limit if limit required
if ($limit) $filtered_webinars = array_slice($filtered_webinars, 0, $limit);
// return the data
return $filtered_webinars;
}
// call the API
private function callAPI($Url, $headers)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
// Fetch and return content, save it.
$raw_data = curl_exec($ch);
curl_close($ch);
// If the API is JSON, use json_decode.
$data = json_decode($raw_data, true);
// handle invalid data
if (isset($data['int_err_code'])) throw new Exception($data['msg']);
if (isset($data['incident'])) throw new Exception($data['description']);
// return the data
return($data);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment