Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 1.63 KB

README.md

File metadata and controls

39 lines (25 loc) · 1.63 KB

Socrata - Basic PHP Library Updated 2014-07-22, Chris Metcalf, chris.metcalf (at) socrata.com

This library provides a simple wrapper for accessing some of the features of the Socrata Open Data API from PHP. Currently it supports HTTP GET, POST, and PUT operations.

The library is very simple. To access the Socrata API, you first instantiate a "Socrata" object, passing in the API base URL for the data site you wish to access. The Base URL is always the URL for the root of the datasite (ex: http://data.medicare.gov). Then you can use its included methods to make simple API calls:

$socrata = new Socrata("https://data.medicare.gov");
$response = $socrata->get("/resource/abcd-2345.json");

Querying

Simple filters and SoQL Queries can be passed as a parameter to the get function:

$socrata = new Socrata("https://data.austintexas.gov", $app_token);

$params = array("\$where" => "within_circle(location, $latitude, $longitude, $range)");

$response = $socrata->get("/resource/$view_uid.json", $params);

Publishing

To use the library to publish data you can use the PUT (replace) or POST (upsert) methods:

$socrata = new Socrata("https://data.medicare.gov", $app_token, $user_name, $password);

// Publish data via 'upsert'
$response = $socrata->post("/resource/abcd-2345.json", $data_as_json);

// Publish data via 'replace'
$response = $socrata->put("/resource/abcd-2345.json", $data_as_json);

The library also includes a simple example application, which retrieves rows from a dataset and dumps them in a simple table.