From 0a16ad751cfac9b05a6dccdcb7a03c0e92f54692 Mon Sep 17 00:00:00 2001 From: Waldo Jaquith Date: Sat, 17 Feb 2018 20:06:50 -0500 Subject: [PATCH] Add a rudimentary endpoint for vote data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s a start. Toward #10. --- htdocs/1.1/.htaccess | 1 + htdocs/1.1/vote.php | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 htdocs/1.1/vote.php diff --git a/htdocs/1.1/.htaccess b/htdocs/1.1/.htaccess index 6ba0658..25fecc8 100644 --- a/htdocs/1.1/.htaccess +++ b/htdocs/1.1/.htaccess @@ -7,6 +7,7 @@ RewriteRule ^bills/([0-9]{4}).json$ bills.php?year=$1 [QSA] RewriteRule ^bill/([0-9]{4})/([A-Za-z0-9]+).json$ bill.php?year=$1&bill=$2 [QSA] RewriteRule ^legislators.json$ legislators.php [QSA] RewriteRule ^legislator/([a-z]+).json$ legislator.php?shortname=$1 [QSA] +RewriteRule ^vote/([0-9]{4})/([a-zA-Z0-9]{4,12}).json$ vote.php?year=$1&lis_id=$2 [QSA] # By default, API data expires in just one hour. #Header set Cache-Control "max-age=360, public" diff --git a/htdocs/1.1/vote.php b/htdocs/1.1/vote.php new file mode 100644 index 0000000..2fa1ebd --- /dev/null +++ b/htdocs/1.1/vote.php @@ -0,0 +1,64 @@ +lis_id = $lis_id; +$vote_info->session_year = $year; +$vote = $vote_info->get_aggregate(); +if ($vote === FALSE) +{ + header('HTTP/1.0 404 Not Found'); + exit(); +} + +/* + * Get detailed information about who voted how. + */ +$vote['legislators'] = $vote_info->get_detailed(); + + +# Send the JSON. If a callback has been specified, prefix the JSON with that callback and wrap the +# JSON in parentheses. +if (isset($callback)) +{ + echo $callback . ' ('; +} +echo json_encode($vote); +if (isset($callback)) +{ + echo ');'; +}