Skip to content

Instantly share code, notes, and snippets.

@neerav
Forked from coryjthompson/WebinarJam.php
Last active February 2, 2018 18:57
Show Gist options
  • Save neerav/843a7599ffa5d5d4e8a36b29b233573b to your computer and use it in GitHub Desktop.
Save neerav/843a7599ffa5d5d4e8a36b29b233573b to your computer and use it in GitHub Desktop.
WebinarJam API Class written in PHP
<?php
/**
* Class WebinarJam
* Implements the WebinarJam API as documented
* https://d3kcv4e58tsh6h.cloudfront.net/api/WebinarJamAPI.pdf
* Created Date : 03/02/2018
*/
class WebinarJam {
public static $API_URL = 'https://webinarjam.genndi.com/api/';
public static $CURL_OPTIONS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_SSL_VERIFYPEER => false,
);
private $_apiKey;
public function __construct($apiKey) {
$this->_apiKey = $apiKey;
}
public function getWebinars() {
return $this->authenticatedCall('webinars');
}
public function getWebinar($webinarId) {
return $this->authenticatedCall('webinar', ['webinar_id' => $webinarId]);
}
public function addToWebinar($webinarId, $first_name, $email, $schedule, $last_name=null, $ipAddress=null, $countryCode=null, $phone=null) {
$params = ['webinar_id' => $webinarId, 'first_name' => $first_name, 'email' => $email, 'schedule' => $schedule];
if ($last_name != null) {
$params['last_name'] = $last_name;
}
if ($ipAddress != null) {
$params['ip_address'] = $ipAddress;
}
if($countryCode != null) {
$params['phone_country_code'] = $countryCode;
}
if($phone != null) {
$params['phone'] = $phone;
}
return $this->authenticatedCall('register', $params);
}
private function authenticatedCall($url, $params = array()) {
$ch = curl_init(self::$API_URL . $url);
$opts = self::$CURL_OPTIONS;
if(empty($this->_apiKey)) {
throw new Exception('Must specify valid API key');
}
$params['api_key'] = $this->_apiKey;
curl_setopt_array($ch, $opts);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
if ($result === false) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception($error);
}
curl_close($ch);
$isReturnArray = true;
$jsonResults = json_decode($result, $isReturnArray);
if(!is_array($jsonResults)) {
throw new Exception($result);
}
return $jsonResults;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment