Пример #1
0
 public function api_get_string($data, $error)
 {
     $data['token'] = $this->token;
     // Create REDCap API request object
     $request = new RestCallRequest($this->api_url, $data);
     // Initiate the API request, and fetch the results from the request object.
     $request->execute();
     $body_str = $request->getResponseBody();
     $header_array = $request->getResponseInfo();
     // Decode the JSON content returned by REDCap (into an array rather
     // than into an object by specifying the second argument as "true"),
     $body_array = json_decode($body_str, true);
     // If an error is returned, there will be an 'error' key in
     // the $body_array
     if (is_array($body_array) && array_key_exists('error', $body_array)) {
         $error .= "Error: '" . $body_array['error'] . "'\n";
         $this->notifier->notify($error);
         return false;
     } else {
         return $body_str;
     }
 }
$records = array();
$events = array();
$fields = array();
$forms = array();
echo "hey 3 <br />";
# an array containing all the elements that must be submitted to the API
$data = array('content' => 'record', 'type' => 'flat', 'format' => 'csv', 'records' => $records, 'events' => $events, 'fields' => $fields, 'forms' => $forms, 'token' => '19BE63523DB731FA55CD2E39C267E4B0');
echo "hey 4 <br />";
# create a new API request object
$request = new RestCallRequest("API_URL", 'POST', $data);
echo "hey 5 <br />";
# initiate the API request
$request->execute();
echo "hey 6 <br />";
# get the content type of the data being returned
$response = $request->getResponseInfo();
$type = explode(";", $response['content_type']);
$contentType = $type[0];
# set the content type of page
header("Content-type: {$contentType}; charset=utf-8");
#print the data to the screen
echo $request->getResponseBody();
# the following line will print out the entire HTTP request object
# good for testing purposes to see what is sent back by the API and for debugging
echo '<pre>' . print_r($request, true) . '</pre>';
/*
*/
?>


Пример #3
0
$data = array('content' => 'record', 'type' => 'flat', 'format' => 'csv', 'records' => $records, 'events' => $events, 'fields' => $fields, 'token' => $local_token);
# create a new API request object for the local machine
$request_local = new RestCallRequest($init_params['local_ip'], 'POST', $data);
# initiate the API request for the data on the local machine
$request_local->execute();
#$local_response = $request_local->getResponseInfo();
$exportdata = $request_local->getResponseBody();
#data from the local machine
//print_r($exportdata);
# an array containing all the elements that must be submitted to the server API
$data = array('content' => 'record', 'type' => 'flat', 'format' => 'csv', 'token' => $server_token, 'data' => $exportdata);
# create a new API request object for the server
$request_server = new RestCallRequest($init_params['server_ip'], 'POST', $data);
# initiate the API request to the server
$request_server->execute();
$server_response = $request_server->getResponseInfo();
//print_r($server_response);
$log_message = implode("\n", array_map(function ($v, $k) {
    return $k . '=' . $v;
}, $server_response, array_keys($server_response)));
# Prepare log folder
$path = $init_params['log_location'];
$response_code = $server_response['http_code'];
if ($response_code != '200') {
    //there was an error
    echo json_encode(array("<h2>ERROR!</h2><br/>", return_httpstat($response_code)));
} else {
    //Success message here
    #Success message here
    $the_date = getdate();
    $month = $the_date['mon'];