Class: TophatterMerchant::Product
- Defined in:
- lib/tophatter_merchant/product.rb
Instance Attribute Summary collapse
-
#accessory_description ⇒ Object
Returns the value of attribute accessory_description.
-
#accessory_price ⇒ Object
Returns the value of attribute accessory_price.
-
#admin_banned_at ⇒ Object
Returns the value of attribute admin_banned_at.
-
#admin_hold_at ⇒ Object
Returns the value of attribute admin_hold_at.
-
#admin_hold_responded_at ⇒ Object
Returns the value of attribute admin_hold_responded_at.
-
#admin_reason ⇒ Object
Returns the value of attribute admin_reason.
-
#all_images ⇒ Object
Returns the value of attribute all_images.
-
#approved_at ⇒ Object
Returns the value of attribute approved_at.
-
#available_quantity ⇒ Object
Returns the value of attribute available_quantity.
-
#brand ⇒ Object
Returns the value of attribute brand.
-
#buy_now_price ⇒ Object
Returns the value of attribute buy_now_price.
-
#buy_one_get_one_price ⇒ Object
Returns the value of attribute buy_one_get_one_price.
-
#catalog_only_at ⇒ Object
Returns the value of attribute catalog_only_at.
-
#category ⇒ Object
Returns the value of attribute category.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#cost_basis ⇒ Object
Returns the value of attribute cost_basis.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#days_to_deliver ⇒ Object
Returns the value of attribute days_to_deliver.
-
#days_to_fulfill ⇒ Object
Returns the value of attribute days_to_fulfill.
-
#deleted_at ⇒ Object
Returns the value of attribute deleted_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#disabled_at ⇒ Object
Returns the value of attribute disabled_at.
-
#expedited_days_to_deliver ⇒ Object
Returns the value of attribute expedited_days_to_deliver.
-
#expedited_shipping_price ⇒ Object
Returns the value of attribute expedited_shipping_price.
-
#extra_images ⇒ Object
Returns the value of attribute extra_images.
-
#health_reason ⇒ Object
Returns the value of attribute health_reason.
-
#health_status ⇒ Object
Returns the value of attribute health_status.
-
#held_at ⇒ Object
Returns the value of attribute held_at.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#in_review_at ⇒ Object
Returns the value of attribute in_review_at.
-
#internal_id ⇒ Object
Returns the value of attribute internal_id.
-
#material ⇒ Object
Returns the value of attribute material.
-
#primary_image ⇒ Object
Returns the value of attribute primary_image.
-
#ratings_average ⇒ Object
Returns the value of attribute ratings_average.
-
#ratings_count ⇒ Object
Returns the value of attribute ratings_count.
-
#refused_at ⇒ Object
Returns the value of attribute refused_at.
-
#retail_price ⇒ Object
Returns the value of attribute retail_price.
-
#shipping_origin ⇒ Object
Returns the value of attribute shipping_origin.
-
#shipping_price ⇒ Object
Returns the value of attribute shipping_price.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#starting_bid ⇒ Object
Returns the value of attribute starting_bid.
-
#success_fee_bid ⇒ Object
Returns the value of attribute success_fee_bid.
-
#success_fee_bid_enabled ⇒ Object
Returns the value of attribute success_fee_bid_enabled.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#variations ⇒ Object
Returns the value of attribute variations.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
-
.all(status: nil, category: nil, health_status: nil, page: 1, per_page: 50, pagination: nil, sort: nil) ⇒ Object
ap TophatterMerchant::Product.all.map(&:to_h).
-
.create(data) ⇒ Object
ap TophatterMerchant::Product.create(TophatterMerchant::Product.new({}).fill!.to_h).to_h.
-
.delete(id) ⇒ Object
ap TophatterMerchant::Product.delete(‘FOOBAR’).to_h NOT DOCUMENTED.
-
.disable(id) ⇒ Object
ap TophatterMerchant::Product.disable(‘FOOBAR’).to_h.
-
.enable(id) ⇒ Object
ap TophatterMerchant::Product.enable(‘FOOBAR’).to_h.
-
.enable_catalog_only(id) ⇒ Object
ap TophatterMerchant::Product.enable_catalog_only(‘FOOBAR’).to_h.
- .retrieve(id) ⇒ Object
-
.schema ⇒ Object
ap TophatterMerchant::Product.schema.
- .search(query:, page: 1, per_page: 50, pagination: nil) ⇒ Object
-
.update(id, data) ⇒ Object
ap TophatterMerchant::Product.update(‘FOOBAR’, buy_now_price: 11).to_h.
Instance Method Summary collapse
- #copy ⇒ Object
- #id ⇒ Object
-
#images(size: 'square') ⇒ Object
Available: thumbnail, square, medium, large, original.
- #to_param ⇒ Object
Methods inherited from Resource
attr_accessor, #attributes, attributes, #attributes=, #initialize, #persisted?, #to_h
Constructor Details
This class inherits a constructor from TophatterMerchant::Resource
Instance Attribute Details
#accessory_description ⇒ Object
Returns the value of attribute accessory_description.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def accessory_description @accessory_description end |
#accessory_price ⇒ Object
Returns the value of attribute accessory_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def accessory_price @accessory_price end |
#admin_banned_at ⇒ Object
Returns the value of attribute admin_banned_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def admin_banned_at @admin_banned_at end |
#admin_hold_at ⇒ Object
Returns the value of attribute admin_hold_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def admin_hold_at @admin_hold_at end |
#admin_hold_responded_at ⇒ Object
Returns the value of attribute admin_hold_responded_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def admin_hold_responded_at @admin_hold_responded_at end |
#admin_reason ⇒ Object
Returns the value of attribute admin_reason.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def admin_reason @admin_reason end |
#all_images ⇒ Object
Returns the value of attribute all_images.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def all_images @all_images end |
#approved_at ⇒ Object
Returns the value of attribute approved_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def approved_at @approved_at end |
#available_quantity ⇒ Object
Returns the value of attribute available_quantity.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def available_quantity @available_quantity end |
#brand ⇒ Object
Returns the value of attribute brand.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def brand @brand end |
#buy_now_price ⇒ Object
Returns the value of attribute buy_now_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def buy_now_price @buy_now_price end |
#buy_one_get_one_price ⇒ Object
Returns the value of attribute buy_one_get_one_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def buy_one_get_one_price @buy_one_get_one_price end |
#catalog_only_at ⇒ Object
Returns the value of attribute catalog_only_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def catalog_only_at @catalog_only_at end |
#category ⇒ Object
Returns the value of attribute category.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def category @category end |
#condition ⇒ Object
Returns the value of attribute condition.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def condition @condition end |
#cost_basis ⇒ Object
Returns the value of attribute cost_basis.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def cost_basis @cost_basis end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def created_at @created_at end |
#days_to_deliver ⇒ Object
Returns the value of attribute days_to_deliver.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def days_to_deliver @days_to_deliver end |
#days_to_fulfill ⇒ Object
Returns the value of attribute days_to_fulfill.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def days_to_fulfill @days_to_fulfill end |
#deleted_at ⇒ Object
Returns the value of attribute deleted_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def deleted_at @deleted_at end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def description @description end |
#disabled_at ⇒ Object
Returns the value of attribute disabled_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def disabled_at @disabled_at end |
#expedited_days_to_deliver ⇒ Object
Returns the value of attribute expedited_days_to_deliver.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def expedited_days_to_deliver @expedited_days_to_deliver end |
#expedited_shipping_price ⇒ Object
Returns the value of attribute expedited_shipping_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def expedited_shipping_price @expedited_shipping_price end |
#extra_images ⇒ Object
Returns the value of attribute extra_images.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def extra_images @extra_images end |
#health_reason ⇒ Object
Returns the value of attribute health_reason.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def health_reason @health_reason end |
#health_status ⇒ Object
Returns the value of attribute health_status.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def health_status @health_status end |
#held_at ⇒ Object
Returns the value of attribute held_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def held_at @held_at end |
#identifier ⇒ Object
Returns the value of attribute identifier.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def identifier @identifier end |
#in_review_at ⇒ Object
Returns the value of attribute in_review_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def in_review_at @in_review_at end |
#internal_id ⇒ Object
Returns the value of attribute internal_id.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def internal_id @internal_id end |
#material ⇒ Object
Returns the value of attribute material.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def material @material end |
#primary_image ⇒ Object
Returns the value of attribute primary_image.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def primary_image @primary_image end |
#ratings_average ⇒ Object
Returns the value of attribute ratings_average.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def end |
#ratings_count ⇒ Object
Returns the value of attribute ratings_count.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def end |
#refused_at ⇒ Object
Returns the value of attribute refused_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def refused_at @refused_at end |
#retail_price ⇒ Object
Returns the value of attribute retail_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def retail_price @retail_price end |
#shipping_origin ⇒ Object
Returns the value of attribute shipping_origin.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def shipping_origin @shipping_origin end |
#shipping_price ⇒ Object
Returns the value of attribute shipping_price.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def shipping_price @shipping_price end |
#slug ⇒ Object
Returns the value of attribute slug.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def slug @slug end |
#starting_bid ⇒ Object
Returns the value of attribute starting_bid.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def starting_bid @starting_bid end |
#success_fee_bid ⇒ Object
Returns the value of attribute success_fee_bid.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def success_fee_bid @success_fee_bid end |
#success_fee_bid_enabled ⇒ Object
Returns the value of attribute success_fee_bid_enabled.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def success_fee_bid_enabled @success_fee_bid_enabled end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def title @title end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def updated_at @updated_at end |
#variations ⇒ Object
Returns the value of attribute variations.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def variations @variations end |
#weight ⇒ Object
Returns the value of attribute weight.
3 4 5 |
# File 'lib/tophatter_merchant/product.rb', line 3 def weight @weight end |
Class Method Details
.all(status: nil, category: nil, health_status: nil, page: 1, per_page: 50, pagination: nil, sort: nil) ⇒ Object
ap TophatterMerchant::Product.all.map(&:to_h)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tophatter_merchant/product.rb', line 57 def all(status: nil, category: nil, health_status: nil, page: 1, per_page: 50, pagination: nil, sort: nil) params = { status: status, category: category, health_status: health_status, page: page, per_page: per_page, pagination: pagination, sort: sort } result = get(url: "#{path}.json", params: params) if pagination.present? result['results'] = result['results'].map { |hash| Product.new(hash) } else result = result.map { |hash| Product.new(hash) } end result end |
.create(data) ⇒ Object
ap TophatterMerchant::Product.create(TophatterMerchant::Product.new({}).fill!.to_h).to_h
96 97 98 |
# File 'lib/tophatter_merchant/product.rb', line 96 def create(data) Product.new post(url: "#{path}.json", params: data) end |
.delete(id) ⇒ Object
ap TophatterMerchant::Product.delete(‘FOOBAR’).to_h NOT DOCUMENTED
122 123 124 |
# File 'lib/tophatter_merchant/product.rb', line 122 def delete(id) Product.new post(url: "#{path}/delete.json", params: { identifier: id }) end |
.disable(id) ⇒ Object
ap TophatterMerchant::Product.disable(‘FOOBAR’).to_h
106 107 108 |
# File 'lib/tophatter_merchant/product.rb', line 106 def disable(id) Product.new post(url: "#{path}/disable.json", params: { identifier: id }) end |
.enable(id) ⇒ Object
ap TophatterMerchant::Product.enable(‘FOOBAR’).to_h
111 112 113 |
# File 'lib/tophatter_merchant/product.rb', line 111 def enable(id) Product.new post(url: "#{path}/enable.json", params: { identifier: id }) end |
.enable_catalog_only(id) ⇒ Object
ap TophatterMerchant::Product.enable_catalog_only(‘FOOBAR’).to_h
116 117 118 |
# File 'lib/tophatter_merchant/product.rb', line 116 def enable_catalog_only(id) Product.new post(url: "#{path}/enable_catalog_only.json", params: { identifier: id }) end |
.retrieve(id) ⇒ Object
91 92 93 |
# File 'lib/tophatter_merchant/product.rb', line 91 def retrieve(id) Product.new get(url: "#{path}/retrieve.json", params: { identifier: id }) end |
.schema ⇒ Object
ap TophatterMerchant::Product.schema
52 53 54 |
# File 'lib/tophatter_merchant/product.rb', line 52 def schema get(url: "#{path}/schema.json") end |
.search(query:, page: 1, per_page: 50, pagination: nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/tophatter_merchant/product.rb', line 79 def search(query:, page: 1, per_page: 50, pagination: nil) result = get(url: "#{path}/search.json", params: { query: query, page: page, per_page: per_page, pagination: pagination }) if pagination.present? result['results'] = result['results'].map { |hash| Product.new(hash) } else result = result.map { |hash| Product.new(hash) } end result end |
.update(id, data) ⇒ Object
ap TophatterMerchant::Product.update(‘FOOBAR’, buy_now_price: 11).to_h
101 102 103 |
# File 'lib/tophatter_merchant/product.rb', line 101 def update(id, data) Product.new post(url: "#{path}/update.json", params: data.merge(identifier: id)) end |
Instance Method Details
#copy ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tophatter_merchant/product.rb', line 34 def copy hash = to_h # Delete the keys that shouldn't be copied. %w(identifier primary_image extra_images all_images ratings_average ratings_count created_at updated_at disabled_at deleted_at catalog_only_at in_review_at approved_at refused_at held_at blacklisted_at slug admin_hold_at).each do |key| hash.delete(key) hash['variations'].each { |variation| variation.delete(key) } end Product.new(hash) end |
#id ⇒ Object
21 22 23 |
# File 'lib/tophatter_merchant/product.rb', line 21 def id created_at.present? ? identifier : nil end |
#images(size: 'square') ⇒ Object
Available: thumbnail, square, medium, large, original.
26 27 28 29 30 31 32 |
# File 'lib/tophatter_merchant/product.rb', line 26 def images(size: 'square') if persisted? all_images.collect { |image| image[size] } else ([primary_image] + extra_images.to_s.split('|')).compact end end |
#to_param ⇒ Object
46 47 48 |
# File 'lib/tophatter_merchant/product.rb', line 46 def to_param slug || identifier end |