Class: ASIN::SimpleCart
- Inherits:
-
Object
- Object
- ASIN::SimpleCart
- Defined in:
- lib/asin/simple_cart.rb
Overview
SimpleCart
The SimpleCart
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.
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #cart_id ⇒ Object
- #empty? ⇒ Boolean
- #hmac ⇒ Object
-
#initialize(hash) ⇒ SimpleCart
constructor
A new instance of SimpleCart.
- #items ⇒ Object
- #price ⇒ Object
- #saved_items ⇒ Object
- #url ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ SimpleCart
Returns a new instance of SimpleCart.
15 16 17 |
# File 'lib/asin/simple_cart.rb', line 15 def initialize(hash) @raw = Hashie::Mash.new(hash) end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
13 14 15 |
# File 'lib/asin/simple_cart.rb', line 13 def raw @raw end |
Instance Method Details
#cart_id ⇒ Object
19 20 21 |
# File 'lib/asin/simple_cart.rb', line 19 def cart_id @raw.CartId end |
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/asin/simple_cart.rb', line 49 def empty? @raw.CartItems.nil? end |
#hmac ⇒ Object
23 24 25 |
# File 'lib/asin/simple_cart.rb', line 23 def hmac @raw.HMAC end |
#items ⇒ Object
35 36 37 38 |
# File 'lib/asin/simple_cart.rb', line 35 def items return [] unless @raw.CartItems @raw.CartItems.CartItem.is_a?(Array) ? @raw.CartItems.CartItem : [@raw.CartItems.CartItem] end |
#price ⇒ Object
31 32 33 |
# File 'lib/asin/simple_cart.rb', line 31 def price @raw.SubTotal.FormattedPrice end |
#saved_items ⇒ Object
40 41 42 43 |
# File 'lib/asin/simple_cart.rb', line 40 def saved_items return [] unless @raw.SavedForLaterItems @raw.SavedForLaterItems.SavedForLaterItem.is_a?(Array) ? @raw.SavedForLaterItems.SavedForLaterItem : [@raw.SavedForLaterItems.SavedForLaterItem] end |
#url ⇒ Object
27 28 29 |
# File 'lib/asin/simple_cart.rb', line 27 def url @raw.PurchaseURL end |
#valid? ⇒ Boolean
45 46 47 |
# File 'lib/asin/simple_cart.rb', line 45 def valid? @raw.Request.IsValid == 'True' end |