Class: TophatterMerchant::Product

Inherits:
Resource
  • Object
show all
Defined in:
lib/tophatter_merchant/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_descriptionObject

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_priceObject

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_atObject

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_atObject

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_atObject

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_reasonObject

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_imagesObject

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_atObject

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_quantityObject

Returns the value of attribute available_quantity.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def available_quantity
  @available_quantity
end

#brandObject

Returns the value of attribute brand.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def brand
  @brand
end

#buy_now_priceObject

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_priceObject

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_atObject

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

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def category
  @category
end

#conditionObject

Returns the value of attribute condition.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def condition
  @condition
end

#cost_basisObject

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_atObject

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_deliverObject

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_fulfillObject

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_atObject

Returns the value of attribute deleted_at.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def deleted_at
  @deleted_at
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def description
  @description
end

#disabled_atObject

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_deliverObject

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_priceObject

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_imagesObject

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_reasonObject

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_statusObject

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_atObject

Returns the value of attribute held_at.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def held_at
  @held_at
end

#identifierObject

Returns the value of attribute identifier.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def identifier
  @identifier
end

#in_review_atObject

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_idObject

Returns the value of attribute internal_id.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def internal_id
  @internal_id
end

#materialObject

Returns the value of attribute material.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def material
  @material
end

#primary_imageObject

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_averageObject

Returns the value of attribute ratings_average.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def ratings_average
  @ratings_average
end

#ratings_countObject

Returns the value of attribute ratings_count.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def ratings_count
  @ratings_count
end

#refused_atObject

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_priceObject

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_originObject

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_priceObject

Returns the value of attribute shipping_price.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def shipping_price
  @shipping_price
end

#slugObject

Returns the value of attribute slug.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def slug
  @slug
end

#starting_bidObject

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_bidObject

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_enabledObject

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

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def updated_at
  @updated_at
end

#variationsObject

Returns the value of attribute variations.



3
4
5
# File 'lib/tophatter_merchant/product.rb', line 3

def variations
  @variations
end

#weightObject

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

.schemaObject

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

#copyObject



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

#idObject



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_paramObject



46
47
48
# File 'lib/tophatter_merchant/product.rb', line 46

def to_param
  slug || identifier
end