class Itexmo::ResponseHelper

helper

Attributes

body[RW]

Public Class Methods

new(body) click to toggle source
# File lib/itexmo/response_helper.rb, line 9
def initialize(body)
  @body = body
end
parse(body) click to toggle source
# File lib/itexmo/response_helper.rb, line 32
def self.parse(body)
  instance = new(body)
  instance.parse
end

Public Instance Methods

parse() click to toggle source
# 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