Class: Varejonline::API::Products

Inherits:
Client
  • Object
show all
Defined in:
lib/varejonline/api/products.rb

Instance Attribute Summary

Attributes inherited from Client

#access_token

Instance Method Summary collapse

Methods inherited from Client

#card_negotiations, #category_levels, #client_classes, #companies, #credit_limits, #default_entries, #entities, #initialize, #installments, #orders, #payables, #payment_conditions, #payments, #product_balances, #product_categories, #products, #provisions, #receivables, #sales_history, #sellers, #third_parties, #units, #user_data

Methods included from ClassMethods

#require_all

Constructor Details

This class inherits a constructor from Varejonline::Client

Instance Method Details

#find(id) ⇒ Object



16
17
18
# File 'lib/varejonline/api/products.rb', line 16

def find(id)
  return parse_response(self.class.get("/#{id}", body: build_body, headers: header))
end

#list(searcher = nil) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/varejonline/api/products.rb', line 9

def list(searcher = nil)
  raise ArgumentError unless searcher.nil? || searcher.is_a?(Varejonline::Searcher::Commercial::ProductSearcher)

  return parse_response(self.class.get('/', body: build_body(searcher.as_parameter), headers: header)) if searcher
  return parse_response(self.class.get('/', body: build_body, headers: header)) unless searcher
end

#save(data) ⇒ Object Also known as: create

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/varejonline/api/products.rb', line 20

def save(data)
  return parse_response(self.class.post('/', body: build_body(data), headers: header))              if data.is_a?(Hash)
  return parse_response(self.class.post('/', body: build_body(data.as_parameter), headers: header)) if data.is_a?(Varejonline::Entity::Commercial::Product)

  raise ArgumentError
end

#update(id, data) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'lib/varejonline/api/products.rb', line 28

def update(id, data)
  return parse_response(self.class.put("/#{id}", body: build_body(data), headers: header))              if data.is_a?(Hash)
  return parse_response(self.class.put("/#{id}", body: build_body(data.as_parameter), headers: header)) if data.is_a?(Varejonline::Entity::Commercial::Product)

  raise ArgumentError
end