soda-ruby 0.2.18 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.mkd +7 -0
- data/lib/soda/client.rb +24 -8
- data/lib/soda/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02d3559111d07cf16cb51d2e2ed9324cb45679ac
|
4
|
+
data.tar.gz: 13ea33266e56d7c05761ff0b978e7c076859b44c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c447fd8cf0ffd2a7ebfd73c112e4cd17c47c5874f90312386bcc0afa371914d7fd60e55c1d9d2ffbd9477a17221747d2cea743c075daa9dbdc4c23111a0aaaa
|
7
|
+
data.tar.gz: 500e60cdd207ca6ee117cab2b6790789f12d9115d14a5c990d27f06f0315398f25477eaf8f0e27365611c7c516514a46e9ddd66850af2670f28ac4757fef4af2
|
data/README.mkd
CHANGED
@@ -42,6 +42,13 @@ datetime_response = client.get("4tka-6guv", {"$where" => "datetime > '2012-09-14
|
|
42
42
|
#=> [#<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">, ... ]
|
43
43
|
```
|
44
44
|
|
45
|
+
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!
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
client = SODA::Client.new({:domain => "soda.demo.socrata.com"})
|
49
|
+
magnitude_response = client.get("https://soda.demo.socrata.com/resource/4tka-6guv.json", {"$where" => "magnitude > '3.0'"})
|
50
|
+
```
|
51
|
+
|
45
52
|
All the field names have built in getter methods since the objects are Hashie::Mashes.
|
46
53
|
|
47
54
|
```ruby
|
data/lib/soda/client.rb
CHANGED
@@ -132,9 +132,15 @@ module SODA
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def post_form(resource, body = {}, params = {})
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
# We'll combine any params we got from our base resource with
|
136
|
+
# those passed in
|
137
|
+
base = URI.parse(parse_resource(resource))
|
138
|
+
query = [
|
139
|
+
base.query,
|
140
|
+
query_string(params)
|
141
|
+
].reject { |s| s.nil? || s.empty? }.join "&"
|
142
|
+
|
143
|
+
uri = URI.parse("https://#{base.host}#{base.path}?#{query}")
|
138
144
|
|
139
145
|
request = Net::HTTP::Post.new(uri.request_uri)
|
140
146
|
add_default_headers_to_request(request)
|
@@ -155,7 +161,10 @@ module SODA
|
|
155
161
|
params.map { |key, val| "#{key}=#{CGI.escape(val.to_s)}" }.join('&')
|
156
162
|
end
|
157
163
|
|
158
|
-
def
|
164
|
+
def parse_resource(resource)
|
165
|
+
# If our resource starts with HTTPS, assume they've passed in a full URI
|
166
|
+
return resource if resource.start_with?("https://")
|
167
|
+
|
159
168
|
# If we didn't get a full path, assume "/resource/"
|
160
169
|
resource = '/resource/' + resource unless resource.start_with?('/')
|
161
170
|
|
@@ -166,7 +175,8 @@ module SODA
|
|
166
175
|
extension = matches.captures[1]
|
167
176
|
end
|
168
177
|
|
169
|
-
|
178
|
+
raise "No base domain specified!" unless @config[:domain]
|
179
|
+
return "https://#{@config[:domain]}#{resource}#{extension}"
|
170
180
|
end
|
171
181
|
|
172
182
|
def handle_response(response)
|
@@ -204,9 +214,15 @@ module SODA
|
|
204
214
|
def connection(method = 'Get', resource = nil, body = nil, params = {})
|
205
215
|
method = method.to_sym.capitalize
|
206
216
|
|
207
|
-
|
208
|
-
|
209
|
-
|
217
|
+
# We'll combine any params we got from our base resource with
|
218
|
+
# those passed in
|
219
|
+
base = URI.parse(parse_resource(resource))
|
220
|
+
query = [
|
221
|
+
base.query,
|
222
|
+
query_string(params)
|
223
|
+
].reject { |s| s.nil? || s.empty? }.join "&"
|
224
|
+
|
225
|
+
uri = URI.parse("https://#{base.host}#{base.path}?#{query}")
|
210
226
|
|
211
227
|
request = eval("Net::HTTP::#{method}").new(uri.request_uri)
|
212
228
|
add_default_headers_to_request(request)
|
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.2.
|
4
|
+
version: 0.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Metcalf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: A simple wrapper for SODA 2.0. Includes an OmniAuth provider for OAuth
|
168
182
|
2.0
|
169
183
|
email: chris.metcalf@socrata.com
|