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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -1
- data/lib/nxt_http_client/client_dsl.rb +28 -16
- data/lib/nxt_http_client/version.rb +1 -1
- 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: ffedb69d52754004e36852106cc642f45c631a976c965d1f461a9ba7932ec836
|
4
|
+
data.tar.gz: dd9e0401a4002238ae521bba964552f0b9b68d2fd565deaa967932fe2f943258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c087b60ab57dfb40ac9ae537ae4df7659fcc2c647177a4374ee7ab6df8e2de21223b29d8f757b39db1fd9231258008275b65c13c70afc9e28aba3bf6466e4069
|
7
|
+
data.tar.gz: 434b45a64a01692dbdd9a261d6cf33fdd1a8960e4c30a2dd207a128b9751fba2b041c35e6dd5fdce125fb601f2b217d381b4004e3d17ac1503f0b0c7cced3d63
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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 ||=
|
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
|
41
|
-
|
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
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|