Class: Moloni::Product

Inherits:
BaseModel show all
Defined in:
lib/moloni/models/product.rb

Constant Summary

Constants inherited from BaseModel

BaseModel::COMMON_ACRONYMS, BaseModel::ERROR_MESSAGES

Class Method Summary collapse

Methods inherited from BaseModel

all, composed_params, count, create, delete, find, format_url, #format_url, method_missing, post, respond_to_missing?

Class Method Details

.each_page(method, args = nil, qty: 50, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moloni/models/product.rb', line 9

def self.each_page(method, args = nil, qty: 50, &block)
  return enum_for(:each_page, method, args, qty:) unless block

  args ||= {}
  offset = 0

  loop do
    page = send(method, args.merge(offset:, qty:))
    break unless page.is_a?(Array)
    break if page.empty?

    yield page
    break if page.length < qty

    offset += qty
  end
end

.paginate(method, args = nil, qty: 50, &block) ⇒ Object



27
28
29
30
31
# File 'lib/moloni/models/product.rb', line 27

def self.paginate(method, args = nil, qty: 50, &block)
  return enum_for(:paginate, method, args, qty:) unless block

  each_page(method, args, qty:) { |page| page.each(&block) }
end

.search_by_name(args) ⇒ Object

rubocop:enable Naming/MethodName



40
41
42
# File 'lib/moloni/models/product.rb', line 40

def self.search_by_name(args)
  post('getByName/', args)
end

.searchByName(args) ⇒ Object

Backward-compatible alias (v0.4 API name) rubocop:disable Naming/MethodName



35
36
37
# File 'lib/moloni/models/product.rb', line 35

def self.searchByName(args)
  post('getByName/', args)
end