• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A RubyGem for the Socrata Open Data API

Build status Build Status

For more details and for documentation, check out http://socrata.github.io/soda-ruby or our developer portal.

Installation

SODA is distributed as a gem, which is how it should be used in your app.

Include the gem and hashie in your Gemfile:

gem 'soda-ruby', :require => 'soda'

Important Note!

In order to access the SODA API via HTTPS, clients must now support the Server Name Indication (SNI) extension to the TLS protocol. What does this mean? It means that if you're using soda-ruby, you must use Ruby 2.0.0 or above, as that is when net/http introduced support for SNI. 2.0.0 was released in 2011, so most up-to-date platforms will be on version 2.0 or greater.

Quick Start

Create a new client. Register for an application token at http://dev.socrata.com/register.

client = SODA::Client.new({:domain => "explore.data.gov", :app_token => "CGxadgoQlgQSev4zyUh5aR5J3"})

Issue a filter query. 644b-gaut is the identifier for the dataset we want to access.

As of version 1.0.0+

The return object is the complete response object with a pre parsed body. The response.body object is an array of [Hashie::Mash].

If you are upgrading from a version < 1.0.0 The previous object returned is now the response.body object.

Prior to version 1 (<1.0.0)

The return object is an array of [Hashie::Mash] that represents the body of the response.

