Class: ApimaticCalculator::BaseController
- Inherits:
-
Object
- Object
- ApimaticCalculator::BaseController
show all
- Defined in:
- lib/apimatic_calculator/controllers/base_controller.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, http_call_back: nil) ⇒ BaseController
Returns a new instance of BaseController.
11
12
13
14
15
16
17
18
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 11
def initialize(config, http_call_back: nil)
@config = config
@http_call_back = http_call_back
@global_headers = {
'user-agent' => get_user_agent
}
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9
10
11
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 9
def config
@config
end
|
#http_call_back ⇒ Object
Returns the value of attribute http_call_back.
9
10
11
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 9
def http_call_back
@http_call_back
end
|
Instance Method Details
#execute_request(request, binary: false) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 33
def execute_request(request, binary: false)
@http_call_back&.on_before_request(request)
APIHelper.clean_hash(request.)
request..merge!(@global_headers)
response = if binary
config.http_client.execute_as_binary(request)
else
config.http_client.execute_as_string(request)
end
@http_call_back&.on_after_response(response)
response
end
|
#get_user_agent ⇒ Object
54
55
56
57
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 54
def get_user_agent
user_agent = 'APIMATIC 3.0'
user_agent
end
|
#validate_parameters(args) ⇒ Object
20
21
22
23
24
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 20
def validate_parameters(args)
args.each do |_name, value|
raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
end
end
|
#validate_parameters_types(args) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 26
def validate_parameters_types(args)
args.each do |_name, type|
key, val = type.first
APIHelper.validate_types(key, val) unless key.nil?
end
end
|
#validate_response(response) ⇒ Object
49
50
51
52
|
# File 'lib/apimatic_calculator/controllers/base_controller.rb', line 49
def validate_response(response)
raise APIException.new 'HTTP Response Not OK', response unless
response.status_code.between?(200, 208) end
|