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



107
108
109
110
# File 'lib/awis-wrapper.rb', line 107

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



139
140
141
142
# File 'lib/awis-wrapper.rb', line 139

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

Instance Method Details

#docObject



112
113
114
# File 'lib/awis-wrapper.rb', line 112

def doc
  @doc
end

#errorObject

Return error code



129
130
131
# File 'lib/awis-wrapper.rb', line 129

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

#get(tag) ⇒ Object



120
121
122
# File 'lib/awis-wrapper.rb', line 120

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

#get_all(tag) ⇒ Object



124
125
126
# File 'lib/awis-wrapper.rb', line 124

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)


134
135
136
# File 'lib/awis-wrapper.rb', line 134

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

#xpath(path) ⇒ Object



116
117
118
# File 'lib/awis-wrapper.rb', line 116

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