Class: TophatterMerchant::Product

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

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Resource

#initialize, #to_hash

Constructor Details

This class inherits a constructor from TophatterMerchant::Resource

Instance Attribute Details

#all_imagesObject



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

def all_images
  @all_images
end

#available_quantityObject



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

def available_quantity
  @available_quantity
end

#brandObject



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

def brand
  @brand
end

#buy_now_priceObject



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

def buy_now_price
  @buy_now_price
end

#buy_one_get_one_priceObject



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

def buy_one_get_one_price
  @buy_one_get_one_price
end

#categoryObject



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

def category
  @category
end

#conditionObject



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

def condition
  @condition
end

#cost_basisObject



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

def cost_basis
  @cost_basis
end

#created_atObject



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

def created_at
  @created_at
end

#days_to_deliverObject



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

def days_to_deliver
  @days_to_deliver
end

#days_to_fulfillObject



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

def days_to_fulfill
  @days_to_fulfill
end

#deleted_atObject



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

def deleted_at
  @deleted_at
end

#descriptionObject



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

def description
  @description
end

#disabled_atObject



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

def disabled_at
  @disabled_at
end

#expedited_days_to_deliverObject



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

def expedited_days_to_deliver
  @expedited_days_to_deliver
end

#expedited_shipping_priceObject



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

def expedited_shipping_price
  @expedited_shipping_price
end

#extra_imagesObject



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

def extra_images
  @extra_images
end

#identifierObject



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

def identifier
  @identifier
end

#internal_idObject



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

def internal_id
  @internal_id
end

#materialObject



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

def material
  @material
end

#primary_imageObject



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

def primary_image
  @primary_image
end

#ratings_averageObject



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

def ratings_average
  @ratings_average
end

#ratings_countObject



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

def ratings_count
  @ratings_count
end

#retail_priceObject



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

def retail_price
  @retail_price
end

#shipping_originObject



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

def shipping_origin
  @shipping_origin
end

#shipping_priceObject



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

def shipping_price
  @shipping_price
end

#titleObject



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

def title
  @title
end

#updated_atObject



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

def updated_at
  @updated_at
end

#variationsObject



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

def variations
  @variations
end

#weightObject



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

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

merchant-api.tophatter.com/docs/product-list TophatterMerchant::Product.all(status: ‘in_stock’)



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tophatter_merchant/product.rb', line 38

def all(status: nil, category: nil, health_status: nil, page: 1, per_page: 50, pagination: nil, sort: nil)
  result = get(url: "#{path}.json", params: { status: status, category: category, health_status: health_status, page: page, per_page: per_page, pagination: pagination, sort: sort }.reject { |_k, v| v.nil? })

  if pagination
    result['results'] = result['results'].map { |hash| Product.new(hash) }
  else
    result = result.map { |hash| Product.new(hash) }
  end

  result
end

.create(data) ⇒ Object



71
72
73
# File 'lib/tophatter_merchant/product.rb', line 71

def create(data)
  Product.new post(url: "#{path}.json", params: data)
end

.disable(id) ⇒ Object

merchant-api.tophatter.com/docs/product-disable TophatterMerchant::Product.disable(‘amazon-fire-7’).disabled_at



83
84
85
# File 'lib/tophatter_merchant/product.rb', line 83

def disable(id)
  Product.new post(url: "#{path}/disable.json", params: { identifier: id })
end

.enable(id) ⇒ Object

merchant-api.tophatter.com/docs/product-enable TophatterMerchant::Product.enable(‘amazon-fire-7’).disabled_at



89
90
91
# File 'lib/tophatter_merchant/product.rb', line 89

def enable(id)
  Product.new post(url: "#{path}/enable.json", params: { identifier: id })
end

.retrieve(id) ⇒ Object

merchant-api.tophatter.com/docs/product-retrieve TophatterMerchant::Product.retrieve(‘amazon-fire-7’)



66
67
68
# File 'lib/tophatter_merchant/product.rb', line 66

def retrieve(id)
  Product.new get(url: "#{path}/retrieve.json", params: { identifier: id })
end

.search(query:, page: 1, per_page: 50, pagination: nil) ⇒ Object

merchant-api.tophatter.com/docs/product-search TophatterMerchant::Product.search(query: ‘Kindle’)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tophatter_merchant/product.rb', line 52

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
    result['results'] = result['results'].map { |hash| Product.new(hash) }
  else
    result = result.map { |hash| Product.new(hash) }
  end

  result
end

.update(id, data) ⇒ Object

merchant-api.tophatter.com/docs/product-update TophatterMerchant::Product.update(‘amazon-fire-7’, brand: ‘Amazon’).brand



77
78
79
# File 'lib/tophatter_merchant/product.rb', line 77

def update(id, data)
  Product.new post(url: "#{path}/update.json", params: data.merge(identifier: id))
end