Example #1
0
 public function testGetResourceWithSoqlQuery()
 {
     $ds = new SodaDataset($this->client, $this->id);
     $soql = new SoqlQuery();
     $soql->select("date_posted", "state", "sample_type")->where("state = 'AR'");
     $results = $ds->getDataset($soql);
     $this->assertTrue(count($results) > 1);
 }
Example #2
0
 /**
  * Get the API version this dataset is using
  *
  * @return int The API version number
  */
 public function getApiVersion()
 {
     // If we don't have the API version set, send a dummy query with limit 0 since we only care about the headers
     if ($this->apiVersion == 0) {
         $soql = new SoqlQuery();
         $soql->limit(0);
         // When we fetch a dataset, the API version is stored
         $this->getDataset($soql);
     }
     return $this->apiVersion;
 }
 public function testDeleteRow()
 {
     $ds = new SodaDataset($this->client, $this->id);
     $soql = new SoqlQuery();
     $soql->select(":id,date,os,visits");
     $result = $ds->getDataset($soql);
     $uID = $result[0][':id'];
     $ds->deleteRow($uID);
     $soql->select(':id')->where(':id = ' . $uID);
     $new_result = $ds->getDataset($soql);
     $this->assertEmpty($new_result);
 }
Example #4
0
 public function testMultipleGroupingQuery()
 {
     $firstColumnToGroup = "1stGroup";
     $secondColumnToGroup = "2ndGroup";
     $soql = new SoqlQuery();
     $soql->group($firstColumnToGroup)->group($secondColumnToGroup);
     $expected = '$group=' . implode(',', array($firstColumnToGroup, $secondColumnToGroup));
     $this->assertContains($expected, (string) $soql);
 }
Example #5
0
// PhpSoda is packaged up in a Phar archive which allows us to include the entire library with a single "include."
// You may also use "include_once," "require," or "require_once"
include "phpsoda-0.1.0.phar";
// PhpSoda organizes its code inside namespaces; in order to use PhpSoda, you'll have to "use" the namespaces. These
// three namespaces should suffice for most code.
use allejo\Socrata\SodaClient;
use allejo\Socrata\SodaDataset;
use allejo\Socrata\SoqlQuery;
// If someone has pushed the "Submit" button, this'll be set to true
$postBack = $_SERVER['REQUEST_METHOD'] == 'POST';
if ($postBack) {
    // Our client will store information about the host, token, and authentication (if necessary)
    $sc = new SodaClient("data.seattle.gov", "B0ixMbJj4LuQVfYnz95Hfp3Ni");
    $ds = new SodaDataset($sc, "pu5n-trf4");
    // Build a SoqlQuery with functions
    $soql = new SoqlQuery();
    $soql->where("within_circle(incident_location, {$_POST['latitude']}, {$_POST['longitude']}, {$_POST['range']})")->limit(20);
    // Get the dataset. $results is now an associative array in the same format as the JSON object
    $results = $ds->getDataset($soql);
}
?>

<html>
    <head>
        <title>Seattle Police Department 911 Incident Response</title>
    </head>
    <body>
        <h1>Seattle Police Department 911 Incident Response</h1>

        <?php 
if (!$postBack) {