http-client-generator 0.1.35 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 21d65c38e42bcd0404d1eaf2e444adfae16136940b1c162c41f29757cd88531b
|
|
4
|
+
data.tar.gz: 869036773a9dbcac9ea6651304a97d48c5fd8d5ee48a6d34dbc052c88bebd9eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd8c24c756289f12cf0868a39b2954898b05c9eface230e1f2c3c34e2b63fca31fa9654e810e2d39348b31758929a3a96bcded22d3155110f0757e56804a0df5
|
|
7
|
+
data.tar.gz: aa75c5897ed9e37c3bea2a432160d0226a6d3b43ec267eac87c7dcd362983848f46f15eba413e3ef65e7adda4d43cab5b5aa5d52e2ca20e401770dab0d40b61a
|
|
@@ -5,13 +5,16 @@ module HttpClientGenerator
|
|
|
5
5
|
class SetHeader
|
|
6
6
|
Plugs.register :set_header, self
|
|
7
7
|
|
|
8
|
-
def initialize(arg
|
|
8
|
+
def initialize(arg: nil, value: nil, header:, func: nil)
|
|
9
9
|
@arg = arg
|
|
10
10
|
@header = header
|
|
11
11
|
@func = func
|
|
12
|
+
@value = value
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def call(req)
|
|
16
|
+
return process_header_value(req) if @value
|
|
17
|
+
|
|
15
18
|
arg = req.rest_args[@arg]
|
|
16
19
|
|
|
17
20
|
req.headers[@header] =
|
|
@@ -26,6 +29,19 @@ module HttpClientGenerator
|
|
|
26
29
|
|
|
27
30
|
req
|
|
28
31
|
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def process_header_value(req)
|
|
36
|
+
req.headers[@header] =
|
|
37
|
+
if @value.is_a?(Proc)
|
|
38
|
+
@value.()
|
|
39
|
+
else
|
|
40
|
+
@value
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
req
|
|
44
|
+
end
|
|
29
45
|
end
|
|
30
46
|
end
|
|
31
47
|
end
|
|
@@ -11,8 +11,8 @@ module HttpClientGenerator
|
|
|
11
11
|
@base = base
|
|
12
12
|
@content_type = content_type
|
|
13
13
|
@name = name
|
|
14
|
-
@req_plugs = req_plugs
|
|
15
|
-
@resp_plugs = resp_plugs
|
|
14
|
+
@req_plugs = select_plugs(req_plugs)
|
|
15
|
+
@resp_plugs = select_plugs(resp_plugs)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def perform_request(url_helper, url_options, body, rest_args)
|
|
@@ -48,5 +48,16 @@ module HttpClientGenerator
|
|
|
48
48
|
|
|
49
49
|
request.response_body
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
def select_plugs(plug_entries)
|
|
53
|
+
plug_entries.filter_map do |entry|
|
|
54
|
+
entry in only:, except:, plug:
|
|
55
|
+
|
|
56
|
+
next if only.any? && !only.include?(name)
|
|
57
|
+
next if except.include?(name)
|
|
58
|
+
|
|
59
|
+
plug
|
|
60
|
+
end
|
|
61
|
+
end
|
|
51
62
|
end
|
|
52
63
|
end
|
|
@@ -23,12 +23,12 @@ module HttpClientGenerator
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def req_plug(plug, *args, **kwargs)
|
|
27
|
-
@req_plugs <<
|
|
26
|
+
def req_plug(plug, *args, only: nil, except: nil, **kwargs)
|
|
27
|
+
@req_plugs << build_plug_entry(plug, *args, only: only, except: except, **kwargs)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def resp_plug(plug, *args, **kwargs)
|
|
31
|
-
@resp_plugs <<
|
|
30
|
+
def resp_plug(plug, *args, only: nil, except: nil, **kwargs)
|
|
31
|
+
@resp_plugs << build_plug_entry(plug, *args, only: only, except: except, **kwargs)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def namespace(_name, &block)
|
|
@@ -39,6 +39,14 @@ module HttpClientGenerator
|
|
|
39
39
|
|
|
40
40
|
private
|
|
41
41
|
|
|
42
|
+
def build_plug_entry(plug, *args, only:, except:, **kwargs)
|
|
43
|
+
{
|
|
44
|
+
plug: build_plug(plug, *args, **kwargs),
|
|
45
|
+
only: Array(only).compact.uniq.map(&:to_sym),
|
|
46
|
+
except: Array(except).compact.uniq.map(&:to_sym)
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
42
50
|
def build_plug(plug, *args, **kwargs)
|
|
43
51
|
if plug.respond_to?(:call)
|
|
44
52
|
plug
|