<?php
/**
* File: archive-meetings.php
* Purpose: Download all the meetings for a set of rooms
*/
CONST APIKEY = 'YOUR-KEY-HERE';
CONST APIURL = 'https://SITE.lucidmeetings.com/lucid/api/v1/';
// This is the only thing you should need to set:
// e.g., $room_ids = array(12345, 12346);
$room_ids = array();
/**
* Callback function to extract headers from the CURL response.
*/
$curl_headers = array();
function header_line($curl, $header_line) {
global $curl_headers;
$curl_headers[] = $header_line;
return strlen($header_line);
}
/**
* Function to prepare and execute an API call via CURL.
*/
function send_request($uri, $method='GET', $params=NULL, $data=NULL) {
global $curl_headers;
// Minor sanitizing on the method param
$method = strtoupper($method);
$headers = array('Content-Type: application/json', 'X-API-KEY: ' . APIKEY);
$curl_headers = array();
// Build the API request string
$request = APIURL . $uri . ($params ? '?' . http_build_query($params) : '');
$result = NULL;
// Build the request/response container
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'header_line');
switch ($method) {
case 'GET':
curl_setopt($ch, CURLOPT_POST, FALSE);
break;
case 'POST':
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case 'PUT':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
break;
default:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}
// Do the request
$result = new StdClass();
$result->response = curl_exec($ch);
$result->code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result->meta = curl_getinfo($ch);
// Check for errors
$curl_error = ($result->code > 0 ? NULL : curl_error($ch) . ' (' . curl_errno($ch) . ')');
curl_close($ch);
if ($curl_error) {
print $curl_error;
exit;
}
return $result;
}
/**
* For each room_id, export and save the meetings.
*/
date_default_timezone_set('America/Los_Angeles');
foreach ($room_ids as $room_id) {
// URI path to retrieve meetings and the local mirror path
$path = 'rooms/' . $room_id . '/meetings';
@mkdir($path, 0775, TRUE);
print $path . "\n";
// Get the meetings in each of the rooms
$params = array('fields' => 'meeting_id,name,start_time', 'timeframe' => 'past', 'per_page' => 1000);
$result = send_request($path, 'GET', $params);
// Decode the JSON response
$data = json_decode($result->response, TRUE);
// Walk through the meetings list returned for this room
foreach ($data as $meeting) {
print 'Getting ' . $meeting['name'] . '... ';
//////////////////////////////////////////////////////////////////////
// Request a meeting export
//////////////////////////////////////////////////////////////////////
$params = array('format' => 'pdf');
$result = send_request('meetings/' . $meeting['meeting_id'], 'GET', $params);
// Check for rate limiting
while ($result->code == 429) {
print 'wait 15s... ';
sleep(15);
$result = send_request('meetings/' . $meeting['meeting_id'], 'GET', $params);
}
// Get the filename from the Content-Type header
$filename = NULL;
foreach ($curl_headers as $header) {
if (strstr($header, 'filename=')) {
list(, $filename) = explode('filename=', $header);
$filename = preg_replace('/\s+/', '_', trim($filename, " \t\n\r\0\x0B\"\'"));
break;
}
}
// Save the file
if ($filename) {
$directory = './' . $path . '/' . date('Ym', $meeting['start_time']['value']);
@mkdir($directory);
file_put_contents($directory . '/' . $filename, $result->response);
}
//////////////////////////////////////////////////////////////////////
// Request an attendance export
//////////////////////////////////////////////////////////////////////
$params = array('format' => 'xlsx');
$result = send_request('meetings/' . $meeting['meeting_id'] . '/attendees', 'GET', $params);
// Check for rate limiting
while ($result->code == 429) {
print 'wait 15s... ';
sleep(15);
$result = send_request('meetings/' . $meeting['meeting_id'] . '/attendees', 'GET', $params);
}
// Get the filename from the Content-Type header
$filename = NULL;
foreach ($curl_headers as $header) {
if (strstr($header, 'filename=')) {
list(, $filename) = explode('filename=', $header);
$filename = preg_replace('/\s+/', '_', trim($filename, " \t\n\r\0\x0B\"\'"));
break;
}
}
// Save the file
if ($filename) {
$directory = './' . $path . '/' . date('Ym', $meeting['start_time']['value']);
@mkdir($directory);
file_put_contents($directory . '/' . $filename, $result->response);
}
print "done\n";
}
print "\n";
}