Class: SealineInsurance::Responses::Base
- Inherits:
-
Object
- Object
- SealineInsurance::Responses::Base
show all
- Defined in:
- lib/sealine_insurance/responses/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(http_response) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/sealine_insurance/responses/base.rb', line 8
def initialize(http_response)
@body = parse_response_body(http_response.body)
if @body.nil?
@success = false
@error_code = 'invalid_response'
@error_message = 'Invalid JSON'
@body = {}
elsif http_response.status == 401
@success = false
@error_code = 'unauthorized'
@error_message = body['detail']
elsif http_response.status == 400
@success = false
@error_code = 'invalid_params'
@error_message = fetch_validation_error(body)
elsif http_response.status == 409
@success = false
@error_code = 'conflict'
@error_message = body['error']
else
@success = true
end
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6
7
8
|
# File 'lib/sealine_insurance/responses/base.rb', line 6
def body
@body
end
|
Instance Method Details
#error? ⇒ Boolean
40
41
42
|
# File 'lib/sealine_insurance/responses/base.rb', line 40
def error?
!success?
end
|
#error_code ⇒ Object
44
45
46
|
# File 'lib/sealine_insurance/responses/base.rb', line 44
def error_code
@error_code ||= body['error_code']
end
|
#error_message ⇒ Object
48
49
50
|
# File 'lib/sealine_insurance/responses/base.rb', line 48
def error_message
@error_message ||= body['error_message']
end
|
#success? ⇒ Boolean
36
37
38
|
# File 'lib/sealine_insurance/responses/base.rb', line 36
def success?
@success
end
|