Skip to content

Instantly share code, notes, and snippets.

@liorsion
Created April 9, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liorsion/0a4ec5769d0b423aca67 to your computer and use it in GitHub Desktop.
Save liorsion/0a4ec5769d0b423aca67 to your computer and use it in GitHub Desktop.
Sample PHP code to access Bringg API
<?
$url = 'http://developer-api.bringg.com/partner_api/tasks/';
$data_string = array(
'title' => "Pizza Delivery",
'address' => "416 Water St. New York, NY 10002",
'scheduled_at' => "2014-11-29T04:16:09.123Z",
'company_id' => "1",
'team_id' => "3208",
'lat' => "45.5",
'lng' => "12.5",
'access_token' => "guRVwczRyt69exW2Vf",
'timestamp' => date('Y-m-d H:i:s')
);
$secret_key = "c49QFCX_GYtjxnUVnt";
// OpenSSL::HMAC.hexdigest("sha1", @partner.hmac_secret, to_query(canonical_params))
$signature = hash_hmac("sha1", http_build_query($data_string), $secret_key);
print("The signature: " + $signature);
$data_string["signature"] = $signature;
print("this is the data string: ");
print_r($data_string);
$content = json_encode($data_string);
print("The content: " + $content);
// $data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type:application/json',
'Content-Length: ' . strlen($content))
);
$json_response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($ch);
$response = json_decode($json_response, true);
print_r($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment