Class: Itexmo::ResponseHelper
- Inherits:
-
Object
- Object
- Itexmo::ResponseHelper
- Defined in:
- lib/itexmo/response_helper.rb
Overview
helper
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body) ⇒ ResponseHelper
constructor
A new instance of ResponseHelper.
- #parse ⇒ Object
Constructor Details
#initialize(body) ⇒ ResponseHelper
Returns a new instance of ResponseHelper.
9 10 11 |
# File 'lib/itexmo/response_helper.rb', line 9 def initialize(body) @body = body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/itexmo/response_helper.rb', line 7 def body @body end |
Class Method Details
.parse(body) ⇒ Object
32 33 34 35 |
# File 'lib/itexmo/response_helper.rb', line 32 def self.parse(body) instance = new(body) instance.parse end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/itexmo/response_helper.rb', line 13 def parse case body when 'INVALID', 'INVALID_APICODE' raise Errors::Authentication, 'invalid api_code' when 'INVALID PARAMETERS' raise Errors::BadRequest, 'invalid parameters' when 'EMPTY' [] when 'ERROR' { code: 422, message: 'unable to do action' } when 'SUCCESS' { code: 200, message: 'action succeeded' } when 'NOT_SUPPORTED' raise Errors::Authentication, 'api_code is not a corporate one' else JSON.parse(body, symbolize_names: true) end end |