1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175:
<?php
if (version_compare(PHP_VERSION, '5.4.0') < 0)
die('PHP 5.4.0 or higher is required');
require_once('LegiScan.php');
class LegiScan_WebTest
{
function processPOST()
{
$keys = array('key', 'op', 'id');
foreach ($keys as $k)
{
$vals[$k] = null;
if (isset($_POST[$k]))
$$k = trim($_POST[$k]);
else
$$k = null;
}
echo "<html><head><title>LegiScan API Demo</title></head>\n";
echo "<body style='font-family: sans-serif;'>\n";
echo "<h2>LegiScan API Demo (Pull)</h2>\n";
echo "<form method='post'>";
echo "<input type='hidden' name='run' value='1'/>";
echo "<table border='0'>";
echo "<tr><td>API Key:</td><td><input type='text' size='34' maxlength='32' name='key' value='$key'></td></tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr valign='top'>";
echo "<td>Request Type:</td><td>";
echo "<input type='radio' name='op' value='sessionlist' ".($op=='sessionlist'?'checked':'').">Session List (<i>state_abbr</i>)<br/>";
echo "<input type='radio' name='op' value='master' ".($op=='master'?'checked':'').">Master List (<i>session_id</i>)<br/>";
echo "<input type='radio' name='op' value='bill' ".($op=='bill'?'checked':'').">Bill (<i>bill_id</i>)<br/>";
echo "<input type='radio' name='op' value='text' ".($op=='text'?'checked':'').">Text (<i>text_id</i>)<br/>";
echo "<input type='radio' name='op' value='amendment' ".($op=='amendment'?'checked':'').">Amendment (<i>amendment_id</i>)<br/>";
echo "<input type='radio' name='op' value='supplement' ".($op=='supplement'?'checked':'').">Supplement (<i>supplement_id</i>)<br/>";
echo "<input type='radio' name='op' value='roll_call' ".($op=='roll_call'?'checked':'').">Vote (<i>roll_call_id</i>)<br/>";
echo "<input type='radio' name='op' value='person' ".($op=='person'?'checked':'').">Person (<i>people_id</i>)<br/>";
echo "</td>";
echo "</tr>\n";
echo "<tr><td> </td></tr>\n";
echo "<tr><td>Request ID:</td><td ><input type='text' size='10' maxlength='7' name='id' value='$id'></td></tr>\n";
echo "<tr valign='top'>";
echo "</tr>\n";
echo "</table>\n";
echo "<br/>";
echo "<input type='submit' value='Make API Request'>";
echo " ";
echo "<input type='reset' value='Reset'><br/>";
echo "</form>";
echo "<pre>";
if (isset($_POST['run']))
{
if (!$key) die('<h2>LegiScan Error</h2>Missing API Key');
if (!$op) die('<h2>LegiScan Error</h2>Missing Request Type');
if (!$id) die('<h2>LegiScan Error</h2>Missing Request ID');
try {
$legiscan = new LegiScan_Pull($key);
switch ($op)
{
case 'sessionlist':
$resp = $legiscan->getSessionList($id);
break;
case 'master':
$resp = $legiscan->getMasterList($id);
break;
case 'bill':
$resp = $legiscan->getBill($id);
break;
case 'text':
$resp = $legiscan->getBillText($id);
break;
case 'amendment':
$resp = $legiscan->getAmendment($id);
break;
case 'supplement':
$resp = $legiscan->getSupplement($id);
break;
case 'roll_call':
$resp = $legiscan->getRollCall($id);
break;
case 'person':
$resp = $legiscan->getPerson($id);
break;
}
echo "<h2>API Reqeust URL</h2>";
echo $legiscan->getURL() . "\n";
echo "<h2>API JSON Response</h2>";
echo $legiscan->getRawResponse() . "\n";
echo "<h2>API Response Object</h2>";
print_r($resp);
} catch (APIException $e) {
echo "<h2>LegiScan Error</h2>";
echo 'API Error: ' . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine() . "\n";
} catch (APIAccessException $e) {
echo "<h2>LegiScan Error</h2>";
echo 'API Access: ' . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine() . "\n";
} catch (APIStatusException $e) {
echo "<h2>LegiScan Error</h2>";
echo 'API Status: ' . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine() . "\n";
} catch (PDOException $e) {
echo "<h2>LegiScan Error</h2>";
echo 'Database Error: ' . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine() . "\n";
} catch (Exception $e) {
echo "<h2>LegiScan Error</h2>";
echo 'Error: ' . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine() . "\n";
}
}
}
}
$webtest = new LegiScan_WebTest();
$webtest->processPOST();