Module: Moonclerk::APIOperations::List

Included in:
Customer, Form, ListObject, Payment
Defined in:
lib/moonclerk/api_operations/list.rb

Instance Method Summary collapse

Instance Method Details

#list(params = {}) ⇒ Object Also known as: all



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/moonclerk/api_operations/list.rb', line 4

def list(params = {})
  response = request(:get, url, params)

  klass = self.is_a?(Moonclerk::ListObject) ? self[:object] : self.class_name.underscore.downcase
  obj = ListObject.construct_from({ data: response, object: klass })
  
  # Set a count and offset so that we can fetch the same number when accessing the
  # next and previous pages
  obj.count = params[:count]
  obj.offset = params[:offset]

  obj
end

#where(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/moonclerk/api_operations/list.rb', line 23

def where(options = {})
  options = Util.symbolize_names(options)
  params = {}
  (@permitted_attributes + default_param_keys).each do |key|
    if options[key]
      if key.to_s.split("_").last =~ /from|to/
        params[key] = CGI.escape(options[key].strftime("%Y-%m-%d"))
      else
        params[key] = CGI.escape(options[key].to_s)
      end
    end
  end

  list(params)
end