client-api-builder 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/client-api-builder.gemspec +1 -1
- data/lib/client_api_builder/router.rb +28 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d181593590629e548b61b096cf47322584fd943002972d002d6104348628af7
|
4
|
+
data.tar.gz: 01a9168981928f32c6a64a0315dce7227c2153a4b75bfb1e9192a69f1bc80785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7eec7746486022b3f92e01a96a49057299cb2a4f6afd9b763ba4214bd6c61d79f0c2d6e4e2447a302a7751939628881dca83b274cbf4efc5a8f70b582d2ecc4
|
7
|
+
data.tar.gz: 2b4729698266b975556d13b717fd6ea5224f2da79379e2f1225058b1bc03e2a20d20be7228ff4d7c181e0275529577f46cf183dcddd271efb08a95f8490ea9b8
|
data/client-api-builder.gemspec
CHANGED
@@ -22,6 +22,7 @@ module ClientApiBuilder
|
|
22
22
|
base_url: nil,
|
23
23
|
headers: {},
|
24
24
|
connection_options: {},
|
25
|
+
query_params: {},
|
25
26
|
query_builder: Hash.method_defined?(:to_query) ? :to_query : :query_params
|
26
27
|
}.freeze
|
27
28
|
end
|
@@ -50,6 +51,12 @@ module ClientApiBuilder
|
|
50
51
|
add_value_to_class_method(:default_options, connection_options: connection_options)
|
51
52
|
end
|
52
53
|
|
54
|
+
def query_param(name, value)
|
55
|
+
query_params = default_options[:query_params].dup
|
56
|
+
query_params[name] = value || block
|
57
|
+
add_value_to_class_method(:default_options, query_params: query_params)
|
58
|
+
end
|
59
|
+
|
53
60
|
def headers
|
54
61
|
default_options[:headers]
|
55
62
|
end
|
@@ -58,6 +65,10 @@ module ClientApiBuilder
|
|
58
65
|
default_options[:connection_options]
|
59
66
|
end
|
60
67
|
|
68
|
+
def query_params
|
69
|
+
default_options[:query_params]
|
70
|
+
end
|
71
|
+
|
61
72
|
def build_query(query)
|
62
73
|
case query_builder
|
63
74
|
when :to_query
|
@@ -239,8 +250,23 @@ module ClientApiBuilder
|
|
239
250
|
end
|
240
251
|
|
241
252
|
def build_query(query, options)
|
242
|
-
|
243
|
-
|
253
|
+
query_params = {}
|
254
|
+
|
255
|
+
add_query_param_proc = proc do |name, value|
|
256
|
+
query_params[name] =
|
257
|
+
if value.is_a?(Proc)
|
258
|
+
instance_eval(&value)
|
259
|
+
elsif value.is_a?(Symbol)
|
260
|
+
send(value)
|
261
|
+
else
|
262
|
+
value
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
self.class.query_params.each(&add_query_param_proc)
|
267
|
+
query&.each(&add_query_param_proc)
|
268
|
+
|
269
|
+
self.class.build_query(query_params)
|
244
270
|
end
|
245
271
|
|
246
272
|
def build_body(body, options)
|