public function test_query_error() { $client = new Socrata("soda.demo.socrata.com", getenv("APP_TOKEN")); // We expect an error! $this->expectException(Exception::class); $response = $client->get("6yvf-kk3n", array("\$paramthatdoesntexist" => "diequerydie")); }
function formValidate() { $view_uid = "cdan-uybe"; //"5fy3-sjg8";//"ypyx-bcrh";//"ykw4-j3aj"; $root_url = "https://brigades.opendatanetwork.com"; //"https://data.austintexas.gov"; $app_token = "dyTNWsNZzxuGgo6FduT0JUzcx"; //"B0ixMbJj4LuQVfYnz95Hfp3Ni"; //Put form elements into post variables (this is where you would sanitize your data) $zipcode = @$_POST['zipcode']; //Establish values that will be returned via ajax $return = array(); $return['msg'] = ''; $return['error'] = false; //Begin form validation functionality if (!isset($zipcode) || empty($zipcode)) { $return['error'] = true; $return['msg'] .= '<li>Error: Field1 is empty.</li>'; } //Begin form success functionality if ($return['error'] === false) { // Create a new unauthenticated client $socrata = new Socrata($root_url, $app_token); //$params = array("\$where" => "within_circle(location_1, $latitude, $longitude, $range)"); $params = array("zip_code" => $zipcode); //"within_circle(location_1, $zipcode, $longitude, $range)"); $response = $socrata->get("/resource/{$view_uid}.json", $params); $return['msg'] = '<li>Success Message</li>'; $return['data'] = $response; } //Return json encoded results return json_encode($return); }
function array_get($needle, $haystack) { return in_array($needle, array_keys($haystack)) ? $haystack[$needle] : NULL; } $view_uid = "h8x4-nvyi"; $root_url = "data.austintexas.gov"; $app_token = "B0ixMbJj4LuQVfYnz95Hfp3Ni"; $response = NULL; $latitude = array_get("latitude", $_POST); $longitude = array_get("longitude", $_POST); $range = array_get("range", $_POST); if ($latitude != NULL && $longitude != NULL && $range != NULL) { // Create a new unauthenticated client $socrata = new Socrata($root_url, $app_token); $params = array("\$where" => "within_circle(location, {$latitude}, {$longitude}, {$range})"); $response = $socrata->get($view_uid, $params); } ?> <html> <head> <title>Austin Dangerous Dogs</title> </head> <body> <h1>Austin Dangerous Dogs</h1> <p>If you get no results, its likely because there are no dangerous dogs at that location. Try another lat/long.</p> <?php if ($response == NULL) { ?> <form action="index.php" method="POST">
<?php require_once "socrata.php"; //$response = NULL; $socrata = new Socrata("https://data.medicare.gov", $app_token); //$params = array("\$where" => "starts_with(zip, $model->zipcode)"); $params = array("\$where" => "starts_with(zip, \"{$model->zipcode}\")"); //$params = array("\$where" => "starts_with(zip, '77584')"); $response = $socrata->get("/resource/aeay-dfax.json", $params); ?> <h2>Results</h2> <?# Create a table for our actual data ?> <table border="1"> <tr> <th>Last Name</th> <th>First Name</th> </tr> <?# Print rows ?> <?php foreach ($response as $row) { ?>
<?php require_once "socrata.php"; $view_uid = "ykw4-j3aj"; $root_url = "https://data.austintexas.gov"; $app_token = 'i2T950xvnFx6nhfJqgUqokaIf'; $response = NULL; $latitude = array_get("latitude", $_POST); $longitude = array_get("longitude", $_POST); $range = array_get("range", $_POST); if ($latitude != NULL && $longitude != NULL && $range != NULL) { // Create a new unauthenticated client $socrata = new Socrata($root_url, $app_token); $params = array("\$where" => "within_circle(location, {$latitude}, {$longitude}, {$range})"); $response = $socrata->get("/resource/{$view_uid}.json", $params); } ?> <html> <head> <title>Austin Dangerous Dogs</title> </head> <body> <h1>Austin Dangerous Dogs</h1> <p>Try 30.27898, -97.68351 with a range of 1000 meters</p> <?php if ($response == NULL) { $form = ActiveForm::begin(['id' => 'soc-form']);