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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b31234fb24d9b3e2a6e895c687f8c5036b8c2f9
4
- data.tar.gz: 4b60658e6a62db5cf3c42a74819c0018b32059a5
3
+ metadata.gz: 02d3559111d07cf16cb51d2e2ed9324cb45679ac
4
+ data.tar.gz: 13ea33266e56d7c05761ff0b978e7c076859b44c
5
5
  SHA512:
6
- metadata.gz: 4e27a9b90898ec21331984a8ac4b7d79db6516ceb7d047e8a8c3fac9f3dc6383ffa65e1e48a1ebb205d22b2573d357fb10fe3890d775df84d858590973863e36
7
- data.tar.gz: 69117b56f9280ffeea188b074c0409f7835e36f3f250e6be302c20830675b627b899687c21bf83ce9fac62feb6125206ee9b9ea8d08ddac770eca12429c3e40c
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
- query = query_string(params)
136
- path = resource_path(resource)
137
- uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
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 resource_path(resource)
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
- resource + extension
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
- query = query_string(params)
208
- path = resource_path(resource)
209
- uri = URI.parse("https://#{@config[:domain]}#{path}?#{query}")
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
@@ -1,3 +1,3 @@
1
1
  module SODA
2
- VERSION = '0.2.18'
2
+ VERSION = '0.2.19'
3
3
  end
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.18
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-04 00:00:00.000000000 Z
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