forked from phoet/asin
/
item.rb
51 lines (39 loc) · 947 Bytes
/
item.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'hashie'
module ASIN
# =Item
#
# The +Item+ class is a wrapper for the Amazon XML-REST-Response.
#
# A Hashie::Mash is used for the internal data representation and can be accessed over the +raw+ attribute.
#
class Item
attr_reader :raw
def initialize(hash)
@raw = Hashie::Mash.new(hash)
end
def asin
@raw.ASIN
end
alias :id :asin
alias :to_param :asin
def title
@raw.ItemAttributes!.Title
end
def cents
price_container = @raw.ItemAttributes!.ListPrice || @raw.OfferSummary!.LowestUsedPrice
if price_container and amount = price_container.Amount
amount.to_i
end
end
def url
@raw.DetailPageURL
end
def description
@raw.EditorialReviews!.EditorialReview!.Content ||
(features =@raw.ItemAttributes!.Feature! and features.join('.')
end
def image
@raw.LargeImage!.URL
end
end
end