Class: CatalogAPI::Item
- Inherits:
-
Object
- Object
- CatalogAPI::Item
- Defined in:
- lib/catalogapi/item.rb
Instance Attribute Summary collapse
-
#brand ⇒ Object
readonly
Returns the value of attribute brand.
-
#catalog_item_id ⇒ Object
readonly
Returns the value of attribute catalog_item_id.
-
#catalog_price ⇒ Object
readonly
Returns the value of attribute catalog_price.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#description ⇒ Object
Returns the value of attribute description.
-
#has_options ⇒ Object
readonly
Returns the value of attribute has_options.
-
#image_150 ⇒ Object
readonly
Returns the value of attribute image_150.
-
#image_300 ⇒ Object
readonly
Returns the value of attribute image_300.
-
#image_75 ⇒ Object
readonly
Returns the value of attribute image_75.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#option_id ⇒ Object
readonly
Returns the value of attribute option_id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#original_points ⇒ Object
readonly
Returns the value of attribute original_points.
-
#original_price ⇒ Object
readonly
Returns the value of attribute original_price.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#retail_price ⇒ Object
readonly
Returns the value of attribute retail_price.
-
#shipping_estimate ⇒ Object
readonly
Returns the value of attribute shipping_estimate.
-
#socket_id ⇒ Object
readonly
Returns the value of attribute socket_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Item
constructor
A new instance of Item.
- #order_params ⇒ Object
- #orderable? ⇒ Boolean
- #view ⇒ Object
Constructor Details
#initialize(opts) ⇒ Item
Returns a new instance of Item.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/catalogapi/item.rb', line 13 def initialize(opts) @brand = opts[:brand] @catalog_item_id = opts[:catalog_item_id] @catalog_price = opts[:catalog_price] @categories = opts[:categories].to_h[:integer] @currency = opts[:currency] || 'USD' @description = opts[:description] @has_options = opts[:has_options] @image_150 = opts[:image_150] @image_300 = opts[:image_300] @image_75 = opts[:image_75] @model = opts[:model] @name = opts[:name] @options = opts[:options] @original_points = opts[:original_points] @original_price = opts[:original_price] @points = opts[:points] @rank = opts[:rank] @retail_price = opts[:retail_price] @shipping_estimate = opts[:shipping_estimate] @socket_id = opts[:socket_id] @tags = opts[:tags].to_h[:string] @quantity = opts[:quantity] || 1 @option_id = opts[:option_id] end |
Instance Attribute Details
#brand ⇒ Object (readonly)
Returns the value of attribute brand.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def brand @brand end |
#catalog_item_id ⇒ Object (readonly)
Returns the value of attribute catalog_item_id.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def catalog_item_id @catalog_item_id end |
#catalog_price ⇒ Object (readonly)
Returns the value of attribute catalog_price.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def catalog_price @catalog_price end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def categories @categories end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def currency @currency end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/catalogapi/item.rb', line 5 def description @description end |
#has_options ⇒ Object (readonly)
Returns the value of attribute has_options.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def @has_options end |
#image_150 ⇒ Object (readonly)
Returns the value of attribute image_150.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def image_150 @image_150 end |
#image_300 ⇒ Object (readonly)
Returns the value of attribute image_300.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def image_300 @image_300 end |
#image_75 ⇒ Object (readonly)
Returns the value of attribute image_75.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def image_75 @image_75 end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def name @name end |
#option_id ⇒ Object (readonly)
Returns the value of attribute option_id.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def option_id @option_id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def @options end |
#original_points ⇒ Object (readonly)
Returns the value of attribute original_points.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def original_points @original_points end |
#original_price ⇒ Object (readonly)
Returns the value of attribute original_price.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def original_price @original_price end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def points @points end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def quantity @quantity end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def rank @rank end |
#retail_price ⇒ Object (readonly)
Returns the value of attribute retail_price.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def retail_price @retail_price end |
#shipping_estimate ⇒ Object (readonly)
Returns the value of attribute shipping_estimate.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def shipping_estimate @shipping_estimate end |
#socket_id ⇒ Object (readonly)
Returns the value of attribute socket_id.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def socket_id @socket_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/catalogapi/item.rb', line 7 def @tags end |
Instance Method Details
#order_params ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/catalogapi/item.rb', line 39 def order_params { catalog_item_id: catalog_item_id, quantity: quantity, currency: currency, catalog_price: catalog_price.to_f, option_id: option_id }.reject { |_k, v| v.nil? }.to_h end |
#orderable? ⇒ Boolean
49 50 51 |
# File 'lib/catalogapi/item.rb', line 49 def orderable? !catalog_item_id.nil? && !catalog_price.nil? end |
#view ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/catalogapi/item.rb', line 53 def view raise CatalogAPI::Error, 'No Socket ID' if socket_id.nil? raise CatalogAPI::Error, 'No Catalog Item ID' if catalog_item_id.nil? request = CatalogAPI.request.new(:view_item) .get(socket_id: socket_id, catalog_item_id: catalog_item_id) fields = request.json.dig(:view_item_response, :view_item_result, :item) request.data = self.class.new(fields.merge(socket_id: socket_id)) request end |