Class: Afterpay::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/afterpay/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Item

Returns a new instance of Item.



9
10
11
12
13
14
15
16
17
18
# File 'lib/afterpay/item.rb', line 9

def initialize(attributes = {})
  @name = attributes[:name]
  @sku = attributes[:sku] || ""
  @quantity = attributes[:quantity]
  @price = attributes[:price]
  @page_url = attributes[:page_url] || ""
  @image_url = attributes[:image_url] || ""
  @categories = attributes[:categories] || []
  @estimated_shipment_date = attributes[:estimated_shipment_date] || ""
end

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def categories
  @categories
end

#estimated_shipment_dateObject

Returns the value of attribute estimated_shipment_date.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def estimated_shipment_date
  @estimated_shipment_date
end

#image_urlObject

Returns the value of attribute image_url.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def image_url
  @image_url
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def name
  @name
end

#page_urlObject

Returns the value of attribute page_url.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def page_url
  @page_url
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def quantity
  @quantity
end

#skuObject

Returns the value of attribute sku.



7
8
9
# File 'lib/afterpay/item.rb', line 7

def sku
  @sku
end

Class Method Details

.from_response(response) ⇒ Object

Builds Item from response



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/afterpay/item.rb', line 37

def self.from_response(response)
  return nil if response.nil?

  new(
    name: response[:name],
    sku: response[:sku],
    quantity: response[:quantity],
    price: Utils::Money.from_response(response[:price]),
    page_url: response[:pageUrl],
    image_url: response[:imageUrl],
    categories: response[:categories],
    estimated_shipment_date: response[:estimatedShipmentDate]
  )
end

Instance Method Details

#to_hashObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/afterpay/item.rb', line 20

def to_hash
  {
    name: name,
    sku: sku,
    quantity: quantity,
    price: {
      amount: price.amount.to_f,
      currency: price.currency.iso_code
    },
    page_url: page_url,
    image_url: image_url,
    categories: categories,
    estimated_shipment_date: estimated_shipment_date
  }
end