Skip to content

Instantly share code, notes, and snippets.

@phillipsj
Created May 31, 2012 13:48
Show Gist options
  • Save phillipsj/2843525 to your computer and use it in GitHub Desktop.
Save phillipsj/2843525 to your computer and use it in GitHub Desktop.
Example of working with Socrata API using Ruby
require 'faraday_middleware'
require 'json'
connection = Faraday.new 'http://data.austintexas.gov' do |conn|
conn.request :json
conn.response :json, :content_type => /\bjson$/
conn.adapter Faraday.default_adapter
end
response = connection.post do |req|
req.url '/api/views/INLINE/rows.json?method=getRows&start=0&length=1000'
#req.options[:method] = 'getRows'
req.headers['Content-Type'] = 'application/json'
req.headers['X-App-Token'] = '<insert your app token here>'
req.body = '{ "originalViewId": "ecmv-9xxi", "name": "Range", "query": { "filterCondition": { "type": "operator", "value": "BETWEEN", "children": [{
"columnId": 10289371, "type": "column" }, { "type": "literal", "value": "05/01/2012" }, { "type": "literal", "value": "05/03/2012" }]}}}'
end
results = response.body
puts results.count
first = results[0]
puts first['sid']
@phillipsj
Copy link
Author

This examples shows how to use the SODA API to query the restaurant score data by a date range.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment