class Afterpay::Item

Attributes

categories[RW]
estimated_shipment_date[RW]
image_url[RW]
name[RW]
page_url[RW]
price[RW]
quantity[RW]
sku[RW]

Public Class Methods

from_response(response) click to toggle source

Builds Item from response

# 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
new(attributes = {}) click to toggle source
# 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

Public Instance Methods

to_hash() click to toggle source
# 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