Class: Abebooks4r::Abe::Response
- Inherits:
-
Object
- Object
- Abebooks4r::Abe::Response
- Defined in:
- lib/abebooks4r.rb
Overview
Response object returned after a REST call to Amazon service.
Instance Method Summary collapse
-
#books ⇒ Object
Return an array of Abebooks4r::Element item objects.
-
#doc ⇒ Object
Return Hpricot object.
-
#error ⇒ Object
Return error message.
-
#error_message ⇒ Object
Return error code.
-
#has_error? ⇒ Boolean
Return true if response has an error.
-
#initialize(xml) ⇒ Response
constructor
XML input is in string format.
-
#total_results ⇒ Object
Return total results.
Constructor Details
#initialize(xml) ⇒ Response
XML input is in string format
80 81 82 |
# File 'lib/abebooks4r.rb', line 80 def initialize(xml) @doc = Hpricot(xml) end |
Instance Method Details
#books ⇒ Object
Return an array of Abebooks4r::Element item objects.
105 106 107 108 109 110 |
# File 'lib/abebooks4r.rb', line 105 def books unless @books @books = (@doc/"book").collect {|item| Element.new(item)} end @books end |
#doc ⇒ Object
Return Hpricot object.
85 86 87 |
# File 'lib/abebooks4r.rb', line 85 def doc @doc end |
#error ⇒ Object
Return error message.
95 96 97 |
# File 'lib/abebooks4r.rb', line 95 def error Element.get(@doc, "searchresults/messages") end |
#error_message ⇒ Object
Return error code
100 101 102 |
# File 'lib/abebooks4r.rb', line 100 def Element.get(@doc, "searchresults/messages") end |
#has_error? ⇒ Boolean
Return true if response has an error.
90 91 92 |
# File 'lib/abebooks4r.rb', line 90 def has_error? !(error.nil? || error.empty?) end |
#total_results ⇒ Object
Return total results.
113 114 115 116 117 118 |
# File 'lib/abebooks4r.rb', line 113 def total_results unless @total_results @total_results = (@doc/"resultcount").inner_html.to_i end @total_results end |