Skip to content

Instantly share code, notes, and snippets.

@chrisalexander
Created February 17, 2014 11:00
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 chrisalexander/9048638 to your computer and use it in GitHub Desktop.
Save chrisalexander/9048638 to your computer and use it in GitHub Desktop.
#FloodHack Flood Flash source code

To use, simply get your import.io API key and user GUID from your account and put in the first to variables, then host the PHP script somewhere on the internet.

Then configure your Twilio SMS endpoint to point at the script, and send the number you configured an SMS.

<?php
$userGuid = "YOUR_USER_GUID";
$apiKey = "YOUR_API_KEY";
function query($connectorGuid, $input, $userGuid, $apiKey) {
$url = "https://api.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("input" => $input)));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
// Query for tile Environment Agency flood search
$result = query("1a80e085-3586-44ec-a46f-61f840d5a731", array("location" => $_REQUEST["Body"] ), $userGuid, $apiKey);
if ($result["totalResults"]) {
$message = "Sending " . count($result["results"]) . " of " . $result["totalResults"] . " results.";
for ($i = 0; $i < count($result["results"]); $i++) {
$res = $result["results"][$i];
$message = $message . "\r\n" . $res["severity"] . ": " . $res["location"];
if ($res["location_detail"] != $res["location"]) {
$message = $message . " - " . $res["location_detail"];
}
}
} else {
$message = "No results for that place.";
}
// now greet the sender
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Message><?php echo $message; ?></Message>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment