class ZoomAPI in Zoom API 7
Zoom API Base Class.
Hierarchy
- class \ZoomAPI
Expanded class hierarchy of ZoomAPI
File
- includes/
zoomapi.classes.inc, line 11 - Base class for the Zoom API.
View source
class ZoomAPI {
/**
* API Key.
*
* @var string
*/
private $apiKey;
/**
* API Secret.
*
* @var string
*/
private $apiSecret;
/**
* API URL.
*
* @var string
*/
private $apiUrl;
/**
* Class constructor.
*/
public function __construct() {
$this->apiKey = variable_get('zoomapi_key', FALSE);
$this->apiSecret = variable_get('zoomapi_secret', FALSE);
$this->apiUrl = 'https://' . trim(variable_get('zoomapi_url', 'api.zoom.us/v1'), '/') . '/';
}
/**
* Send Request.
*/
protected function sendRequest($endpoint, $data = []) {
if (variable_get('zoomapi_debug', FALSE)) {
watchdog('zoomapi_debug', 'Request: @endpoint => !data', [
'@endpoint' => $endpoint,
'!data' => '<pre>' . print_r($data, TRUE) . '</pre>',
], WATCHDOG_DEBUG);
}
$request_url = $this->apiUrl . $endpoint;
$data['api_key'] = $this->apiKey;
$data['api_secret'] = $this->apiSecret;
$data['data_type'] = 'JSON';
drupal_alter('zoomapi_sendrequest', $request_url, $data);
$post_fields = drupal_http_build_query($data);
// Allow a site to disable sending requests for debug / development
// purposes. This may be useful because Zoom does not currently support prod
// vs test environments.
if (variable_get('zoomapi_sendrequests_enabled', TRUE)) {
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
} catch (Exception $e) {
watchdog('zoomapi', 'An error occurred making a call to !endpoint with data !data. Exception: @exception.', [
'!endpoint' => $endpoint,
'!data' => '<pre>' . print_r($data, TRUE) . '</pre>',
'@exception' => $e
->getMessage(),
], WATCHDOG_ERROR);
return [];
}
$response = drupal_json_decode($response);
if (variable_get('zoomapi_debug', FALSE)) {
watchdog('zoomapi_debug', 'Response: @endpoint => !response', [
'@endpoint' => $endpoint,
'!response' => '<pre>' . print_r($response, TRUE) . '</pre>',
], WATCHDOG_DEBUG);
}
if (isset($response['error'])) {
watchdog('zoomapi', 'An error occurred making a call to !endpoint with data !data. Error code: @code. Message: @message', [
'!endpoint' => $endpoint,
'!data' => '<pre>' . print_r($data, TRUE) . '</pre>',
'@code' => $response['error']['code'],
'@message' => $response['error']['message'],
], WATCHDOG_ERROR);
return [];
}
}
else {
$response = [
'error' => [
'code' => 0,
'message' => t('This site has disabled the zoomapi_sendrequests_enabled variable.'),
],
];
}
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ZoomAPI:: |
private | property | API Key. | |
ZoomAPI:: |
private | property | API Secret. | |
ZoomAPI:: |
private | property | API URL. | |
ZoomAPI:: |
protected | function | Send Request. | |
ZoomAPI:: |
public | function | Class constructor. |