Class: Amazon::Awis::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/awis-wrapper.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



105
106
107
108
# File 'lib/awis-wrapper.rb', line 105

def initialize(xml)
 @doc = Nokogiri::XML(xml)
  @namespace = Awis::NAMESPACE
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



137
138
139
140
# File 'lib/awis-wrapper.rb', line 137

def method_missing(methodId)
  puts methodId
  @doc.send methodId 
end

Instance Method Details

#docObject



110
111
112
# File 'lib/awis-wrapper.rb', line 110

def doc
  @doc
end

#errorObject

Return error code



127
128
129
# File 'lib/awis-wrapper.rb', line 127

def error
  @doc.at_xpath("//aws:StatusMessage").content
end

#get(tag) ⇒ Object



118
119
120
# File 'lib/awis-wrapper.rb', line 118

def get(tag)
  Element.new @doc.at_xpath("//aws:#{Amazon::Awis.camel_case tag}", @namespace)
end

#get_all(tag) ⇒ Object



122
123
124
# File 'lib/awis-wrapper.rb', line 122

def get_all(tag)
  @doc.xpath("//aws:#{Amazon::Awis.camel_case tag}", @namespace).collect{|data|Element.new data}
end

#success?Boolean

Return error message.

Returns:

  • (Boolean)


132
133
134
# File 'lib/awis-wrapper.rb', line 132

def success?
	(@doc.at_xpath "//aws:StatusCode").content == "Success"     	      	      
end

#xpath(path) ⇒ Object



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

def xpath(path)
  @doc.xpath(path, @namesapce)
end