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: 176: 177: 178: 179: 180: 181: 182: 183:
<?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_Endpoint
{
function process()
{
try {
$handler = new LegiScan_Push();
$logic = new LegiScan_Process();
$missing = array();
if (isset($_SERVER['HTTP_AUTHORIZATION']))
{
$auth_token = LegiScan::getConfig('api_auth_token');
list($auth_type,$auth_value) = explode(' ', $_SERVER['HTTP_AUTHORIZATION']);
if ($auth_token && $auth_type == 'Token' && (strtolower($auth_token) != strtolower($auth_value)))
{
throw new APIAuthTokenException('Authorization token does not match!');
}
}
$handler->processPush();
$payload = $handler->getPayload();
switch ($handler->getPayloadType())
{
case 'bill':
LegiScan::fileLog("LegiScan Push processing bill {$payload['bill']['bill_id']}");
$missing = $logic->processBill($payload);
foreach (array_keys($missing) as $key)
{
foreach ($missing[$key] as $id)
{
LegiScan::fileLog("LegiScan Push requesting $key $id");
}
}
break;
case 'roll_call':
LegiScan::fileLog("LegiScan Push processing roll_call {$payload['roll_call']['roll_call_id']}");
$logic->processRollCall($payload);
$missing = $logic->getMissing();
foreach (array_keys($missing) as $key)
{
foreach ($missing[$key] as $id)
{
LegiScan::fileLog("LegiScan Push requesting $key $id");
}
}
break;
case 'text':
LegiScan::fileLog("LegiScan Push processing text {$payload['text']['doc_id']}");
$logic->processBillText($payload);
break;
case 'amendment':
LegiScan::fileLog("LegiScan Push processing amendment {$payload['amendment']['amendment_id']}");
$logic->processAmendment($payload);
break;
case 'supplement':
LegiScan::fileLog("LegiScan Push processing supplement {$payload['supplement']['supplement_id']}");
$logic->processSupplement($payload);
break;
case 'person':
LegiScan::fileLog("LegiScan Push processing person {$payload['person']['people_id']}");
$logic->processPerson($payload);
break;
case 'session':
LegiScan::fileLog("LegiScan Push processing session {$payload['session']['session_id']}");
$logic->processSession($payload);
break;
default:
throw new APIException('Unhandled payload type: ' . $handler->getPayloadType());
break;
}
$handler->respondOk($missing);
} catch (APIAuthTokenException $e) {
$error_msg = $e->getMessage();
LegiScan::fileLog("LegiScan Push ERROR $error_msg");
$handler->respondError($error_msg);
} catch (APIAccessException $e) {
$error_msg = $e->getMessage();
LegiScan::fileLog("LegiScan Push ERROR $error_msg");
$handler->respondError($error_msg);
} catch (APIException $e) {
$error_msg = "API Error: " . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine();
LegiScan::fileLog("LegiScan Push ERROR $error_msg");
$handler->respondError($error_msg);
} catch (PDOException $e) {
$error_msg = "Database: " . $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine();;
LegiScan::fileLog("LegiScan Push ERROR $error_msg");
$handler->respondError($error_msg);
} catch (Exception $e) {
$error_msg = $e->getMessage() . ' in ' . basename($e->getFile()) . ' on line ' . $e->getLine();
LegiScan::fileLog("LegiScan Push ERROR $error_msg");
$handler->respondError($error_msg);
}
}
}
if (php_sapi_name() === 'cli')
die("legiscan-push.php cannot be invoked from command line, it is a Push API subscription service endpoint.\n");
$endpoint = new LegiScan_Endpoint();
$endpoint->process();