Skip to content

Commit

Permalink
more decision stuffz
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Salisbury committed Feb 6, 2017
1 parent 8ce89f7 commit 1c4be69
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions api/routes/decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,96 @@
$response = $response->withJSON($response_json);
return $response;
});

function getFdctLoginInfo(){
$endpoint = "http://api.fooducate.com/fdct/login/basic/?username=guest&password=&responseformat=json";
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Fdct-Udid: RuddCenter_Test",
"X-Fdct-User-Agent: RuddCenter/1.0 ( OSX; 10.10.4; MacPro/2009; 1.0 )",
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response,true);
$importantStuff ['fdctuserid'] = $response['response']['body']['user']['@attributes']['id'];
$importantStuff ['fdctsessionid'] = $response['response']['head']['session']['@attributes']['id'];
$importantStuff ['fdcttimestamp'] = $response['response']['head']['request']['@attributes']['timestamp'];
return $importantStuff;
}
function getProductIngredients($fdct_id) {
$endpoint ="http://www.fooducate.com/internal/chef_client_proxy/get_product_by_id/".$fdct_id."/null";
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$res = json_decode($response,true);
$greds = $res['response']['body']['product_list']['products'][0]['product_ingredients']['original_ingredients']['@text'];
return $greds;
curl_close($ch);
}




$app->get('/getProductInfo/{upc}', function($request, $response) {

$upc = $request->getAttribute('upc');

$fdctconfig = array();
$fdctconfig['passphrase'] = "Partially Hydrogenated Vegetable";
//login and get the session id and userid from the login
$fdctstuff = getFdctLoginInfo();
// set the default timezone to match fooducate server
date_default_timezone_set("UTC");
$tstamp = date(DATE_ISO8601, time());
// build the token
$token = $fdctstuff['fdctuserid']. ":" . $fdctstuff['fdctsessionid'] . ":" . $tstamp;
// create the hash w the passphrase
$signature = base64_encode(hash_hmac('sha256', $token, $fdctconfig['passphrase'],true));
// get ready and stuff
$endpoint = "http://api.fooducate.com/fdct/product/view/product/?reason=scan&upc=".$upc."&responseformat=json";
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//set the headers based on the api spec..right? WHY YOU NO WORK!
$headers = array(
"X-Fdct-Udid: RuddCenter_Test",
"X-Fdct-User-Agent: RuddCenter/1.0 ( OSX; 10.10.4; MacPro/2009; 1.0 )",
"X-Fdct-Signature-Method: SHA1-HMAC256",
"X-Fdct-Timestamp: ".$tstamp,
"X-Fdct-Session: " .$fdctstuff['fdctsessionid'],
"X-Fdct-Signature: ". $signature);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set our own response headers and output the result
// $response->headers->set('Content-Type', 'application/json');
$fdctresponse = curl_exec($ch);
$res = json_decode($fdctresponse,true);
$fdct_id = $res['response']['body']['product_list']['products'][0]['@attributes']['id'];
$ingreds = getProductIngredients($fdct_id);
$res['response']['body']['product_list']['products'][0]['@attributes']['ingreds'] = $ingreds;



$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => "OK"
],
"data" => [$res]
];

$response = $response->withJSON($response_json);
return $response;


curl_close($ch);
});


$app->get('/getDecision/{upc}/{category}', function($request, $response) {

// get the ingredients by UPC
// get the rules by category

// for each rules, evaluate ingredients
// profit!
});

0 comments on commit 1c4be69

Please sign in to comment.