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

- (SimpleCart) initialize(hash)

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

- (Object) raw (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

- (Object) cart_id



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

def cart_id
  @raw.CartId
end

- (Boolean) empty?

Returns:

  • (Boolean)


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

def empty?
  @raw.CartItems.nil?
end

- (Object) hmac



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

def hmac
  @raw.HMAC
end

- (Object) items



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

- (Object) price



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

def price
  @raw.SubTotal.FormattedPrice
end

- (Object) saved_items



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

- (Object) url



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

def url
  @raw.PurchaseURL
end

- (Boolean) valid?

Returns:

  • (Boolean)


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

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