diff --git a/API/examples/PHP/ClickMeetingRestClient.php b/API/examples/PHP/ClickMeetingRestClient.php index 744cd4c..6343ed3 100644 --- a/API/examples/PHP/ClickMeetingRestClient.php +++ b/API/examples/PHP/ClickMeetingRestClient.php @@ -1,7 +1,9 @@ 'gzip,deflate', + CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 8 - ); + ]; /** * Error codes @@ -49,7 +53,7 @@ class ClickMeetingRestClient /** * Allowed formats - * @var unknown + * @var array */ protected $formats = array('json', 'xml', 'js', 'printr'); @@ -58,10 +62,9 @@ class ClickMeetingRestClient * @param array $params * @throws Exception */ - public function __construct(array $params) + public function __construct(array $params = null) { - if (false === extension_loaded('curl')) - { + if (false === extension_loaded('curl')) { throw new Exception('The curl extension must be loaded for using this class!'); } @@ -70,16 +73,16 @@ public function __construct(array $params) $this->format = isset($params['format']) && in_array(strtolower($params['format']), $this->formats) ? strtolower($params['format']) : $this->format; } - /** * Get response + * * @param string $method * @param string $path * @param array $params * @param bool $format_response * @param bool $is_upload_file - * @throws Exception * @return string|array + * @throws Exception */ protected function sendRequest($method, $path, $params = null, $format_response = true, $is_upload_file = false) { @@ -87,13 +90,13 @@ protected function sendRequest($method, $path, $params = null, $format_response $curl = curl_init(); // set URL - curl_setopt($curl, CURLOPT_URL, $this->url.$path.'.'.(isset($this->format) ? $this->format : 'json')); + curl_setopt($curl, CURLOPT_URL, $this->url . $path . '.' . (isset($this->format) ? $this->format : 'json')); + // set api key - $headers = array( 'X-Api-Key:' . $this->api_key); + $headers = array('X-Api-Key:' . $this->api_key); // is uplaoded file - if (true == $is_upload_file) - { + if (true == $is_upload_file) { $headers[] = 'Content-type: multipart/form-data'; } @@ -106,8 +109,7 @@ protected function sendRequest($method, $path, $params = null, $format_response $headers[] = 'Expect:'; break; case 'PUT': - if(empty($params)) - { + if (empty($params)) { $headers[] = 'Content-Length: 0'; } curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); @@ -119,13 +121,10 @@ protected function sendRequest($method, $path, $params = null, $format_response curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // add params - if (!empty($params)) - { + if (!empty($params)) { curl_setopt($curl, CURLOPT_POSTFIELDS, $is_upload_file ? $params : http_build_query($params)); } - curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt_array($curl, $this->curl_options); // send the request @@ -133,54 +132,59 @@ protected function sendRequest($method, $path, $params = null, $format_response $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - if (isset($this->http_errors[$http_code])) - { + if (isset($this->http_errors[$http_code])) { throw new Exception($response, $http_code); - } - elseif (!in_array($http_code, array(200,201))) - { + } elseif (!in_array($http_code, array(200, 201))) { throw new Exception('Response status code: ' . $http_code); } // check for curl error - if (0 < curl_errno($curl)) - { - throw new Exception('Unable to connect to '.$this->url . ' Error: ' . curl_error($curl)); + if (0 < curl_errno($curl)) { + throw new Exception('Unable to connect to ' . $this->url . ' Error: ' . curl_error($curl)); } // close the connection curl_close($curl); // check return format - if (!isset($this->format) && true == $format_response) - { + if (!isset($this->format) && true == $format_response) { $response = json_decode($response); } + return $response; } /** * Get conferences + * * @param string $status * @param int $page + * @return mixed + * @throws Exception */ public function conferences($status = 'active', $page = 1) { - return $this->sendRequest('GET', 'conferences/'.$status . '?page=' . $page); + return $this->sendRequest('GET', 'conferences/' . $status . '?page=' . $page); } /** * Get conference - * @param unknown $room_id + * + * @param string $room_id + * @return mixed + * @throws Exception */ public function conference($room_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id); + return $this->sendRequest('GET', 'conferences/' . $room_id); } /** * Add conference + * * @param array $params + * @return mixed + * @throws Exception */ public function addConference(array $params) { @@ -189,51 +193,61 @@ public function addConference(array $params) /** * Edit conference + * * @param int $room_id * @param array $params + * @return mixed + * @throws Exception */ public function editConference($room_id, array $params) { - return $this->sendRequest('PUT', 'conferences/'.$room_id, $params); + return $this->sendRequest('PUT', 'conferences/' . $room_id, $params); } /** * Delete conference + * * @param int $room_id + * @return mixed + * @throws Exception */ public function deleteConference($room_id) { - return $this->sendRequest('DELETE', 'conferences/'.$room_id); + return $this->sendRequest('DELETE', 'conferences/' . $room_id); } /** * Conference autologin hash - * @param unknown $room_id + * + * @param string $room_id * @param array $params + * @return mixed + * @throws Exception */ public function conferenceAutologinHash($room_id, array $params) { - return $this->sendRequest('POST', 'conferences/'.$room_id.'/room/autologin_hash', $params); + return $this->sendRequest('POST', 'conferences/' . $room_id . '/room/autologin_hash', $params); } /** * Send invitation mail + * * @param int $room_id * @param string $lang * @param array $params - * @return Ambigous + * @return mixed + * @throws Exception */ - public function sendConferenceEmailInvitations($room_id, $lang = 'en', $params) + public function sendConferenceEmailInvitations($room_id, $params, $lang = 'en') { - return $this->sendRequest('POST', 'conferences/'.$room_id.'/invitation/email/'.$lang, $params); + return $this->sendRequest('POST', 'conferences/' . $room_id . '/invitation/email/' . $lang, $params); } /** * Conference skins - * @param int $room_id - * @param string $lang - * @param array $params - * @return Ambigous + * + * @return mixed + * @throws Exception */ public function conferenceSkins() { @@ -242,66 +256,87 @@ public function conferenceSkins() /** * Conference generate tokens + * * @param int $room_id * @param array $params + * @return mixed + * @throws Exception */ public function generateConferenceTokens($room_id, array $params) { - return $this->sendRequest('POST', 'conferences/'.$room_id.'/tokens', $params); + return $this->sendRequest('POST', 'conferences/' . $room_id . '/tokens', $params); } /** * Get coference tokens + * * @param int $room_id + * @return mixed + * @throws Exception */ public function conferenceTokens($room_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/tokens'); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/tokens'); } /** * Get conference sessions - * @param unknown $room_id + * + * @param string $room_id + * @return mixed + * @throws Exception */ public function conferenceSessions($room_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/sessions'); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/sessions'); } /** * Get conference session + * * @param int $room_id * @param int $session_id + * @return mixed + * @throws Exception */ public function conferenceSession($room_id, $session_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/sessions/'.$session_id); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/sessions/' . $session_id); } /** * Get conference session attendees + * * @param int $room_id * @param int $session_id + * @return mixed + * @throws Exception */ public function conferenceSessionAttendees($room_id, $session_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/sessions/'.$session_id.'/attendees'); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/sessions/' . $session_id . '/attendees'); } /** * Generate pdf report + * * @param int $room_id * @param int $session_id * @param string $lang + * @return mixed + * @throws Exception */ public function generateConferenceSessionPDF($room_id, $session_id, $lang = 'en') { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/sessions/'.$session_id.'/generate-pdf/'.$lang); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/sessions/' . $session_id . '/generate-pdf/' . $lang); } /** * Add new contact + * * @param array $params + * @return mixed + * @throws Exception */ public function addContact($params) { @@ -310,6 +345,9 @@ public function addContact($params) /** * Get timezone list + * + * @return mixed + * @throws Exception */ public function timeZoneList() { @@ -318,15 +356,21 @@ public function timeZoneList() /** * Get timezone by country + * * @param string $country + * @return mixed + * @throws Exception */ public function countryTimeZoneList($country) { - return $this->sendRequest('GET', 'time_zone_list/'.$country); + return $this->sendRequest('GET', 'time_zone_list/' . $country); } /** * Get phone gateways + * + * @return mixed + * @throws Exception */ public function phoneGatewayList() { @@ -335,37 +379,49 @@ public function phoneGatewayList() /** * Add conference registration + * * @param int $room_id * @param array $params + * @return mixed + * @throws Exception */ public function addConferenceRegistration($room_id, $params) { - return $this->sendRequest('POST', 'conferences/'.$room_id.'/registration', $params); + return $this->sendRequest('POST', 'conferences/' . $room_id . '/registration', $params); } /** * Get conference registrants + * * @param int $room_id * @param string $status + * @return mixed + * @throws Exception */ public function conferenceRegistrations($room_id, $status) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/registrations/'.$status); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/registrations/' . $status); } /** - * Get conference session registants + * Get conference session registrants + * * @param int $room_id * @param int $session_id * @param string $status + * @return mixed + * @throws Exception */ public function conferenceSessionRegistrations($room_id, $session_id, $status) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/sessions'.$session_id.'/registrations/'.$status); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/sessions' . $session_id . '/registrations/' . $status); } /** * Get files from library + * + * @return mixed + * @throws Exception */ public function fileLibrary() { @@ -373,80 +429,107 @@ public function fileLibrary() } /** - * Get coference file library + * Get conference file library + * * @param int $room_id + * @return mixed + * @throws Exception */ public function conferenceFileLibrary($room_id) { - return $this->sendRequest('GET', 'file-library/conferences/'.$room_id); + return $this->sendRequest('GET', 'file-library/conferences/' . $room_id); } /** * Get file details + * * @param int $file_id + * @return mixed + * @throws Exception */ public function fileLibraryFile($file_id) { - return $this->sendRequest('GET', 'file-library/'.$file_id); + return $this->sendRequest('GET', 'file-library/' . $file_id); } /** * Add file to library + * * @param string $file_path + * @return mixed + * @throws Exception */ public function addFileLibraryFile($file_path) { - return $this->sendRequest('POST', 'file-library', array('uploaded' => '@'.$file_path), true, true); + return $this->sendRequest('POST', 'file-library', array('uploaded' => '@' . $file_path), true, true); } /** * Download file + * * @param int $file_id + * @return mixed + * @throws Exception */ public function fileLibraryContent($file_id) { - return $this->sendRequest('GET', 'file-library/'.$file_id.'/download', null, false); + return $this->sendRequest('GET', 'file-library/' . $file_id . '/download', null, false); } /** * Delete file + * * @param int $file_id + * @return mixed + * @throws Exception */ public function deleteFileLibraryFile($file_id) { - return $this->sendRequest('DELETE', 'file-library/'.$file_id); + return $this->sendRequest('DELETE', 'file-library/' . $file_id); } /** * Get conference recordings + * * @param int $room_id + * @return mixed + * @throws Exception */ public function conferenceRecordings($room_id) { - return $this->sendRequest('GET', 'conferences/'.$room_id.'/recordings'); + return $this->sendRequest('GET', 'conferences/' . $room_id . '/recordings'); } /** * Delete conference recordings + * * @param int $room_id + * @return mixed + * @throws Exception */ public function deleteConferenceRecordings($room_id) { - return $this->sendRequest('DELETE', 'conferences/'.$room_id.'/recordings'); + return $this->sendRequest('DELETE', 'conferences/' . $room_id . '/recordings'); } /** * Delete conference recording + * * @param int $room_id * @param int $recording_id + * @return mixed + * @throws Exception */ public function deleteConferenceRecording($room_id, $recording_id) { - return $this->sendRequest('DELETE', 'conferences/'.$room_id.'/recordings/'.$recording_id); + return $this->sendRequest('DELETE', 'conferences/' . $room_id . '/recordings/' . $recording_id); } /** * Get chats + * + * @return mixed + * @throws Exception */ public function chats() { @@ -455,10 +538,13 @@ public function chats() /** * Get chat record + * * @param int $session_id + * @return mixed + * @throws Exception */ public function conferenceSessionChats($session_id) { - return $this->sendRequest('GET', 'chats/'.$session_id, null, false); + return $this->sendRequest('GET', 'chats/' . $session_id, null, false); } -} +} \ No newline at end of file