soda-ruby 0.2.22 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/soda/client.rb +16 -13
- data/lib/soda/version.rb +1 -1
- metadata +5 -20
- data/README.mkd +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 778c87a4294f9311d752ddcc8df487549b84c467f10e88d73981694ed3599790
|
4
|
+
data.tar.gz: 898adb8fa65dd8f869429b9f72c9199039631053838132e60fb24880cb92b6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04dc1e34fb728e0a6e76b5ab4662eeef5ddd4f60740131829213f272d68c983fdf0f6b9511799610aa9279724b3b007e4445508519f7f04a0285f5c7492fb7bf
|
7
|
+
data.tar.gz: 686adfbd9c0efa77bf2b5c86d42d131ac28793b7cab2f35459ce912c67b62d5b83a9aafd284efba564ecff590f984af0f9add23956c54851613302024f522676
|
data/lib/soda/client.rb
CHANGED
@@ -182,22 +182,24 @@ module SODA
|
|
182
182
|
"https://#{@config[:domain]}#{resource}#{extension}"
|
183
183
|
end
|
184
184
|
|
185
|
+
# Returns a response with a parsed body
|
185
186
|
def handle_response(response)
|
186
187
|
# Check our response code
|
187
188
|
check_response_fail(response)
|
188
|
-
if blank?(response.body)
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
response = JSON.parse(response.body, :
|
193
|
-
if response.is_a? Array
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
189
|
+
return nil if blank?(response.body)
|
190
|
+
|
191
|
+
# Return a bunch of mashes as the body if we're JSON
|
192
|
+
begin
|
193
|
+
response.body = JSON.parse(response.body, max_nesting: false)
|
194
|
+
response.body = if response.body.is_a? Array
|
195
|
+
response.body.map { |r| Hashie::Mash.new(r) }
|
196
|
+
else
|
197
|
+
Hashie::Mash.new(response.body)
|
198
|
+
end
|
199
|
+
rescue => exception
|
200
|
+
raise "JSON parsing failed. Error details: #{exception}"
|
201
|
+
ensure
|
202
|
+
return response
|
201
203
|
end
|
202
204
|
end
|
203
205
|
|
@@ -265,6 +267,7 @@ module SODA
|
|
265
267
|
http = Net::HTTP.new(host, port)
|
266
268
|
http.use_ssl = true
|
267
269
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @config[:ignore_ssl]
|
270
|
+
http.open_timeout = @config[:timeout] if @config[:timeout]
|
268
271
|
http.read_timeout = @config[:timeout] if @config[:timeout]
|
269
272
|
http.set_debug_output(@config[:debug_stream]) if @config[:debug_stream]
|
270
273
|
http
|
data/lib/soda/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soda-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Metcalf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: '3.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: '3.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multipart-post
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.2
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activesupport
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 4.2.5
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 4.2.5
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: bundler
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,7 +186,6 @@ extensions: []
|
|
200
186
|
extra_rdoc_files: []
|
201
187
|
files:
|
202
188
|
- LICENSE
|
203
|
-
- README.mkd
|
204
189
|
- lib/omniauth-socrata.rb
|
205
190
|
- lib/soda.rb
|
206
191
|
- lib/soda/client.rb
|
@@ -225,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
210
|
version: 1.3.6
|
226
211
|
requirements: []
|
227
212
|
rubyforge_project: soda-ruby
|
228
|
-
rubygems_version: 2.
|
213
|
+
rubygems_version: 2.7.6
|
229
214
|
signing_key:
|
230
215
|
specification_version: 4
|
231
216
|
summary: Ruby for SODA 2.0
|
data/README.mkd
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
|
2
|
-
[](https://ci.appveyor.com/project/chrismetcalf/soda-ruby)
|
3
|
-
[](https://travis-ci.org/socrata/soda-ruby)
|
4
|
-
|
5
|
-
For more details and for documentation, check out <http://socrata.github.io/soda-ruby> or our [developer portal](http://dev.socrata.com).
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
SODA is distributed as a gem, which is how it should be used in your app.
|
10
|
-
|
11
|
-
Include the gem and hashie in your Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'soda-ruby', :require => 'soda'
|
15
|
-
```
|
16
|
-
|
17
|
-
### Important Note!
|
18
|
-
|
19
|
-
In order to access the SODA API via HTTPS, clients must now [support the Server Name Indication (SNI)](https://dev.socrata.com/changelog/2016/08/24/sni-now-required-for-https-connections.html) 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](https://en.wikipedia.org/wiki/Server_Name_Indication), 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.
|
20
|
-
|
21
|
-
## Quick Start
|
22
|
-
|
23
|
-
Create a new client. Register for an application token at <http://dev.socrata.com/register>.
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
client = SODA::Client.new({:domain => "explore.data.gov", :app_token => "CGxadgoQlgQSev4zyUh5aR5J3"})
|
27
|
-
```
|
28
|
-
|
29
|
-
Issue a filter query. `644b-gaut` is the identifier for the dataset we want to access. The return object is an array of [Hashie::Mash](https://github.com/intridea/hashie) objects:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
response = client.get("644b-gaut", {"$limit" => 1, :namelast => "WINFREY", :namefirst => "OPRAH"})
|
33
|
-
|
34
|
-
#=> [#<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">]
|
35
|
-
```
|
36
|
-
|
37
|
-
You can use other simple query SoQL methods found here: <http://dev.socrata.com/docs/queries.html>
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
client = SODA::Client.new({:domain => "soda.demo.socrata.com"})
|
41
|
-
magnitude_response = client.get("4tka-6guv", {"$where" => "magnitude > '3.0'"})
|
42
|
-
|
43
|
-
#=> [#<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">, ... ]
|
44
|
-
|
45
|
-
datetime_response = client.get("4tka-6guv", {"$where" => "datetime > '2012-09-14T09:28:55' AND datetime < '2012-12-25T09:00:00'"})
|
46
|
-
|
47
|
-
#=> [#<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">, ... ]
|
48
|
-
```
|
49
|
-
|
50
|
-
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!
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
client = SODA::Client.new({:domain => "soda.demo.socrata.com"})
|
54
|
-
magnitude_response = client.get("https://soda.demo.socrata.com/resource/4tka-6guv.json", {"$where" => "magnitude > '3.0'"})
|
55
|
-
```
|
56
|
-
|
57
|
-
All the field names have built in getter methods since the objects are Hashie::Mashes.
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
magnitude_response.first.number_of_stations #=> "6"
|
61
|
-
```
|
62
|
-
*Note that the return value is a string object.*
|