Class: ClientApiBuilder::NestedRouter
- Inherits:
-
Object
- Object
- ClientApiBuilder::NestedRouter
show all
- Includes:
- Router
- Defined in:
- lib/client_api_builder/nested_router.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#base_url(options) ⇒ Object
-
#build_body(body, options) ⇒ Object
-
#build_connection_options(options) ⇒ Object
-
#build_headers(options) ⇒ Object
-
#build_query(query, options) ⇒ Object
-
#expected_response_code!(response, expected_response_codes, options) ⇒ Object
-
#handle_response(response, options, &block) ⇒ Object
-
#initialize(root_router) ⇒ NestedRouter
constructor
A new instance of NestedRouter.
-
#request(**options, &block) ⇒ Object
-
#stream(**options, &block) ⇒ Object
-
#stream_to_file(**options, &block) ⇒ Object
-
#stream_to_io(**options, &block) ⇒ Object
Methods included from Router
#build_uri, included, #parse_response
Constructor Details
#initialize(root_router) ⇒ NestedRouter
Returns a new instance of NestedRouter.
13
14
15
|
# File 'lib/client_api_builder/nested_router.rb', line 13
def initialize(root_router)
@root_router = root_router
end
|
Instance Attribute Details
#root_router ⇒ Object
Returns the value of attribute root_router.
11
12
13
|
# File 'lib/client_api_builder/nested_router.rb', line 11
def root_router
@root_router
end
|
Class Method Details
.get_instance_method(var) ⇒ Object
17
18
19
|
# File 'lib/client_api_builder/nested_router.rb', line 17
def self.get_instance_method(var)
"\#{root_router.#{var}\}"
end
|
Instance Method Details
#base_url(options) ⇒ Object
37
38
39
|
# File 'lib/client_api_builder/nested_router.rb', line 37
def base_url(options)
self.class.base_url || root_router.base_url(options)
end
|
#build_body(body, options) ⇒ Object
88
89
90
|
# File 'lib/client_api_builder/nested_router.rb', line 88
def build_body(body, options)
root_router.build_body(body, options)
end
|
#build_connection_options(options) ⇒ Object
60
61
62
|
# File 'lib/client_api_builder/nested_router.rb', line 60
def build_connection_options(options)
root_router.build_connection_options(options)
end
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/client_api_builder/nested_router.rb', line 41
def (options)
= root_router.(options)
= proc do |name, value|
[name] =
if value.is_a?(Proc)
root_router.instance_eval(&value)
elsif value.is_a?(Symbol)
root_router.send(value)
else
value
end
end
self.class..each(&)
end
|
#build_query(query, options) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/client_api_builder/nested_router.rb', line 64
def build_query(query, options)
return nil if query.nil? && root_router.class.query_params.empty? && self.class.query_params.empty?
query_params = {}
add_query_param_proc = proc do |name, value|
query_params[name] =
if value.is_a?(Proc)
root_router.instance_eval(&value)
elsif value.is_a?(Symbol)
root_router.send(value)
else
value
end
end
root_router.class.query_params.each(&add_query_param_proc)
self.class.query_params.each(&add_query_param_proc)
query && query.each(&add_query_param_proc)
options[:query] && options[:query].each(&add_query_param_proc)
self.class.build_query(query_params)
end
|
#expected_response_code!(response, expected_response_codes, options) ⇒ Object
92
93
94
|
# File 'lib/client_api_builder/nested_router.rb', line 92
def expected_response_code!(response, expected_response_codes, options)
root_router.expected_response_code!(response, expected_response_codes, options)
end
|
#handle_response(response, options, &block) ⇒ Object
96
97
98
|
# File 'lib/client_api_builder/nested_router.rb', line 96
def handle_response(response, options, &block)
root_router.handle_response(response, options, &block)
end
|
#request(**options, &block) ⇒ Object
21
22
23
|
# File 'lib/client_api_builder/nested_router.rb', line 21
def request(**options, &block)
root_router.request(**options, &block)
end
|
#stream(**options, &block) ⇒ Object
25
26
27
|
# File 'lib/client_api_builder/nested_router.rb', line 25
def stream(**options, &block)
root_router.stream(**options, &block)
end
|
#stream_to_file(**options, &block) ⇒ Object
33
34
35
|
# File 'lib/client_api_builder/nested_router.rb', line 33
def stream_to_file(**options, &block)
root_router.stream_to_file(**options, &block)
end
|
#stream_to_io(**options, &block) ⇒ Object
29
30
31
|
# File 'lib/client_api_builder/nested_router.rb', line 29
def stream_to_io(**options, &block)
root_router.stream_to_io(**options, &block)
end
|