(https://github.com/intridea/hashie) objects:

response = client.get("644b-gaut", {"$limit" => 1, :namelast => "WINFREY", :namefirst => "OPRAH"})

 #=> [#<Hashie::Mash appt_end_date="12/3/09 23:59" appt_made_date="12/2/09 18:05" appt_start_date="12/3/09 9:30" caller_name_first="SALLY" caller_name_last="ARMBRUSTER" last_updatedby="J7" lastentrydate="12/2/09 18:05" meeting_loc="WH" meeting_room="DIP ROOM" namefirst="OPRAH" namelast="WINFREY" post="WIN" release_date=1269586800 terminal_suffix="J7" total_people="10" type_of_access="VA" uin="U60816" visitee_namefirst="SEMONTI" visitee_namelast="STEPHENS">]

You can use other simple query SoQL methods found here: http://dev.socrata.com/docs/queries.html

client = SODA::Client.new({:domain => "soda.demo.socrata.com"})
magnitude_response = client.get("4tka-6guv", {"$where" => "magnitude > '3.0'"})

#=> [#<Hashie::Mash datetime="2012-09-14T09:28:55" depth="20" earthquake_id="12258012" location=#<Hashie::Mash latitude="19.7859" longitude="-64.0849" needs_recoding=false> magnitude="3.1" number_of_stations="6" region="north of the Virgin Islands" source="pr" version="0">, #<Hashie::Mash datetime="2012-09-14T07:58:39" depth="74" earthquake_id="12258011" location=#<Hashie::Mash latitude="19.5907" longitude="-64.1723" needs_recoding=false> magnitude="3.3" number_of_stations="4" region="Virgin Islands region" source="pr" version="0">, ... ]

datetime_response = client.get("4tka-6guv", {"$where" => "datetime > '2012-09-14T09:28:55' AND datetime < '2012-12-25T09:00:00'"})

#=> [#<Hashie::Mash datetime="2012-09-14T10:10:19" depth="8.2" earthquake_id="00388609" location=#<Hashie::Mash latitude="36.9447" longitude="-117.6778" needs_recoding=false> magnitude="1.7" number_of_stations="29" region="Northern California" source="nn" version="9">, #<Hashie::Mash datetime="2012-09-14T10:06:11" depth="6.4" earthquake_id="00388607" location=#<Hashie::Mash latitude="36.9417" longitude="-117.6903" needs_recoding=false> magnitude="1.7" number_of_stations="29" region="Central California" source="nn" version="9">, ... ]

You can also provide a full URI to an API endpoint instead of specifying the ID. Just copy and paste the dataset URI from the API documentation!

client = SODA::Client.new({:domain => "soda.demo.socrata.com"})
magnitude_response = client.get("https://soda.demo.socrata.com/resource/4tka-6guv.json", {"$where" => "magnitude > '3.0'"})

All the field names have built in getter methods since the objects are Hashie::Mashes.

magnitude_response.first.number_of_stations   #=> "6"

Note that the return value is a string object.

Contribution

How to Publish

Raw ruby-gems publishing information can be found at https://guides.rubygems.org/publishing/.

  1. First you must publish with a soda-ruby maintainer account. Please use the tylsvc-rubygems rubygems.org account located in lasspass. If you do not see it in lasspass, please reach out to a lasspass admin in order to get access.

  2. After finding the account, proceed to your local soda-ruby project directory. Update the version of the file project inside the soda.gemspec file, under s.version = '1.0.1'. This project uses semantic versioning, learn more here https://semver.org/.

  3. Now build the gem by running gem build soda.gemspec. It should output a file with the name soda-ruby-VERSION_NUMBER.gem.

  4. Then to publish the gem run gem publish soda-ruby-VERSION_NUMBER.gem. Please insert the correct VERSION_NUMBER. This is where gems prompt for the tylsvc-rubygems user name and password.

Congrats! The gem should now be published.

More Repositories

1

soda-js

A Javascript-based library for accessing the SODA2 API.
JavaScript
171
star
2

socrata-py

socrata data-pipeline python library
Python
87
star
3

datasync

Desktop / Console application for updating Socrata datasets automatically.
Java
76
star
4

soda-java

This is the Java API for the SODA 2.0 API
Java
70
star
5

soda-php

A simple library to make it easier to access SODA services from PHP
PHP
64
star
6

dev.socrata.com

Socrata Developer Site
Jupyter Notebook
61
star
7

soda-ios-sdk

Objective-C
47
star
8

soda-swift

SODA SDK for Apple's Swift programming language
Swift
46
star
9

soda-android-sdk

Java
35
star
10

opendatanetwork.com

The Open Data Network
JavaScript
19
star
11

soda-scala

Native Scala API for SODA2
Scala
17
star
12

shipyard

An open-sourced collection of docker images that probably don't merit their own git repo, but serve as building blocks or one-off utilities.
Dockerfile
12
star
13

connectors

ETL Tools and Templates
Python
11
star
14

discuss

Discuss all the things!
10
star
15

socrata-kettle

Socrata plug-in for Pentaho Kettle
Java
10
star
16

presentations

Presentations by @chrismetcalf at hackathons, conferences, and other Open Data events
HTML
9
star
17

odn-backend

Backend for the Open Data Network.
JavaScript
9
star
18

exkml

kml parser
Elixir
7
star
19

data-studio-connector

Google Data Studio connector to public Socrata dataset
JavaScript
7
star
20

labs-common-jekyll

HTML
6
star
21

snuffleupadata.com

Home of @socrata's mascot, Snuffleupadata
HTML
4
star
22

oauth_sample_app_ruby

A sample app to show how to connect to the Socrata Open Data API using the OAuth2 Rubygem
Ruby
4
star
23

python-release-plugin

A Python setuptools plugin to simplify the release process for Python modules
Python
4
star
24

cdc-indicator

Chronic Disease Indicator App
JavaScript
3
star
25

Socrata

Python
2
star
26

spark-etl-experiment

how to spend 2 days mostly waiting for sbt, reading tracebacks & desperately googling
Elm
2
star
27

cms-plan-finder-automation

Python-based workflow to automate daily release of CMS Plan Finder data
Python
2
star
28

thank-a-govie.com

Ruby
2
star
29

labs-common

Common resources for Jekyll web projects
JavaScript
2
star
30

eurybates

Consumer & producer library for many-to-many communication over ActiveMQ or Kafka
Scala
2
star
31

publishing_api_examples

Examples using Python and the sodapy library to publish and update datasets
Jupyter Notebook
2
star
32

kibana

Monitoring for the Elastic stack. Primary source can be found here: https://github.com/elastic/kibana
Shell
1
star
33

Socrata-PowerShell

PowerShell module for creating and updating datasets on a Socrata domain
PowerShell
1
star
34

arcs

A Python library for Assessing Relevance of our Catalog Search system.
Python
1
star
35

python-101

An introduction to programming using Python for non-engineers.
Python
1
star