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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e5b76aafc223c8695b05460638fbd487b9ee2ad969e690f26de97d1cccf8293
4
- data.tar.gz: 4b31ea3ef759fd3cf553d32e6b474378137e6b0badc52139068f7db9d7f87b00
3
+ metadata.gz: 5d181593590629e548b61b096cf47322584fd943002972d002d6104348628af7
4
+ data.tar.gz: 01a9168981928f32c6a64a0315dce7227c2153a4b75bfb1e9192a69f1bc80785
5
5
  SHA512:
6
- metadata.gz: bb0d45fe8b4832a73b84a931f63ea3713a955c0d5b44a31159a54b0d454b4b63c0d29d80a379cbbcbd1c469b4b65a9e04ba238650d04e749f28918819987b65a
7
- data.tar.gz: 752dfdf1071668e456532b1d41c1adcdbd522e09bb6a05a5c904f678a71e62014247ecc6e66a0a51fe8474fc222dee05127e9988406b95e6c5887ee6682f7f23
6
+ metadata.gz: b7eec7746486022b3f92e01a96a49057299cb2a4f6afd9b763ba4214bd6c61d79f0c2d6e4e2447a302a7751939628881dca83b274cbf4efc5a8f70b582d2ecc4
7
+ data.tar.gz: 2b4729698266b975556d13b717fd6ea5224f2da79379e2f1225058b1bc03e2a20d20be7228ff4d7c181e0275529577f46cf183dcddd271efb08a95f8490ea9b8
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'client-api-builder'
5
- s.version = '0.2.0'
5
+ s.version = '0.2.1'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Develop Client API libraries faster'
8
8
  s.description = 'Utility for constructing API clients'
@@ -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
- query.merge!(options[:query]) if options[:query]
243
- self.class.build_query(query)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client-api-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch