Class: Amazon::Awis::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon/awis.rb

Overview

Response object returned after a REST call to Amazon service.

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Response

XML input is in string format



94
95
96
# File 'lib/amazon/awis.rb', line 94

def initialize(xml)
  @doc = Hpricot(xml)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodId) ⇒ Object

returns inner html of any tag in awis response i.e resp.rank => 3



124
125
126
127
128
129
130
131
# File 'lib/amazon/awis.rb', line 124

def method_missing(methodId)
  txt = (@doc/"aws:#{methodId.id2name}").innerHTML
  if txt.empty?
    raise NoMethodError
  else
    txt
  end
end

Instance Method Details

#docObject

Return Hpricot object.



99
100
101
# File 'lib/amazon/awis.rb', line 99

def doc
  @doc
end

#errorObject

Return error message.



109
110
111
# File 'lib/amazon/awis.rb', line 109

def error
  Element.get(@doc, "error/message")
end

#error_codeObject

Return error code



114
115
116
# File 'lib/amazon/awis.rb', line 114

def error_code
  Element.get(@doc, "error/code")
end

#has_error?Boolean

Return true if response has an error.

Returns:

  • (Boolean)


104
105
106
# File 'lib/amazon/awis.rb', line 104

def has_error?
  !(error.nil? || error.empty?)
end

#is_success?Boolean

Return error message.

Returns:

  • (Boolean)


119
120
121
# File 'lib/amazon/awis.rb', line 119

def is_success?
  (@doc/"aws:statuscode").innerHTML == "Success"
end