-
-
Save neerav/843a7599ffa5d5d4e8a36b29b233573b to your computer and use it in GitHub Desktop.
WebinarJam API Class written in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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