@ 2015-10-01T18:59:18Z <?php
/**
* Makes an API request to elucidat
* @param $headers
* @param $fields
* @param $url
* @param $consumer_secret
* @return mixed
*/
function call_elucidat($headers, $fields, $method, $url, $consumer_secret){
//Build a signature
$headers['oauth_signature'] = build_signature($consumer_secret, array_merge($headers, $fields), $method, $url);
//Build OAuth headers
$auth_headers = 'Authorization:';
$auth_headers .= build_base_string($headers, ',');
//Build the request string
$fields_string = build_base_string($fields, '&');
//Set the headers
$header = array($auth_headers, 'Expect:');
// Create curl options
if(strcasecmp($method, "GET") == 0){
$url .= '?'.$fields_string;
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
} else {
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => count($fields),
CURLOPT_POSTFIELDS => $fields_string);
}
//Init the request and set its params
$request = curl_init();
curl_setopt_array($request, $options);
//Make the request
$response = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
curl_close($request);
return array(
'status' => $status,
'response' => json_decode($response, true)
);
}
/**
* Each request to the elucidat API must be accompanied by a unique key known as a nonce.
* This key adds an additional level of security to the API.
* A new key must be requested for each API call.
* @param $api_url
* @param $consumer_key
* @param $consumer_secret
* @return bool
*/
function get_nonce($api_url, $consumer_key, $consumer_secret){
// Start with some standard headers, unsetting the oauth_nonce. without the nonce header the API will automatically issue us one.
$auth_headers = auth_headers($consumer_key);
unset($auth_headers['oauth_nonce']);
//Make a request to elucidat for a nonce...any url is fine providing it doesnt already have a nonce
$json = call_elucidat($auth_headers, array(), 'GET', $api_url, $consumer_secret);
if(isset($json['response']['nonce'])){
return $json['response']['nonce'];
}
return false;
}
/**
* Computes and returns a signature for the request.
* @param $secret
* @param $fields
* @param $request_type
* @param $url
* @return string
*/
function build_signature($secret, $fields, $request_type, $url){
ksort($fields);
//Build base string to be used as a signature
$base_info = $request_type.'&'.$url.'&'.build_base_string($fields, '&'); //return complete base string
//Create the signature from the secret and base string
$composite_key = rawurlencode($secret);
return base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
}
/**
* Builds a segment from an array of fields. Its used to create string representations of headers and URIs
* @param $fields
* @param $delim
* @return string
*/
function build_base_string($fields, $delim){
$r = array();
foreach($fields as $key=>$value){
$r[] = rawurlencode($key) . "=" . rawurlencode($value);
}
return implode($delim, $r); //return complete base string
}
/**
* Returns typical headers needed for a request
* @param $consumer_key
* @param $nonce
*/
function auth_headers($consumer_key, $nonce = ''){
return array('oauth_consumer_key' => $consumer_key,
'oauth_nonce' => $nonce,
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_version' => '1.0');
}
$nonce = get_nonce('https://api.elucidat.com/v2/projects', '1558A022-336C-6922-4B1F-AD3505839D5A', 'A393E5ED-C79F-4EB7-7DAE-9CB6C090B9E8');
$headers = auth_headers('1558A022-336C-6922-4B1F-AD3505839D5A', $nonce);
$fields = array('simulation_mode'=>'simulation');
$result = call_elucidat($headers, $fields, 'GET', 'https://api.elucidat.com/v2/projects', 'A393E5ED-C79F-4EB7-7DAE-9CB6C090B9E8');
echo ("HTTP status code: " . $result['status'] . "\n");
print_r($result['response']);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.2.6 0.008 0.006 16.84 7.2.0 0.016 0.003 19.54 7.1.20 0.009 0.006 15.85 7.1.10 0.007 0.007 18.06 7.1.7 0.000 0.007 16.82 7.1.6 0.012 0.009 19.27 7.1.5 0.000 0.015 17.13 7.1.0 0.010 0.070 22.43 7.0.20 0.008 0.003 16.99 7.0.8 0.040 0.060 20.08 7.0.7 0.033 0.087 19.92 7.0.6 0.047 0.053 20.07 7.0.5 0.037 0.063 20.32 7.0.4 0.003 0.043 20.13 7.0.3 0.003 0.037 20.14 7.0.2 0.010 0.043 20.07 7.0.1 0.003 0.047 20.03 7.0.0 0.010 0.083 19.95 5.6.28 0.003 0.043 21.13 5.6.23 0.007 0.063 20.77 5.6.22 0.007 0.083 20.61 5.6.21 0.010 0.077 20.78 5.6.20 0.013 0.067 21.07 5.6.19 0.007 0.050 21.19 5.6.18 0.010 0.067 20.99 5.6.17 0.000 0.083 21.13 5.6.16 0.013 0.050 21.05 5.6.15 0.007 0.060 21.13 5.6.14 0.007 0.037 21.03 5.6.13 0.003 0.067 21.10 5.6.12 0.010 0.047 21.04 5.6.11 0.007 0.040 20.95 5.6.10 0.000 0.043 21.04 5.6.9 0.000 0.083 21.06 5.6.8 0.007 0.037 20.37 5.6.7 0.013 0.037 20.42 5.6.6 0.007 0.037 20.47 5.6.5 0.003 0.040 20.58 5.6.4 0.003 0.040 20.46 5.6.3 0.007 0.057 20.47 5.6.2 0.000 0.043 20.33 5.6.1 0.007 0.033 20.51 5.6.0 0.003 0.047 20.38 5.5.37 0.013 0.077 20.39 5.5.36 0.013 0.073 20.55 5.5.35 0.007 0.073 20.48 5.5.34 0.010 0.047 20.79 5.5.33 0.003 0.047 20.90 5.5.32 0.003 0.043 20.91 5.5.31 0.007 0.053 20.76 5.5.30 0.007 0.073 20.89 5.5.29 0.003 0.043 20.91 5.5.28 0.010 0.037 20.94 5.5.27 0.000 0.043 20.84 5.5.26 0.003 0.040 20.77 5.5.25 0.003 0.037 20.57 5.5.24 0.003 0.040 20.17 5.5.23 0.003 0.040 20.05 5.5.22 0.007 0.037 20.32 5.5.21 0.000 0.043 20.26 5.5.20 0.000 0.040 20.27 5.5.19 0.003 0.047 20.11 5.5.18 0.003 0.040 20.26 5.5.16 0.003 0.040 20.29 5.5.15 0.003 0.040 20.09 5.5.14 0.003 0.073 20.28 5.5.13 0.003 0.040 20.11 5.5.12 0.007 0.060 20.28 5.5.11 0.000 0.043 20.10 5.5.10 0.017 0.067 20.13 5.5.9 0.003 0.077 20.13 5.5.8 0.003 0.073 20.09 5.5.7 0.010 0.043 20.09 5.5.6 0.013 0.077 20.18 5.5.5 0.007 0.073 20.09 5.5.4 0.003 0.043 20.14 5.5.3 0.013 0.050 20.17 5.5.2 0.017 0.070 20.18 5.5.1 0.003 0.080 20.07 5.5.0 0.000 0.057 20.05 5.4.45 0.007 0.037 19.36 5.4.44 0.003 0.040 19.48 5.4.43 0.007 0.037 19.20 5.4.42 0.010 0.060 19.47 5.4.41 0.003 0.037 19.22 5.4.40 0.003 0.033 19.10 5.4.39 0.003 0.040 19.18 5.4.38 0.003 0.033 19.04 5.4.37 0.003 0.037 18.95 5.4.36 0.003 0.043 19.14 5.4.35 0.003 0.033 18.95 5.4.34 0.003 0.037 19.12 5.4.32 0.007 0.037 18.86 5.4.31 0.003 0.037 18.95 5.4.30 0.003 0.037 19.04 5.4.29 0.003 0.037 19.02 5.4.28 0.000 0.040 19.16 5.4.27 0.003 0.037 19.02 5.4.26 0.003 0.073 19.04 5.4.25 0.007 0.073 18.87 5.4.24 0.007 0.067 19.04 5.4.23 0.013 0.060 18.94 5.4.22 0.003 0.073 19.11 5.4.21 0.017 0.047 19.02 5.4.20 0.007 0.073 19.13 5.4.19 0.010 0.063 19.17 5.4.18 0.007 0.077 19.13 5.4.17 0.000 0.090 18.89 5.4.16 0.007 0.077 19.10 5.4.15 0.007 0.040 18.86 5.4.14 0.013 0.030 16.39 5.4.13 0.000 0.080 16.46 5.4.12 0.003 0.063 16.24 5.4.11 0.013 0.067 16.44 5.4.10 0.017 0.063 16.39 5.4.9 0.010 0.070 16.52 5.4.8 0.007 0.067 16.55 5.4.7 0.010 0.070 16.54 5.4.6 0.013 0.073 16.43 5.4.5 0.017 0.063 16.37 5.4.4 0.003 0.077 16.38 5.4.3 0.003 0.050 16.31 5.4.2 0.007 0.077 16.41 5.4.1 0.000 0.077 16.45 5.4.0 0.013 0.063 15.86
preferences:dark mode live preview
33.63 ms | 400 KiB | 5 Q