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 +4 -4
- data/lib/clientele/request.rb +2 -2
- data/lib/clientele/resource.rb +21 -12
- data/lib/clientele/response.rb +8 -17
- data/lib/clientele/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c007e157b3b34fbc7d0527566670837e910f33da
|
4
|
+
data.tar.gz: 7ed13ea38b32be707dee5ba56fe81a2166d33bae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80785216d87f2da664a61cf762f22a788d7da55de2c09b762f7f2f369b0c011fa940a1f5cc18c801c988d87a71cb3025dab776125e7dcd441c6f3311bbc30ac9
|
7
|
+
data.tar.gz: 30d5360b2d15203a67692f1f43b8ffeaea271572ea7aee16c3c39158efba48f16fd90010cfc12ad339344ef033188d5a158c115584aa12cfd1fda2fdcf6d8a10
|
data/lib/clientele/request.rb
CHANGED
@@ -79,11 +79,11 @@ module Clientele
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def result
|
82
|
-
Response.
|
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))
|
data/lib/clientele/resource.rb
CHANGED
@@ -66,19 +66,26 @@ module Clientele
|
|
66
66
|
@nested_plural_key || plural_key
|
67
67
|
end
|
68
68
|
|
69
|
-
def build(data, client: nil,
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
data/lib/clientele/response.rb
CHANGED
@@ -6,28 +6,19 @@ module Clientele
|
|
6
6
|
|
7
7
|
class Response < SimpleDelegator
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
@response = response
|
12
|
-
super(
|
9
|
+
class << self
|
10
|
+
def build(response, resource, client)
|
13
11
|
if resource
|
14
|
-
resource.build
|
12
|
+
resource.build(response.body, response: response, client: client)
|
15
13
|
else
|
16
|
-
response
|
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
|
-
|
26
|
-
|
27
|
-
|
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
|
data/lib/clientele/version.rb
CHANGED