Class: Amazon::Awis::Response
- Inherits:
-
Object
- Object
- Amazon::Awis::Response
- Defined in:
- lib/amazon/awis.rb
Overview
Response object returned after a REST call to Amazon service.
Instance Method Summary collapse
-
#doc ⇒ Object
Return Hpricot object.
-
#error ⇒ Object
Return error message.
-
#error_code ⇒ Object
Return error code.
-
#has_error? ⇒ Boolean
Return true if response has an error.
-
#initialize(xml) ⇒ Response
constructor
XML input is in string format.
-
#is_success? ⇒ Boolean
Return error message.
-
#method_missing(methodId) ⇒ Object
returns inner html of any tag in awis response i.e resp.rank => 3.
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
#doc ⇒ Object
Return Hpricot object.
99 100 101 |
# File 'lib/amazon/awis.rb', line 99 def doc @doc end |
#error ⇒ Object
Return error message.
109 110 111 |
# File 'lib/amazon/awis.rb', line 109 def error Element.get(@doc, "error/message") end |
#error_code ⇒ Object
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.
104 105 106 |
# File 'lib/amazon/awis.rb', line 104 def has_error? !(error.nil? || error.empty?) end |
#is_success? ⇒ Boolean
Return error message.
119 120 121 |
# File 'lib/amazon/awis.rb', line 119 def is_success? (@doc/"aws:statuscode").innerHTML == "Success" end |