Class: ASIN::SimpleCart

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#rawObject (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_idObject



19
20
21
# File 'lib/asin/simple_cart.rb', line 19

def cart_id
  @raw.CartId
end

#empty?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/asin/simple_cart.rb', line 49

def empty?
  @raw.CartItems.nil?
end

#hmacObject



23
24
25
# File 'lib/asin/simple_cart.rb', line 23

def hmac
  @raw.HMAC
end

#itemsObject



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

#priceObject



31
32
33
# File 'lib/asin/simple_cart.rb', line 31

def price
  @raw.SubTotal.FormattedPrice
end

#saved_itemsObject



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

#urlObject



27
28
29
# File 'lib/asin/simple_cart.rb', line 27

def url
  @raw.PurchaseURL
end

#valid?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/asin/simple_cart.rb', line 45

def valid?
  @raw.Request.IsValid == 'True'
end