Skip to content

Instantly share code, notes, and snippets.

@liorsion
Created June 15, 2015 08:49
Show Gist options
  • Select an option

  • Save liorsion/693b1ae79b00742bd702 to your computer and use it in GitHub Desktop.

Select an option

Save liorsion/693b1ae79b00742bd702 to your computer and use it in GitHub Desktop.
Create Formatted Note in Bringg Sample
<?
$Header = array('Item', 'Price', 'Quantity');
$body = array(array('Chicken Breast', '10$', 1), array('French Fries', '3$', 5));
$primary_array = array("Header"=>$Header,"Body"=>$body);
echo "****XXXXXXXXXXXXXXXXXXXXXXXXXXXXX******SAMPLE ARRAY FORMAT NOTES*****XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*****";
echo "<pre>";
print_r($primary_array);
echo "****XXXXXXXXXXXXXXXXXXXXXXXXXXXXX******SAMPLE ARRAY FORMAT NOTES*****XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*****";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<pre>";
// $url = 'http://developer-api.bringg.com/partner_api/tasks/917/way_points/852/notes';
$url = 'localhost:3000/partner_api/tasks/917/way_points/852/notes';
// Add some test data
$data_string = array(
'company_id' => '1',
'note' => $primary_array,
'type' => 1,
'access_token' => "yguRVwczRyt69exGW2Vf",
'timestamp' => date('Y-m-d H:i:s')
);
$secret_key = "Yc49QFCaX_GYtjxnUVnt";
echo "signing: ";
echo "***\n";
echo http_build_query($primary_array);
echo "***\n";
// echo http_build_query($data_string);
echo http_build_query($data_string);
echo "***\n";
echo var_dump($data_string);
// 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_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HEADER, false);
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);
curl_close($ch);
$return_data = json_decode($json_response);
echo "****XXXXXXXXXXXXXXXXXXXXXXXXXXXXX******RETURN FROM BRINGG *****XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*****";
echo "<br>";
echo "<br>";
print_r($return_data);
echo "****XXXXXXXXXXXXXXXXXXXXXXXXXXXXX******RETURN FROM BRINGG *****XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*****";
?>
@johhansantana

Copy link
Copy Markdown

could you do a javascript example for the first 3 variables? I'm trying to create the formatted note like this but with javascript and it always returns an empty note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment