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



86
87
88
# File 'lib/amazon/awis.rb', line 86

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



116
117
118
119
120
121
122
123
# File 'lib/amazon/awis.rb', line 116

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.



91
92
93
# File 'lib/amazon/awis.rb', line 91

def doc
	      @doc
end

#errorObject

Return error message.



101
102
103
# File 'lib/amazon/awis.rb', line 101

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

#error_codeObject

Return error code



106
107
108
# File 'lib/amazon/awis.rb', line 106

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

#has_error?Boolean

Return true if response has an error.

Returns:

  • (Boolean)


96
97
98
# File 'lib/amazon/awis.rb', line 96

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

#is_success?Boolean

Return error message.

Returns:

  • (Boolean)


111
112
113
# File 'lib/amazon/awis.rb', line 111

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