Class: MWS::API::Response

Inherits:
Hashie::Rash
  • Object
show all
Defined in:
lib/ruby-mws/api/response.rb

Class Method Summary collapse

Class Method Details

.handle_error_response(error) ⇒ Object

Raises:



21
22
23
24
25
# File 'lib/ruby-mws/api/response.rb', line 21

def self.handle_error_response(error)
  msg = "#{error.code}: #{error.message}"
  msg << " -- #{error.detail}" unless error.detail.nil?
  raise ErrorResponse, msg
end

.parse(body, name, params) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby-mws/api/response.rb', line 6

def self.parse(body, name, params)
  return body unless body.is_a?(Hash)

  rash = self.new(body)
  handle_error_response(rash["error_response"]["error"]) unless rash["error_response"].nil?
  raise BadResponseError, "received non-matching response type #{rash.keys}" if rash["#{name}_response"].nil?
  rash = rash["#{name}_response"]

  if rash = rash["#{name}_result"]
    # only runs mods if correct result is present
    params[:mods].each {|mod| mod.call(rash) } if params[:mods]
    rash
  end
end