Skip to content

Instantly share code, notes, and snippets.

@coryjthompson
Created January 20, 2016 17:19
Show Gist options
  • Save coryjthompson/a13190bc3887bb5f6ae9 to your computer and use it in GitHub Desktop.
Save coryjthompson/a13190bc3887bb5f6ae9 to your computer and use it in GitHub Desktop.
Implements the WebinarJam API.
<?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;
}
}
@neerav
Copy link

neerav commented Feb 2, 2018

A little update to keep it working with latest api:

1) Change in API URL (line 10)

    public static $API_URL = 'https://webinarjam.genndi.com/api/';

2) Change in addToWebinar function (line 32 to 46)

    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);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment