Class: SageWorld::Api::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/sage_world/api/product.rb

Constant Summary collapse

DEFAULT_SEARCH_PARAMS =
{
  quick_search: ''
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_id) ⇒ Product

Returns a new instance of Product.



14
15
16
# File 'lib/sage_world/api/product.rb', line 14

def initialize(product_id)
  @product_id = product_id
end

Class Method Details

.cached_data(supp_id, params = {}) ⇒ Object



168
169
170
171
# File 'lib/sage_world/api/product.rb', line 168

def self.cached_data(supp_id, params={})
  response = SageWorld::Client.new(cached_product_params(supp_id, params)).send_request
  SageWorld::ResponseHandler.new(response)
end

.search(keyword, options = {}) ⇒ Object

Maxitems to find (<=1000) e.g response = SageWorld::Api::Product.search(“Ceramic mug”, { pr_name: “13 Ceramic Mug”, max_total_items: 100 })



161
162
163
164
165
166
# File 'lib/sage_world/api/product.rb', line 161

def self.search(keyword, options = {})
  options[:quick_search] = keyword
  params = DEFAULT_SEARCH_PARAMS.merge(options)
  response = SageWorld::Client.new(search_product_params(params)).send_request
  SageWorld::ResponseHandler.new(response)
end

Instance Method Details

#details(options = {}) ⇒ Object

Product Details Usage: product = SageWorld::Api::Product.new(“Product_id_or_spc”) response = product.details response.body => product details as hash



24
25
26
27
28
29
30
31
32
# File 'lib/sage_world/api/product.rb', line 24

def details(options = {})
  if @existing_options == options
    @response
  else
    @existing_options = options
    response = SageWorld::Client.new(find_product_params(@product_id ,options)).send_request
    @response = SageWorld::ResponseHandler.new(response)
  end
end