Created
May 31, 2012 13:48
-
-
Save phillipsj/2843525 to your computer and use it in GitHub Desktop.
Example of working with Socrata API using Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This examples shows how to use the SODA API to query the restaurant score data by a date range.