Class: Lakala::Response
- Inherits:
-
Object
- Object
- Lakala::Response
- Defined in:
- lib/lakala/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#net_http_response ⇒ Object
readonly
Returns the value of attribute net_http_response.
Instance Method Summary collapse
- #error_code ⇒ Object
- #error_msg ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(res) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(res) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/lakala/response.rb', line 9 def initialize(res) @net_http_response = res @body = JSON.parse(res.body&.dup&.force_encoding('UTF-8')) @code = res.code end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/lakala/response.rb', line 5 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/lakala/response.rb', line 5 def code @code end |
#net_http_response ⇒ Object (readonly)
Returns the value of attribute net_http_response.
5 6 7 |
# File 'lib/lakala/response.rb', line 5 def net_http_response @net_http_response end |
Instance Method Details
#error_code ⇒ Object
23 24 25 |
# File 'lib/lakala/response.rb', line 23 def error_code @body['code'] if failed? end |
#error_msg ⇒ Object
27 28 29 |
# File 'lib/lakala/response.rb', line 27 def error_msg @body['msg'] if failed? end |
#failed? ⇒ Boolean
19 20 21 |
# File 'lib/lakala/response.rb', line 19 def failed? @net_http_response.code != '200' end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/lakala/response.rb', line 15 def success? !failed? end |