Created
January 20, 2016 17:19
-
-
Save coryjthompson/a13190bc3887bb5f6ae9 to your computer and use it in GitHub Desktop.
Implements the WebinarJam API.
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://s3.amazonaws.com/webinarjam/files/WebinarJamAPI.pdf | |
*/ | |
class WebinarJam { | |
public static $API_URL = 'https://app.webinarjam.com/api/v2/'; | |
public static $CURL_OPTIONS = array( | |
CURLOPT_CONNECTTIMEOUT => 10, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_TIMEOUT => 60, | |
); | |
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, $name, $email, $schedule, $ipAddress=null, $countryCode=null, $phone=null) { | |
$params = ['webinarId' => $webinarId, 'name' => $name, 'email' => $email, 'schedule' => $schedule]; | |
if ($ipAddress != null) { | |
$params['ip_address'] = $ipAddress; | |
} | |
if($countryCode != null) { | |
$params['country_code'] = $countryCode; | |
} | |
if($countryCode != null) { | |
$params['phone'] = $phone; | |
} | |
} | |
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
A little update to keep it working with latest api:
1) Change in API URL (line 10)
2) Change in addToWebinar function (line 32 to 46)