Class: Amazon::MWS::Response

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/amazon/mws/response.rb,
lib/amazon/mws/response/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.format(response) ⇒ Object

This is the factoryish method that is called!, not new



9
10
11
12
13
14
15
# File 'lib/amazon/mws/response.rb', line 9

def self.format(response)
  if response.content_type =~ /xml/ || response.body =~ /<?xml/
    parse_xml(response)
  else
    response.body
  end
end

.parse_xml(response) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/amazon/mws/response.rb', line 17

def self.parse_xml(response)
  if [Net::HTTPClientError, Net::HTTPServerError].any? {|error| response.is_a? error }
    return ResponseError.from_xml(response.body)
  else
    return self.from_xml(response.body)
  end
end

Instance Method Details

#accessorsObject



25
26
27
# File 'lib/amazon/mws/response.rb', line 25

def accessors
  roxml_references.map {|r| r.accessor}
end

#as_hashObject

render a ROXML object as a normal hash, eliminating the @ and some unneeded admin fields



30
31
32
33
34
35
36
37
38
39
# File 'lib/amazon/mws/response.rb', line 30

def as_hash
  obj_hash = {}
  self.instance_variables.each do |v|
    m = v.to_s.sub('@','')
    if m != 'roxml_references' && m!= 'promotion_ids'
      obj_hash[m.to_sym] = self.instance_variable_get(v)
    end
  end
  obj_hash
end