lib/fassbinder/response.rb in fassbinder-0.0.6 vs lib/fassbinder/response.rb in fassbinder-0.0.7
- old
+ new
@@ -2,40 +2,34 @@
# And I don't believe that melodramatic feelings are laughable - they should
# be taken absolutely seriously.
#
class Response
+ include Enumerable
+
def initialize(response, locale)
raise InvalidResponseError unless response.valid?
@response = response
@locale = locale
end
# Yields each snapshot to given block.
#
- def each
- @response.each('Item') { |doc| yield parse(doc) }
+ def each(&block)
+ @response.each('Item') { |doc| block.call(parse(doc)) }
end
- # Returns an array of snapshots.
- #
- def to_a
- @response.map('Item') do |doc|
- parse(doc)
- end
- end
-
def errors
@response.errors.map do |error|
error['Message'].scan(/[0-9A-Z]{10}/).first rescue nil
end.compact
end
private
def parse(doc)
- Kosher::Snapshot.new(
+ Kosher::Book.new(
'amazon.' + Sucker::Request::HOSTS[@locale].match(/[^.]+$/).to_s,
nil,
doc['ASIN'],
doc['SalesRank'].to_i,
doc['Offers']['TotalOffers'].to_i,