scorpio 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22844b5d53c060f169a666bb1d0d2648cd82248b
4
- data.tar.gz: 8b5a502e30aa099bdefed739a3be484eaf554f0e
3
+ metadata.gz: ec3a7a7b122c8c4b3791f1b22db539efd241dc33
4
+ data.tar.gz: dbdf6eeaf02f1830326aa4e1ec0c10649fd1107e
5
5
  SHA512:
6
- metadata.gz: 1ae0e2820929636321a1dfd4b6cfaf155d45ed3b9bff22f11a6d21a35e6ded3b0e51b5499833e8e097f8bdd2f20d6b29348b29de25573b10dc2a2b91b16c5dce
7
- data.tar.gz: 0f52f15981cf3e840c6381100afb59b8aad162e8ee6d906e5b95352050ad49ff2ea916d4e931a824f681d1e2b2985f9d9b9b42cddc9c05adf84c97fd6d4adafb
6
+ metadata.gz: 623f45a68e0d16d10bd561f8d511c45a842f0f456a34f3a4ae0acae75ad1b4800af9ca3ca36eb8119d07e370975a5ce97c38455a216021a3f2ddd96677259197
7
+ data.tar.gz: 14d553f686f25457c4e7257d8dee188b4d3c5ed4fef4646d041b9eef23eafaddcd2ed231c4d1a1348b4c5c8846c18f5905b350077ccc4677452423b0df821afb
@@ -189,13 +189,14 @@ module Scorpio
189
189
  end
190
190
 
191
191
  def call_api_method(method_name, call_params: nil, model_attributes: nil)
192
- call_params = Scorpio.stringify_symbol_keys(call_params || {})
192
+ call_params = Scorpio.stringify_symbol_keys(call_params) if call_params.is_a?(Hash)
193
193
  model_attributes = Scorpio.stringify_symbol_keys(model_attributes || {})
194
194
  method_desc = api_description['resources'][self.resource_name]['methods'][method_name]
195
195
  http_method = method_desc['httpMethod'].downcase.to_sym
196
196
  path_template = Addressable::Template.new(method_desc['path'])
197
- template_params = model_attributes.merge(call_params)
198
- missing_variables = path_template.variables - call_params.keys - model_attributes.keys
197
+ template_params = model_attributes
198
+ template_params = template_params.merge(call_params) if call_params.is_a?(Hash)
199
+ missing_variables = path_template.variables - template_params.keys
199
200
  if missing_variables.any?
200
201
  raise(ArgumentError, "path #{method_desc['path']} for method #{method_name} requires attributes " +
201
202
  "which were missing: #{missing_variables.inspect}")
@@ -209,21 +210,34 @@ module Scorpio
209
210
  url = Addressable::URI.parse(base_url) + path
210
211
  # assume that call_params must be included somewhere. model_attributes are a source of required things
211
212
  # but not required to be here.
212
- other_params = call_params.reject { |k, _| path_template.variables.include?(k) }
213
+ other_params = call_params
214
+ if other_params.is_a?(Hash)
215
+ other_params.reject! { |k, _| path_template.variables.include?(k) }
216
+ end
213
217
 
214
218
  method_desc = (((api_description['resources'] || {})[resource_name] || {})['methods'] || {})[method_name]
215
219
  request_schema = deref_schema(method_desc['request'])
216
220
  if request_schema
217
221
  # TODO deal with model_attributes / call_params better in nested whatever
218
- body = request_body_for_schema(model_attributes.merge(call_params), request_schema)
219
- body.update(call_params)
222
+ if call_params.nil?
223
+ body = request_body_for_schema(model_attributes, request_schema)
224
+ elsif call_params.is_a?(Hash)
225
+ body = request_body_for_schema(model_attributes.merge(call_params), request_schema)
226
+ body.update(call_params)
227
+ else
228
+ body = call_params
229
+ end
220
230
  else
221
- if other_params.any?
222
- if METHODS_WITH_BODIES.any? { |m| m == http_method.downcase }
231
+ if other_params
232
+ if METHODS_WITH_BODIES.any? { |m| m.to_s == http_method.downcase.to_s }
223
233
  body = other_params
224
234
  else
225
- # TODO pay more attention to 'parameters' api method attribute
226
- url.query_values = other_params
235
+ if other_params.is_a?(Hash)
236
+ # TODO pay more attention to 'parameters' api method attribute
237
+ url.query_values = other_params
238
+ else
239
+ raise
240
+ end
227
241
  end
228
242
  end
229
243
  end
@@ -244,7 +258,8 @@ module Scorpio
244
258
  end
245
259
 
246
260
  response_schema = method_desc['response']
247
- response_object_to_instances(response.body, response_schema, 'persisted' => true)
261
+ source = {'method_name' => method_name, 'call_params' => call_params, 'url' => url.to_s}
262
+ response_object_to_instances(response.body, response_schema, 'persisted' => true, 'source' => source)
248
263
  end
249
264
 
250
265
  def request_body_for_schema(object, schema)
@@ -1,3 +1,3 @@
1
1
  module Scorpio
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday