Skip to content

Instantly share code, notes, and snippets.

@jaboutboul
Created April 12, 2012 18:14
Show Gist options
  • Save jaboutboul/2369767 to your computer and use it in GitHub Desktop.
Save jaboutboul/2369767 to your computer and use it in GitHub Desktop.
Cost of Freedom Text Based App
<?php
header('Content-type:text/xml');
$message = $_REQUEST['Body'];
$response = '';
//our spreadsheet's key
$key = "0Aoz1Ir-h-0g5dG00N1lDVG1COTFHellrc2o2bDhoeXc";
//the public url
$url = "http://spreadsheets.google.com/feeds/cells/$key/1/public/values";
$ch = curl_init();
//set some curl options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$google_sheet = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
$doc->loadXML($google_sheet);
//for each state, we load in the appropriate cell from the spreadsheet and then print out the text within
if ($message == "AL"){
$node = $doc->getElementsByTagName("cell")->item(5);
$response = $node->textContent;
}else
if ($message == "AK"){
$node = $doc->getElementsByTagName("cell")->item(8);
$response = $node->textContent;
}else
if ($message == "AZ"){
$node = $doc->getElementsByTagName("cell")->item(11);
$response = $node->textContent;
}else
if ($message == "AR"){
$node = $doc->getElementsByTagName("cell")->item(14);
$response = $node->textContent;
}else
if ($message == "CA"){
$node = $doc->getElementsByTagName("cell")->item(17);
$response = $node->textContent;
}else
if ($message == "CO"){
$node = $doc->getElementsByTagName("cell")->item(20);
$response = $node->textContent;
}else
if ($message == "CT"){
$node = $doc->getElementsByTagName("cell")->item(23);
$response = $node->textContent;
}else
if ($message == "DE"){
$node = $doc->getElementsByTagName("cell")->item(26);
$response = $node->textContent;
}else
if ($message == "DC"){
$node = $doc->getElementsByTagName("cell")->item(29);
$response = $node->textContent;
}else
if ($message == "FL"){
$node = $doc->getElementsByTagName("cell")->item(32);
$response = $node->textContent;
}else
if ($message == "GA"){
$node = $doc->getElementsByTagName("cell")->item(35);
$response = $node->textContent;
}else
if ($message == "HI"){
$node = $doc->getElementsByTagName("cell")->item(38);
$response = $node->textContent;
}else
if ($message == "ID"){
$node = $doc->getElementsByTagName("cell")->item(41);
$response = $node->textContent;
}else
if ($message == "IL"){
$node = $doc->getElementsByTagName("cell")->item(44);
$response = $node->textContent;
}else
if ($message == "IN"){
$node = $doc->getElementsByTagName("cell")->item(47);
$response = $node->textContent;
}else
if ($message == "IA"){
$node = $doc->getElementsByTagName("cell")->item(50);
$response = $node->textContent;
}else
if ($message == "KS"){
$node = $doc->getElementsByTagName("cell")->item(53);
$response = $node->textContent;
}else
if ($message == "KY"){
$node = $doc->getElementsByTagName("cell")->item(56);
$response = $node->textContent;
}else
if ($message == "LA"){
$node = $doc->getElementsByTagName("cell")->item(59);
$response = $node->textContent;
}else
if ($message == "ME"){
$node = $doc->getElementsByTagName("cell")->item(62);
$response = $node->textContent;
}else
if ($message == "MD"){
$node = $doc->getElementsByTagName("cell")->item(65);
$response = $node->textContent;
}else
if ($message == "MA"){
$node = $doc->getElementsByTagName("cell")->item(68);
$response = $node->textContent;
}else
if ($message == "MI"){
$node = $doc->getElementsByTagName("cell")->item(71);
$response = $node->textContent;
}else
if ($message == "MN"){
$node = $doc->getElementsByTagName("cell")->item(74);
$response = $node->textContent;
}else
if ($message == "MS"){
$node = $doc->getElementsByTagName("cell")->item(77);
$response = $node->textContent;
}else
if ($message == "MO"){
$node = $doc->getElementsByTagName("cell")->item(80);
$response = $node->textContent;
}else
if ($message == "MT"){
$node = $doc->getElementsByTagName("cell")->item(83);
$response = $node->textContent;
}else
if ($message == "NE"){
$node = $doc->getElementsByTagName("cell")->item(86);
$response = $node->textContent;
}else
if ($message == "NV"){
$node = $doc->getElementsByTagName("cell")->item(89);
$response = $node->textContent;
}else
if ($message == "NH"){
$node = $doc->getElementsByTagName("cell")->item(92);
$response = $node->textContent;
}else
if ($message == "NJ"){
$node = $doc->getElementsByTagName("cell")->item(95);
$response = $node->textContent;
}else
if ($message == "NM"){
$node = $doc->getElementsByTagName("cell")->item(98);
$response = $node->textContent;
}else
if ($message == "NY"){
$node = $doc->getElementsByTagName("cell")->item(101);
$response = $node->textContent;
}else
if ($message == "NC"){
$node = $doc->getElementsByTagName("cell")->item(104);
$response = $node->textContent;
}else
if ($message == "ND"){
$node = $doc->getElementsByTagName("cell")->item(107);
$response = $node->textContent;
}else
if ($message == "OH"){
$node = $doc->getElementsByTagName("cell")->item(110);
$response = $node->textContent;
}else
if ($message == "OK"){
$node = $doc->getElementsByTagName("cell")->item(113);
$response = $node->textContent;
}else
if ($message == "OR"){
$node = $doc->getElementsByTagName("cell")->item(116);
$response = $node->textContent;
}else
if ($message == "PA"){
$node = $doc->getElementsByTagName("cell")->item(119);
$response = $node->textContent;
}else
if ($message == "RI"){
$node = $doc->getElementsByTagName("cell")->item(122);
$response = $node->textContent;
}else
if ($message == "SC"){
$node = $doc->getElementsByTagName("cell")->item(125);
$response = $node->textContent;
}else
if ($message == "SD"){
$node = $doc->getElementsByTagName("cell")->item(128);
$response = $node->textContent;
}else
if ($message == "TN"){
$node = $doc->getElementsByTagName("cell")->item(131);
$response = $node->textContent;
}else
if ($message == "TX"){
$node = $doc->getElementsByTagName("cell")->item(134);
$response = $node->textContent;
}else
if ($message == "UT"){
$node = $doc->getElementsByTagName("cell")->item(137);
$response = $node->textContent;
}else
if ($message == "VT"){
$node = $doc->getElementsByTagName("cell")->item(140);
$response = $node->textContent;
}else
if ($message == "VA"){
$node = $doc->getElementsByTagName("cell")->item(143);
$response = $node->textContent;
}else
if ($message == "WA"){
$node = $doc->getElementsByTagName("cell")->item(146);
$response = $node->textContent;
}else
if ($message == "WV"){
$node = $doc->getElementsByTagName("cell")->item(149);
$response = $node->textContent;
}else
if ($message == "WI"){
$node = $doc->getElementsByTagName("cell")->item(152);
$response = $node->textContent;
}else
if ($message == "WY"){
$node = $doc->getElementsByTagName("cell")->item(155);
$response = $node->textContent;
}
else {
$response = "Welcome to the Cost of Freedom. Please text your state abbreviation to get Voter ID requirements and info.";}
?>
<Response>
<Sms><?php echo $response;?></Sms>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment