Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created December 8, 2010 17:35
Show Gist options
  • Select an option

  • Save mheadd/733606 to your computer and use it in GitHub Desktop.

Select an option

Save mheadd/733606 to your computer and use it in GitHub Desktop.
<?php
define("COUCH_DB_HOST", "");
define("COUCH_DB_PORT", "");
define("COUCH_DB_NAME", "");
function saveData($question, $to, $answer) {
$doc = json_encode(array("question" => $question, "to" => $to, "answer" => $answer, ));
$url = COUCH_DB_HOST.":".COUCH_DB_PORT."/".COUCH_DB_NAME;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $doc);
curl_exec($ch);
// HTTP response on POST should be '201' (created) if successful, 400 class on error.
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != '201') {
return false;
}
return true;
}
call($to, array("network" => "JABBER", "channel" => "TEXT"));
$answer = ask($question, array('choices' => '[ANY]'));
if(saveData($question, $to, $answer->value)) {
_log("*** Answer saved successfully. ***");
} else {
_log("*** Oops! There was a probem saving the answer. ***");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment