Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Forked from jaboutboul/cof.php
Created June 23, 2012 20:05
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 jonmarkgo/2979755 to your computer and use it in GitHub Desktop.
Save jonmarkgo/2979755 to your computer and use it in GitHub Desktop.
Cost of Freedom Text Based App
<?php
header('Content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$message = strip_tags($_REQUEST['Body']);
$response = "Welcome to the Cost of Freedom. Please text your state abbreviation to get Voter ID requirements and info.";
//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
$states = array(
'AL' => 5,
'AK' => 8,
'AZ' => 11,
'AR' => 14,
'CA' => 17,
'CO' => 20,
'CT' => 23,
'DE' => 26,
'DC' => 29,
'FL' => 32,
'GA' => 35,
'HI' => 38,
'ID' => 41,
'IL' => 44,
'IN' => 47,
'IA' => 50,
'KS' => 53,
'KY' => 56,
'LA' => 59,
'ME' => 62,
'MD' => 65,
'MA' => 68,
'MI' => 71,
'MN' => 74,
'MS' => 77,
'MO' => 80,
'MT' => 83,
'NE' => 86,
'NV' => 89,
'NH' => 92,
'NJ' => 95,
'NM' => 98,
'NY' => 101,
'NC' => 104,
'ND' => 107,
'OH' => 110,
'OK' => 113,
'OR' => 116,
'PA' => 119,
'RI' => 122,
'SC' => 125,
'SD' => 128,
'TN' => 131,
'TX' => 134,
'UT' => 137,
'VT' => 140,
'VA' => 143,
'WA' => 146,
'WV' => 149,
'WI' => 152,
'WY' => 155
);
if (in_array($message, $states)) {
$node = $doc->getElementsByTagName("cell")->item($states[$message]);
$response = $node->textContent;
}
?>
<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