Skip to content

CommunityData/PhpSoda

 
 

Repository files navigation

PhpSoda Stable Release Build Status Scrutinizer Code Quality Coverage Status

A PHP library for working with the Socrata API. Provided as an alternative to Socrata's official implementation, this library takes more of an object-oriented approach to working with the API instead of manually creating requests and aims to fill some of the short-comings of the official library.

This library fully supports interacting with the API by getting datasets and handling tokens/authentication in order to write or modify datasets.

Requirements

  • PHP 5.3+

Installation

This library is available on Packagist as allejo/php-soda, add it using Composer.

You're not using Composer? Don't worry, this library is also provided as a Phar archive for you include in your code. Get the latest Phar archive from our Releases.

Check out our wiki article if you require assistance with using this library.

Sample Usage

Here are some quick examples on how PhpSoda works, but there's a lot more you can do. Check out our wiki to see everything else.

Get a dataset

// Create a client with information about the API to handle tokens and authentication
$sc = new SodaClient("opendata.socrata.com");

// Access a dataset based on the API end point
$ds = new SodaDataset($sc, "pkfj-5jsd");

// Create a SoqlQuery that will be used to filter out the results of a dataset
$soql = new SoqlQuery();

// Write a SoqlQuery naturally
$soql->select("date_posted", "state", "sample_type")
     ->where("state = 'AR'")
     ->limit(1);

// Fetch the dataset into an associative array
$results = $ds->getDataset($soql);

Updating a dataset

// Create a client with information about the API to handle tokens and authentication
$sc = new SodaClient("opendata.socrata.com", "<token here>", "email@example.com", "password");

// The dataset to upload
$data = file_get_contents("dataset.json");

// Access a dataset based on the API end point
$ds = new SodaDataset($sc, "1234-abcd");

// To upsert a dataset
$ds->upsert($data);

// To replace a dataset
$ds->replace($data);

Getting Help

To get help, see if our wiki has any information regarding your question. If the wiki can't help you, you may either create an issue or stop by IRC; I'm available on IRC as "allejo" so feel free to ping me. I recommend creating an issue in case others have the same question but for quick help, IRC works just fine.

To report a bug or request a feature, please submit an issue.

IRC

Channel: #socrata-soda
Network: irc.freenode.net

Thank You

License

PhpSoda - A PHP library for the Socrata API
Copyright (C) 2015 Vladimir "allejo" Jimenez

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

About

A PHP library for working with the Socrata API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.9%
  • Shell 0.1%