@ 2013-03-08T20:44:37Z <?php
class Client
{
private $language = '';
private $hashing_key = '';
function __construct($hashing_key, $language='en-US')
{
$this->language = $language;
$this->hashing_key = $hashing_key;
}
public function call($url, $method, $vars, $headers)
{
if (!array_key_exists('app_key', $headers))
$headers['app_key'] = $vars['app_key'];
if (!array_key_exists('user_email', $headers))
$headers['user_email'] = $vars['user_email'];
if (!array_key_exists('auth_token', $headers))
$headers['auth_token'] = '';
$headers['Accept-Language'] = $this->language;
$headers['request_timestamp'] = gmdate('c');
$headers['request_body'] = $vars;
$headers['request_url'] = $url;
$headers['request_method'] = $method;
$headers['api_signature'] = $this->get_signature($headers);
$request_body = $this->encode_post_data($vars);
$headers['request_body'] = $request_body;
$url = $this->encode_query_string($url);
$headers['request_url'] = $url;
$curl = new Curl();
$curl->headers = $headers;
$response = $curl->request(strtoupper($method), $url, $vars);
$rv = array();
$rv['body'] = json_decode($response->body, true);
$rv['headers'] = $response->headers;
$rv['exception'] =$rv['body']['exception'];
$rv['http_status_code'] = $rv['body']['http_status_code'];
$rv['auth_token'] = $rv['body']['auth_token'];
$rv['body'] = $rv['body']['body'];
return $rv;
}
function encode_query_string($url)
{
$pos = strpos($url, '?',0);
if ($pos !== false)
{
$qs = substr($url,$pos+1);
$qs = rawurlencode(urldecode($qs));
$url = substr($url,0, $pos+1) . $qs;
}
return $url;
}
function encode_post_data($vars)
{
$request_body = '';
if ($vars)
{
foreach ($vars AS $key=>$value)
{
if (is_array($value))
$request_body .= $this->urlencode_array($value, $key).'&';
else
$request_body .= $key.'='.$value.'&';
}
$request_body = rtrim($request_body, '&');
}
return $request_body;
}
function get_signature($vars)
{
$key = $this->hashing_key;
$message = $vars['auth_token'] . $vars['app_key'] . $vars['user_email'] . $vars['request_timestamp'] . $this->encode_post_data($vars['request_body']) .$this->encode_query_string($vars['request_url']) . $vars['request_method'];
return base64_encode(hash_hmac('sha512', $message, hash('sha512', $this->hashing_key)));
}
function urlencode_array($var, $varName, $separator = '&')
{
$toImplode = array();
foreach ($var as $key => $value)
{
if (is_array($value))
$toImplode[] = urlencode_array($value, "{$varName}[{$key}]", $separator);
else
$toImplode[] = "{$varName}[{$key}]=".rawurlencode(urldecode($value));
}
return implode($separator, $toImplode);
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/WMGv7 on line 5
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/WMGv7 on line 5
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/WMGv7 on line 5
Process exited with code 255 . preferences:dark mode live preview
254.15 ms | 401 KiB | 343 Q