Class: Itexmo::ResponseHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/itexmo/response_helper.rb

Overview

helper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject

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

#parseObject



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