clientele 0.3.7 → 0.3.8

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: 87bc7d61e47a39881cd03d0d2e1f4bb023bc6a77
4
- data.tar.gz: ecf6d0bc7f9273140438fe915f7485bca663f489
3
+ metadata.gz: c007e157b3b34fbc7d0527566670837e910f33da
4
+ data.tar.gz: 7ed13ea38b32be707dee5ba56fe81a2166d33bae
5
5
  SHA512:
6
- metadata.gz: fcd2499a0aa2d47f34b52129cc3db141be7012ef5c9607ed96c482b2f4a2a81e74518668beae10e771e6ac5c5981a05338b3c92ecfee3e081c7f2a286545ba15
7
- data.tar.gz: 4eb4de1043f19967b2197df9e13977122f0ef1a0ed2bbba374925c288e8b760f825d747090a7384bcacc1b1971e087c6d96ea45a033afdf9f093f81918975a15
6
+ metadata.gz: 80785216d87f2da664a61cf762f22a788d7da55de2c09b762f7f2f369b0c011fa940a1f5cc18c801c988d87a71cb3025dab776125e7dcd441c6f3311bbc30ac9
7
+ data.tar.gz: 30d5360b2d15203a67692f1f43b8ffeaea271572ea7aee16c3c39158efba48f16fd90010cfc12ad339344ef033188d5a158c115584aa12cfd1fda2fdcf6d8a10
@@ -79,11 +79,11 @@ module Clientele
79
79
  private
80
80
 
81
81
  def result
82
- Response.new response, client: client, resource: resource
82
+ Response.build(response, resource, client)
83
83
  end
84
84
 
85
85
  def response
86
- faraday_client.send(verb, ensure_trailing_slash(path)) do |request|
86
+ @response ||= faraday_client.send(verb, ensure_trailing_slash(path)) do |request|
87
87
  request.headers = options.fetch(:headers, {}).merge(headers)
88
88
  request.params = deep_camelize_keys(query)
89
89
  request.body = JSON.dump(deep_camelize_keys(body))
@@ -66,19 +66,26 @@ module Clientele
66
66
  @nested_plural_key || plural_key
67
67
  end
68
68
 
69
- def build(data, client: nil, klass: nil)
70
- if (klass or data).kind_of? Array
71
- data.map do |dataset|
72
- build dataset, client: client
73
- end
74
- elsif (klass or data).kind_of? Hash and data.keys.map(&:to_s).include? result_key.to_s
75
- build data.send result_key, client: client
76
- elsif (klass or data).kind_of? Hash and data.keys.map(&:to_s).include? plural_key.to_s
77
- build data.send plural_key, client: client
78
- else
79
- new(data).tap do |instance|
80
- instance.instance_variable_set :@client, client if client
69
+ def build(data, client: nil, response: nil)
70
+ new(
71
+ catch(:build) do
72
+ if data.kind_of? Hash
73
+ if data.keys.map(&:to_s).include? plural_key.to_s
74
+ build data.fetch(plural_key), client: client, response: response
75
+ elsif data.keys.map(&:to_s).include? result_key.to_s
76
+ throw :build, data.fetch(result_key)
77
+ else
78
+ throw :build, data
79
+ end
80
+ elsif data.respond_to? :map
81
+ data.map do |dataset|
82
+ build dataset, client: client, response: response
83
+ end
84
+ end
81
85
  end
86
+ ).tap do |instance|
87
+ instance.instance_variable_set :@client, client if client
88
+ instance.instance_variable_set :@response, response if response
82
89
  end
83
90
  end
84
91
 
@@ -92,5 +99,7 @@ module Clientele
92
99
 
93
100
  end
94
101
 
102
+ attr_accessor :response
103
+
95
104
  end
96
105
  end
@@ -6,28 +6,19 @@ module Clientele
6
6
 
7
7
  class Response < SimpleDelegator
8
8
 
9
- attr_reader :response
10
- def initialize(response, client: nil, resource: nil)
11
- @response = response
12
- super(
9
+ class << self
10
+ def build(response, resource, client)
13
11
  if resource
14
- resource.build response.body, client: client, klass: response.body.class
12
+ resource.build(response.body, response: response, client: client)
15
13
  else
16
- response.body
14
+ new response
17
15
  end
18
- )
19
- end
20
-
21
- def respond_to_missing?(method_name, include_private=false)
22
- @response.respond_to?(method_name, include_private) or super
16
+ end
23
17
  end
24
18
 
25
- def method_missing(method_name, *args, &block)
26
- begin
27
- super
28
- rescue NoMethodError
29
- @response.send method_name, *args, &block
30
- end
19
+ attr_reader :response
20
+ def initialize(response)
21
+ super @response = response
31
22
  end
32
23
 
33
24
  end
@@ -1,3 +1,3 @@
1
1
  module Clientele
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clientele
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Keele