Class: Afterpay::Item
- Inherits:
-
Object
- Object
- Afterpay::Item
- Defined in:
- lib/afterpay/item.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#estimated_shipment_date ⇒ Object
Returns the value of attribute estimated_shipment_date.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#page_url ⇒ Object
Returns the value of attribute page_url.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#sku ⇒ Object
Returns the value of attribute sku.
Class Method Summary collapse
-
.from_response(response) ⇒ Object
Builds Item from response.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Item
constructor
A new instance of Item.
- #to_hash ⇒ Object
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
#categories ⇒ Object
Returns the value of attribute categories.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def categories @categories end |
#estimated_shipment_date ⇒ Object
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_url ⇒ Object
Returns the value of attribute image_url.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def image_url @image_url end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def name @name end |
#page_url ⇒ Object
Returns the value of attribute page_url.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def page_url @page_url end |
#price ⇒ Object
Returns the value of attribute price.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
7 8 9 |
# File 'lib/afterpay/item.rb', line 7 def quantity @quantity end |
#sku ⇒ Object
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_hash ⇒ Object
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 |