nxt_http_client 0.2.1 → 0.2.2

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: 24cb9d0503259603ad4a511e5f015503995a8a888fce15c87dcd6d66c6115ea2
4
- data.tar.gz: 2158e2a01d44bad00194de299ecaedeeb29fb76d7c172cbb7b862c92c3f40b81
3
+ metadata.gz: ffedb69d52754004e36852106cc642f45c631a976c965d1f461a9ba7932ec836
4
+ data.tar.gz: dd9e0401a4002238ae521bba964552f0b9b68d2fd565deaa967932fe2f943258
5
5
  SHA512:
6
- metadata.gz: 7b1928da8bacd8f94dab46a279c537fc4195c63940f9424b0366cafe94fd8689cfbea3e718d16ba376653d5ac919a23b967f46449137332bc9578b7ed7fcb465
7
- data.tar.gz: 9bd2e240a1cb683fec23bd67392ecda8b96b6e17161b1297350fc00f4b85ea3633bcf151049d01c5bd2906e3495c6b45616afbec5c528b57becd27f2a6e79da9
6
+ metadata.gz: c087b60ab57dfb40ac9ae537ae4df7659fcc2c647177a4374ee7ab6df8e2de21223b29d8f757b39db1fd9231258008275b65c13c70afc9e28aba3bf6466e4069
7
+ data.tar.gz: 434b45a64a01692dbdd9a261d6cf33fdd1a8960e4c30a2dd207a128b9751fba2b041c35e6dd5fdce125fb601f2b217d381b4004e3d17ac1503f0b0c7cced3d63
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_http_client (0.2.1)
4
+ nxt_http_client (0.2.2)
5
5
  activesupport (~> 5.2)
6
6
  typhoeus
7
7
 
data/README.md CHANGED
@@ -60,7 +60,11 @@ class MyClient < NxtHttpClient
60
60
 
61
61
  # In case one of the response handler callbacks raises an error
62
62
  # after fire will has access to it and you may want to reraise the error in that case.
63
- raise result if result.is_a?(StandardError)
63
+ if error
64
+ raise error
65
+ else
66
+ result
67
+ end
64
68
  end
65
69
 
66
70
  def fetch_details
@@ -79,6 +83,13 @@ class MyClient < NxtHttpClient
79
83
  end
80
84
  end
81
85
  end
86
+
87
+ def update
88
+ # there are also convenience methods for all http verbs (get post patch put delete head)
89
+ post(params: { my: 'payload' }) do |handler|
90
+ # would post to the base_url
91
+ end
92
+ end
82
93
  end
83
94
  ```
84
95
 
@@ -1,9 +1,11 @@
1
1
  module NxtHttpClient
2
2
  module ClientDsl
3
3
  def configure(opts = {}, &block)
4
- @default_config ||= DefaultConfig.new(**opts)
5
- @default_config.tap { |d| block.call(d) }
6
- @default_config
4
+ opts.each do |k,v|
5
+ default_config.send(k, v)
6
+ end
7
+ default_config.tap { |d| block.call(d) }
8
+ default_config
7
9
  end
8
10
 
9
11
  def before_fire(&block)
@@ -11,7 +13,7 @@ module NxtHttpClient
11
13
  end
12
14
 
13
15
  def before_fire_callback
14
- @before_fire_callback
16
+ @before_fire ||= dup_instance_variable_from_ancestor_chain(:@before_fire_callback)
15
17
  end
16
18
 
17
19
  def after_fire(&block)
@@ -19,34 +21,44 @@ module NxtHttpClient
19
21
  end
20
22
 
21
23
  def after_fire_callback
22
- @after_fire_callback
24
+ @after_fire_callback ||= dup_instance_variable_from_ancestor_chain(:@after_fire_callback)
23
25
  end
24
26
 
25
27
  def default_config
26
- @default_config ||= DefaultConfig.new
28
+ @default_config ||= dup_instance_variable_from_ancestor_chain(:@default_config) { DefaultConfig.new }
27
29
  end
28
30
 
29
31
  def register_response_handler(handler = nil, &block)
30
32
  @response_handler = handler
31
- @response_handler ||= dup_handler_from_ancestor_or_new
33
+ @response_handler ||= dup_instance_variable_from_ancestor_chain(:@response_handler) { NxtHttpClient::ResponseHandler.new }
32
34
  @response_handler.configure(&block) if block_given?
33
35
  @response_handler
34
36
  end
35
37
 
36
38
  def response_handler
37
- @response_handler
39
+ @response_handler ||= dup_instance_variable_from_ancestor_chain(:@response_handler) { NxtHttpClient::ResponseHandler.new }
38
40
  end
39
41
 
40
- def dup_handler_from_ancestor_or_new
41
- handler_from_ancestor = ancestors[1].instance_variable_get(:@response_handler)
42
- handler_from_ancestor && handler_from_ancestor.dup || NxtHttpClient::ResponseHandler.new
42
+ def client_ancestors
43
+ ancestors.select { |ancestor| ancestor <= NxtHttpClient::Client }
43
44
  end
44
45
 
45
- def inherited(child)
46
- child.instance_variable_set(:@response_handler, @response_handler.dup)
47
- child.instance_variable_set(:@before_fire_callback, @before_fire_callback.dup)
48
- child.instance_variable_set(:@after_fire_callback, @after_fire_callback.dup)
49
- child.instance_variable_set(:@default_config, DefaultConfig.new(**default_config.to_h.deep_dup))
46
+ def instance_variable_from_ancestor_chain(instance_variable_name)
47
+ client = client_ancestors.find do |client|
48
+ client.instance_variable_get(instance_variable_name)
49
+ end
50
+
51
+ client.instance_variable_get(instance_variable_name)
52
+ end
53
+
54
+ def dup_instance_variable_from_ancestor_chain(instance_variable_name)
55
+ result = instance_variable_from_ancestor_chain(instance_variable_name).dup
56
+
57
+ if block_given?
58
+ result || yield
59
+ else
60
+ result
61
+ end
50
62
  end
51
63
  end
52
64
  end
@@ -1,3 +1,3 @@
1
1
  module NxtHttpClient
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke