client-api-builder 0.2.7 → 0.3.0
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 +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +40 -28
- data/client-api-builder.gemspec +1 -1
- data/lib/client_api_builder/nested_router.rb +17 -10
- data/lib/client_api_builder/query_params.rb +31 -18
- data/lib/client_api_builder/router.rb +65 -42
- data/lib/client_api_builder/section.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22b0877a7db8197b265529650ceb1f9c9be7269ebd7f13a9172f79f218a066d0
|
4
|
+
data.tar.gz: 0e265efc80476f256a133594cddeeafac7cc0addd63415ffd830d2fedb4ea66c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e09ef235f9784b004d819def746f19587836e51ca93cccf25496626acf519e22d3edf20ed59c0fb58333575235ca19d90c9ad540c6d0ecb26c5de0dd319fab3
|
7
|
+
data.tar.gz: 513d91d8567ed57456c0db09e66b373caad85bc157a1ab7a7cb7ff17d8cce2e320cdbe9fd1f74382f5da7e0b46c0fe431819bf20c30508fc933df24f73958a5a
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,64 +1,76 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (7.0.2.3)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 1.6, < 2)
|
7
|
+
minitest (>= 5.1)
|
8
|
+
tzinfo (~> 2.0)
|
4
9
|
addressable (2.8.0)
|
5
10
|
public_suffix (>= 2.0.2, < 5.0)
|
6
11
|
ast (2.4.2)
|
12
|
+
concurrent-ruby (1.1.9)
|
7
13
|
crack (0.4.5)
|
8
14
|
rexml
|
9
|
-
diff-lcs (1.
|
15
|
+
diff-lcs (1.5.0)
|
10
16
|
docile (1.4.0)
|
11
17
|
hashdiff (1.0.1)
|
18
|
+
i18n (1.10.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
12
20
|
inheritance-helper (0.2.5)
|
13
|
-
|
14
|
-
|
21
|
+
minitest (5.15.0)
|
22
|
+
parallel (1.21.0)
|
23
|
+
parser (3.1.1.0)
|
15
24
|
ast (~> 2.4.1)
|
16
25
|
public_suffix (4.0.6)
|
17
|
-
rainbow (3.
|
18
|
-
rake (13.0.
|
19
|
-
regexp_parser (2.
|
26
|
+
rainbow (3.1.1)
|
27
|
+
rake (13.0.6)
|
28
|
+
regexp_parser (2.2.1)
|
20
29
|
rexml (3.2.5)
|
21
|
-
rspec (3.
|
22
|
-
rspec-core (~> 3.
|
23
|
-
rspec-expectations (~> 3.
|
24
|
-
rspec-mocks (~> 3.
|
25
|
-
rspec-core (3.
|
26
|
-
rspec-support (~> 3.
|
27
|
-
rspec-expectations (3.
|
30
|
+
rspec (3.11.0)
|
31
|
+
rspec-core (~> 3.11.0)
|
32
|
+
rspec-expectations (~> 3.11.0)
|
33
|
+
rspec-mocks (~> 3.11.0)
|
34
|
+
rspec-core (3.11.0)
|
35
|
+
rspec-support (~> 3.11.0)
|
36
|
+
rspec-expectations (3.11.0)
|
28
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.
|
30
|
-
rspec-mocks (3.
|
38
|
+
rspec-support (~> 3.11.0)
|
39
|
+
rspec-mocks (3.11.0)
|
31
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.
|
33
|
-
rspec-support (3.
|
34
|
-
rubocop (1.
|
41
|
+
rspec-support (~> 3.11.0)
|
42
|
+
rspec-support (3.11.0)
|
43
|
+
rubocop (1.26.0)
|
35
44
|
parallel (~> 1.10)
|
36
|
-
parser (>= 3.
|
45
|
+
parser (>= 3.1.0.0)
|
37
46
|
rainbow (>= 2.2.2, < 4.0)
|
38
47
|
regexp_parser (>= 1.8, < 3.0)
|
39
48
|
rexml
|
40
|
-
rubocop-ast (>= 1.
|
49
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
41
50
|
ruby-progressbar (~> 1.7)
|
42
51
|
unicode-display_width (>= 1.4.0, < 3.0)
|
43
|
-
rubocop-ast (1.
|
44
|
-
parser (>= 3.
|
52
|
+
rubocop-ast (1.16.0)
|
53
|
+
parser (>= 3.1.1.0)
|
45
54
|
ruby-progressbar (1.11.0)
|
46
55
|
simplecov (0.21.2)
|
47
56
|
docile (~> 1.1)
|
48
57
|
simplecov-html (~> 0.11)
|
49
58
|
simplecov_json_formatter (~> 0.1)
|
50
59
|
simplecov-html (0.12.3)
|
51
|
-
simplecov_json_formatter (0.1.
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
simplecov_json_formatter (0.1.4)
|
61
|
+
tzinfo (2.0.4)
|
62
|
+
concurrent-ruby (~> 1.0)
|
63
|
+
unicode-display_width (2.1.0)
|
64
|
+
webmock (3.14.0)
|
65
|
+
addressable (>= 2.8.0)
|
55
66
|
crack (>= 0.3.2)
|
56
67
|
hashdiff (>= 0.4.0, < 2.0.0)
|
57
68
|
|
58
69
|
PLATFORMS
|
59
|
-
x86_64-darwin-
|
70
|
+
x86_64-darwin-21
|
60
71
|
|
61
72
|
DEPENDENCIES
|
73
|
+
activesupport
|
62
74
|
inheritance-helper
|
63
75
|
rake
|
64
76
|
rspec
|
@@ -67,4 +79,4 @@ DEPENDENCIES
|
|
67
79
|
webmock
|
68
80
|
|
69
81
|
BUNDLED WITH
|
70
|
-
2.
|
82
|
+
2.3.3
|
data/client-api-builder.gemspec
CHANGED
@@ -8,10 +8,12 @@ module ClientApiBuilder
|
|
8
8
|
class NestedRouter
|
9
9
|
include ::ClientApiBuilder::Router
|
10
10
|
|
11
|
-
attr_reader :root_router
|
11
|
+
attr_reader :root_router,
|
12
|
+
:nested_router_options
|
12
13
|
|
13
|
-
def initialize(root_router)
|
14
|
+
def initialize(root_router, nested_router_options)
|
14
15
|
@root_router = root_router
|
16
|
+
@nested_router_options = nested_router_options
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.get_instance_method(var)
|
@@ -34,12 +36,12 @@ module ClientApiBuilder
|
|
34
36
|
root_router.stream_to_file(**options, &block)
|
35
37
|
end
|
36
38
|
|
37
|
-
def base_url
|
38
|
-
self.class.base_url || root_router.base_url
|
39
|
+
def base_url
|
40
|
+
self.class.base_url || root_router.base_url
|
39
41
|
end
|
40
42
|
|
41
43
|
def build_headers(options)
|
42
|
-
headers = root_router.build_headers(options)
|
44
|
+
headers = nested_router_options[:ignore_headers] ? {} : root_router.build_headers(options)
|
43
45
|
|
44
46
|
add_header_proc = proc do |name, value|
|
45
47
|
headers[name] =
|
@@ -52,7 +54,7 @@ module ClientApiBuilder
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
|
-
self.class.
|
57
|
+
self.class.default_headers.each(&add_header_proc)
|
56
58
|
|
57
59
|
headers
|
58
60
|
end
|
@@ -62,7 +64,8 @@ module ClientApiBuilder
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def build_query(query, options)
|
65
|
-
return nil if query.nil? && root_router.class.
|
67
|
+
return nil if query.nil? && root_router.class.default_query_params.empty? && self.class.default_query_params.empty?
|
68
|
+
return nil if nested_router_options[:ignore_query] && query.nil? && self.class.default_query_params.empty?
|
66
69
|
|
67
70
|
query_params = {}
|
68
71
|
|
@@ -77,12 +80,12 @@ module ClientApiBuilder
|
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
80
|
-
root_router.class.
|
81
|
-
self.class.
|
83
|
+
root_router.class.default_query_params.each(&add_query_param_proc)
|
84
|
+
self.class.default_query_params.each(&add_query_param_proc)
|
82
85
|
query && query.each(&add_query_param_proc)
|
83
86
|
options[:query] && options[:query].each(&add_query_param_proc)
|
84
87
|
|
85
|
-
self.class.build_query(query_params)
|
88
|
+
self.class.build_query(self, query_params)
|
86
89
|
end
|
87
90
|
|
88
91
|
def build_body(body, options)
|
@@ -96,5 +99,9 @@ module ClientApiBuilder
|
|
96
99
|
def handle_response(response, options, &block)
|
97
100
|
root_router.handle_response(response, options, &block)
|
98
101
|
end
|
102
|
+
|
103
|
+
def escape_path(path)
|
104
|
+
root_router.escape_path(path)
|
105
|
+
end
|
99
106
|
end
|
100
107
|
end
|
@@ -2,59 +2,72 @@
|
|
2
2
|
require 'cgi'
|
3
3
|
|
4
4
|
module ClientApiBuilder
|
5
|
-
|
6
|
-
|
5
|
+
class QueryParams
|
6
|
+
attr_reader :name_value_separator,
|
7
|
+
:param_separator
|
7
8
|
|
8
|
-
|
9
|
+
attr_accessor :custom_escape_proc
|
10
|
+
|
11
|
+
def initialize(name_value_separator: '=', param_separator: '&', custom_escape_proc: nil)
|
12
|
+
@name_value_separator = name_value_separator
|
13
|
+
@param_separator = param_separator
|
14
|
+
@custom_escape_proc = custom_escape_proc
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_query(data, namespace = nil)
|
9
18
|
case data
|
10
19
|
when Hash
|
11
|
-
to_query_from_hash(data, (namespace ?
|
20
|
+
to_query_from_hash(data, (namespace ? escape(namespace) : nil)).join(param_separator)
|
12
21
|
when Array
|
13
|
-
to_query_from_array(data, (namespace ? "#{
|
22
|
+
to_query_from_array(data, (namespace ? "#{escape(namespace)}[]" : '[]')).join(param_separator)
|
14
23
|
else
|
15
24
|
if namespace
|
16
|
-
"#{
|
25
|
+
"#{escape(namespace)}#{name_value_separator}#{escape(data.to_s)}"
|
17
26
|
else
|
18
|
-
|
27
|
+
escape(data.to_s)
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
23
|
-
def to_query_from_hash(hsh, namespace
|
32
|
+
def to_query_from_hash(hsh, namespace)
|
24
33
|
query_params = []
|
25
34
|
|
26
35
|
hsh.each do |key, value|
|
27
36
|
case value
|
28
37
|
when Array
|
29
|
-
array_namespace = namespace ? "#{namespace}[#{
|
30
|
-
query_params += to_query_from_array(value, array_namespace
|
38
|
+
array_namespace = namespace ? "#{namespace}[#{escape(key.to_s)}][]" : "#{escape(key.to_s)}[]"
|
39
|
+
query_params += to_query_from_array(value, array_namespace)
|
31
40
|
when Hash
|
32
|
-
hash_namespace = namespace ? "#{namespace}[#{
|
33
|
-
query_params += to_query_from_hash(value, hash_namespace
|
41
|
+
hash_namespace = namespace ? "#{namespace}[#{escape(key.to_s)}]" : "#{escape(key.to_s)}"
|
42
|
+
query_params += to_query_from_hash(value, hash_namespace)
|
34
43
|
else
|
35
|
-
query_name = namespace ? "#{namespace}[#{
|
36
|
-
query_params << "#{query_name}#{name_value_separator}#{
|
44
|
+
query_name = namespace ? "#{namespace}[#{escape(key.to_s)}]" : "#{escape(key.to_s)}"
|
45
|
+
query_params << "#{query_name}#{name_value_separator}#{escape(value.to_s)}"
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
40
49
|
query_params
|
41
50
|
end
|
42
51
|
|
43
|
-
def to_query_from_array(array, namespace
|
52
|
+
def to_query_from_array(array, namespace)
|
44
53
|
query_params = []
|
45
54
|
|
46
55
|
array.each do |value|
|
47
56
|
case value
|
48
57
|
when Hash
|
49
|
-
query_params += to_query_from_hash(value, namespace
|
58
|
+
query_params += to_query_from_hash(value, namespace)
|
50
59
|
when Array
|
51
|
-
query_params += to_query_from_array(value, "#{namespace}[]"
|
60
|
+
query_params += to_query_from_array(value, "#{namespace}[]")
|
52
61
|
else
|
53
|
-
query_params << "#{namespace}#{name_value_separator}#{
|
62
|
+
query_params << "#{namespace}#{name_value_separator}#{escape(value.to_s)}"
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
66
|
query_params
|
58
67
|
end
|
68
|
+
|
69
|
+
def escape(str)
|
70
|
+
custom_escape_proc ? custom_escape_proc.call(str) : CGI.escape(str)
|
71
|
+
end
|
59
72
|
end
|
60
73
|
end
|
@@ -8,7 +8,7 @@ module ClientApiBuilder
|
|
8
8
|
base.extend ClassMethods
|
9
9
|
base.include ::ClientApiBuilder::Section
|
10
10
|
base.include ::ClientApiBuilder::NetHTTP::Request
|
11
|
-
base.attr_reader :response, :request_options
|
11
|
+
base.send(:attr_reader, :response, :request_options)
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
@@ -30,93 +30,106 @@ module ClientApiBuilder
|
|
30
30
|
}.freeze
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
def
|
33
|
+
# tracks the proc used to handle responses
|
34
|
+
def add_response_proc(method_name, proc)
|
35
35
|
response_procs = default_options[:response_procs].dup
|
36
36
|
response_procs[method_name] = proc
|
37
37
|
add_value_to_class_method(:default_options, response_procs: response_procs)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
# retrieves the proc used to handle the response
|
41
|
+
def get_response_proc(method_name)
|
42
|
+
default_options[:response_procs][method_name]
|
43
43
|
end
|
44
44
|
|
45
|
+
# set/get base url
|
45
46
|
def base_url(url = nil)
|
46
47
|
return default_options[:base_url] unless url
|
47
48
|
|
48
49
|
add_value_to_class_method(:default_options, base_url: url)
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
# set the builder to :to_json, :to_query, :query_params or specify a proc to handle building the request body payload
|
53
|
+
# or get the body builder
|
54
|
+
def body_builder(builder = nil, &block)
|
55
|
+
return default_options[:body_builder] if builder.nil? && block.nil?
|
53
56
|
|
54
|
-
add_value_to_class_method(:default_options, body_builder: builder)
|
57
|
+
add_value_to_class_method(:default_options, body_builder: builder || block)
|
55
58
|
end
|
56
59
|
|
57
|
-
|
58
|
-
|
60
|
+
# set the builder to :to_query, :query_params or specify a proc to handle building the request query params
|
61
|
+
# or get the query builder
|
62
|
+
def query_builder(builder = nil, &block)
|
63
|
+
return default_options[:query_builder] if builder.nil? && block.nil?
|
59
64
|
|
60
|
-
add_value_to_class_method(:default_options, query_builder: builder)
|
65
|
+
add_value_to_class_method(:default_options, query_builder: builder || block)
|
61
66
|
end
|
62
67
|
|
68
|
+
# add a request header
|
63
69
|
def header(name, value = nil, &block)
|
64
70
|
headers = default_options[:headers].dup
|
65
71
|
headers[name] = value || block
|
66
72
|
add_value_to_class_method(:default_options, headers: headers)
|
67
73
|
end
|
68
74
|
|
75
|
+
# set a connection_option, specific to Net::HTTP
|
69
76
|
def connection_option(name, value)
|
70
77
|
connection_options = default_options[:connection_options].dup
|
71
78
|
connection_options[name] = value
|
72
79
|
add_value_to_class_method(:default_options, connection_options: connection_options)
|
73
80
|
end
|
74
81
|
|
82
|
+
# add a query param to all requests
|
75
83
|
def query_param(name, value = nil, &block)
|
76
84
|
query_params = default_options[:query_params].dup
|
77
85
|
query_params[name] = value || block
|
78
86
|
add_value_to_class_method(:default_options, query_params: query_params)
|
79
87
|
end
|
80
88
|
|
81
|
-
|
89
|
+
# get default headers
|
90
|
+
def default_headers
|
82
91
|
default_options[:headers]
|
83
92
|
end
|
84
93
|
|
85
|
-
|
94
|
+
# get configured connection_options
|
95
|
+
def default_connection_options
|
86
96
|
default_options[:connection_options]
|
87
97
|
end
|
88
98
|
|
89
|
-
|
99
|
+
# get default query_params to add to all requests
|
100
|
+
def default_query_params
|
90
101
|
default_options[:query_params]
|
91
102
|
end
|
92
103
|
|
93
|
-
def build_body(router, body
|
94
|
-
|
95
|
-
|
96
|
-
case builder
|
104
|
+
def build_body(router, body)
|
105
|
+
case body_builder
|
97
106
|
when :to_json
|
98
107
|
body.to_json
|
99
108
|
when :to_query
|
100
109
|
body.to_query
|
101
110
|
when :query_params
|
102
|
-
ClientApiBuilder::QueryParams.to_query(body)
|
111
|
+
ClientApiBuilder::QueryParams.new.to_query(body)
|
112
|
+
when Symbol
|
113
|
+
router.send(body_builder, body)
|
103
114
|
else
|
104
|
-
router.instance_exec(body, &
|
115
|
+
router.instance_exec(body, &body_builder)
|
105
116
|
end
|
106
117
|
end
|
107
118
|
|
108
|
-
def build_query(query)
|
119
|
+
def build_query(router, query)
|
109
120
|
case query_builder
|
110
121
|
when :to_query
|
111
122
|
query.to_query
|
112
123
|
when :query_params
|
113
|
-
ClientApiBuilder::QueryParams.to_query(query)
|
124
|
+
ClientApiBuilder::QueryParams.new.to_query(query)
|
125
|
+
when Symbol
|
126
|
+
router.send(query_builder, query)
|
114
127
|
else
|
115
|
-
|
128
|
+
router.instance_exec(query, &query_builder)
|
116
129
|
end
|
117
130
|
end
|
118
131
|
|
119
|
-
def
|
132
|
+
def auto_detect_http_method(method_name)
|
120
133
|
case method_name.to_s
|
121
134
|
when /^(?:post|create|add|insert)/i
|
122
135
|
:post
|
@@ -172,6 +185,7 @@ module ClientApiBuilder
|
|
172
185
|
arguments
|
173
186
|
end
|
174
187
|
|
188
|
+
# returns a list of arguments to add to the route method
|
175
189
|
def get_arguments(value)
|
176
190
|
case value
|
177
191
|
when Hash
|
@@ -184,7 +198,7 @@ module ClientApiBuilder
|
|
184
198
|
end
|
185
199
|
|
186
200
|
def get_instance_method(var)
|
187
|
-
"#\{#{var}\}"
|
201
|
+
"#\{escape_path(#{var})\}"
|
188
202
|
end
|
189
203
|
|
190
204
|
@@namespaces = []
|
@@ -192,6 +206,7 @@ module ClientApiBuilder
|
|
192
206
|
@@namespaces
|
193
207
|
end
|
194
208
|
|
209
|
+
# a namespace is a top level path to apply to all routes within the namespace block
|
195
210
|
def namespace(name)
|
196
211
|
namespaces << name
|
197
212
|
yield
|
@@ -199,7 +214,7 @@ module ClientApiBuilder
|
|
199
214
|
end
|
200
215
|
|
201
216
|
def generate_route_code(method_name, path, options = {})
|
202
|
-
http_method = options[:method] ||
|
217
|
+
http_method = options[:method] || auto_detect_http_method(method_name)
|
203
218
|
|
204
219
|
path = namespaces.join + path
|
205
220
|
|
@@ -211,7 +226,7 @@ module ClientApiBuilder
|
|
211
226
|
path_arguments = []
|
212
227
|
path.gsub!(/:([a-z0-9_]+)/i) do |_|
|
213
228
|
path_arguments << $1
|
214
|
-
"#\{#{$1}\}"
|
229
|
+
"#\{escape_path(#{$1})\}"
|
215
230
|
end
|
216
231
|
|
217
232
|
has_body_param = options[:body].nil? && requires_body?(http_method, options)
|
@@ -268,12 +283,10 @@ module ClientApiBuilder
|
|
268
283
|
method_args += ["#{stream_param}:"] if stream_param
|
269
284
|
method_args += ['**__options__', '&block']
|
270
285
|
|
271
|
-
code = "def #{method_name}(" + method_args.join(', ') + ")\n"
|
272
|
-
code += " block ||= self.class.response_proc(#{method_name.inspect})\n"
|
286
|
+
code = "def #{method_name}_raw_response(" + method_args.join(', ') + ")\n"
|
273
287
|
code += " __path__ = \"#{path}\"\n"
|
274
288
|
code += " __query__ = #{query}\n"
|
275
289
|
code += " __body__ = #{body}\n"
|
276
|
-
code += " __expected_response_codes__ = #{expected_response_codes.inspect}\n"
|
277
290
|
code += " __uri__ = build_uri(__path__, __query__, __options__)\n"
|
278
291
|
code += " __body__ = build_body(__body__, __options__)\n"
|
279
292
|
code += " __headers__ = build_headers(__options__)\n"
|
@@ -292,7 +305,13 @@ module ClientApiBuilder
|
|
292
305
|
else
|
293
306
|
code += " @response = request(**@request_options)\n"
|
294
307
|
end
|
308
|
+
code += "end\n"
|
309
|
+
code += "\n"
|
295
310
|
|
311
|
+
code += "def #{method_name}(" + method_args.join(', ') + ")\n"
|
312
|
+
code += " block ||= self.class.get_response_proc(#{method_name.inspect})\n"
|
313
|
+
code += " __expected_response_codes__ = #{expected_response_codes.inspect}\n"
|
314
|
+
code += " #{method_name}_raw_response(" + method_args.map { |a| a =~ /:$/ ? "#{a} #{a.sub(':', '')}" : a }.join(', ') + ")\n"
|
296
315
|
code += " expected_response_code!(@response, __expected_response_codes__, __options__)\n"
|
297
316
|
|
298
317
|
if options[:stream] || options[:return] == :response
|
@@ -308,14 +327,14 @@ module ClientApiBuilder
|
|
308
327
|
end
|
309
328
|
|
310
329
|
def route(method_name, path, options = {}, &block)
|
311
|
-
|
330
|
+
add_response_proc(method_name, block) if block
|
312
331
|
|
313
332
|
self.class_eval generate_route_code(method_name, path, options), __FILE__, __LINE__
|
314
333
|
end
|
315
334
|
end
|
316
335
|
|
317
|
-
def base_url
|
318
|
-
|
336
|
+
def base_url
|
337
|
+
self.class.base_url
|
319
338
|
end
|
320
339
|
|
321
340
|
def build_headers(options)
|
@@ -332,7 +351,7 @@ module ClientApiBuilder
|
|
332
351
|
end
|
333
352
|
end
|
334
353
|
|
335
|
-
self.class.
|
354
|
+
self.class.default_headers.each(&add_header_proc)
|
336
355
|
options[:headers] && options[:headers].each(&add_header_proc)
|
337
356
|
|
338
357
|
headers
|
@@ -340,14 +359,14 @@ module ClientApiBuilder
|
|
340
359
|
|
341
360
|
def build_connection_options(options)
|
342
361
|
if options[:connection_options]
|
343
|
-
self.class.
|
362
|
+
self.class.default_connection_options.merge(options[:connection_options])
|
344
363
|
else
|
345
|
-
self.class.
|
364
|
+
self.class.default_connection_options
|
346
365
|
end
|
347
366
|
end
|
348
367
|
|
349
368
|
def build_query(query, options)
|
350
|
-
return nil if query.nil? && self.class.
|
369
|
+
return nil if query.nil? && self.class.default_query_params.empty?
|
351
370
|
|
352
371
|
query_params = {}
|
353
372
|
|
@@ -362,11 +381,11 @@ module ClientApiBuilder
|
|
362
381
|
end
|
363
382
|
end
|
364
383
|
|
365
|
-
self.class.
|
384
|
+
self.class.default_query_params.each(&add_query_param_proc)
|
366
385
|
query && query.each(&add_query_param_proc)
|
367
386
|
options[:query] && options[:query].each(&add_query_param_proc)
|
368
387
|
|
369
|
-
self.class.build_query(query_params)
|
388
|
+
self.class.build_query(self, query_params)
|
370
389
|
end
|
371
390
|
|
372
391
|
def build_body(body, options)
|
@@ -375,11 +394,11 @@ module ClientApiBuilder
|
|
375
394
|
return nil unless body
|
376
395
|
return body if body.is_a?(String)
|
377
396
|
|
378
|
-
self.class.build_body(self, body
|
397
|
+
self.class.build_body(self, body)
|
379
398
|
end
|
380
399
|
|
381
400
|
def build_uri(path, query, options)
|
382
|
-
uri = URI(base_url
|
401
|
+
uri = URI(base_url + path)
|
383
402
|
uri.query = build_query(query, options)
|
384
403
|
uri
|
385
404
|
end
|
@@ -416,5 +435,9 @@ module ClientApiBuilder
|
|
416
435
|
def root_router
|
417
436
|
self
|
418
437
|
end
|
438
|
+
|
439
|
+
def escape_path(path)
|
440
|
+
path
|
441
|
+
end
|
419
442
|
end
|
420
443
|
end
|
@@ -8,7 +8,7 @@ module ClientApiBuilder
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def section(name, &block)
|
11
|
+
def section(name, nested_router_options={}, &block)
|
12
12
|
kls = InheritanceHelper::ClassBuilder::Utils.create_class(
|
13
13
|
self,
|
14
14
|
name,
|
@@ -24,7 +24,7 @@ def self.#{name}_router
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def #{name}
|
27
|
-
@#{name} ||= self.class.#{name}_router.new(self.root_router)
|
27
|
+
@#{name} ||= self.class.#{name}_router.new(self.root_router, #{nested_router_options.inspect})
|
28
28
|
end
|
29
29
|
CODE
|
30
30
|
self.class_eval code, __FILE__, __LINE__
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client-api-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.3.3
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Develop Client API libraries faster
|