Class: ZohoCrm::Record::ListService

Inherits:
BaseService
  • Object
show all
Includes:
Enumerable
Defined in:
lib/zoho_crm/record/list_service.rb

Constant Summary collapse

SORT_COLUMNS =
%w[id Created_Time Modified_Time].freeze
SORT_ORDERS =
%w[asc desc].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#call, #each

Constructor Details

#initialize(module_name:, fields:, page: 1, per_page: Float::INFINITY, sort_by: 'id', sort_order: 'desc') ⇒ ListService

List records.

www.zoho.com/crm/developer/docs/api/v7/get-records.html

Examples

service = ZohoCrm::Record::ListService.call(module_name: 'Contacts', fields: 'Email,Last_Name').first
service.id

If you don’t provide the ‘per_page` argument, multiple API requests will be made untill all records have been returned. You could be rate limited, so use wisely.

ZohoCrm::Record::ListService.call(module_name: 'Contacts', fields: 'Email,Last_Name', page: 1, per_page: 10).each { _1 }

Sort by column.

ZohoCrm::Record::ListService.call(module_name: 'Contacts', fields: 'Email,Last_Name', sort_by: 'id', sort_order: 'asc').map { _1 }

Columns to sort by are ‘id`, `Created_Time` and `Modified_Time`.

GET /crm/v7/:module_name



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zoho_crm/record/list_service.rb', line 40

def initialize(module_name:, fields:, page: 1, per_page: Float::INFINITY, sort_by: 'id', sort_order: 'desc')
  @module_name = module_name
  @fields      = fields
  @sort_by     = sort_by
  @sort_order  = sort_order

  super(
    path:         module_name,
    list_key:     'data',
    facade_klass: ZohoCrm::Record::Facade,
    page:         page,
    per_page:     per_page
  )
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/zoho_crm/record/list_service.rb', line 9

def fields
  @fields
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



9
10
11
# File 'lib/zoho_crm/record/list_service.rb', line 9

def module_name
  @module_name
end

#sort_byObject (readonly)

Returns the value of attribute sort_by.



9
10
11
# File 'lib/zoho_crm/record/list_service.rb', line 9

def sort_by
  @sort_by
end

#sort_orderObject (readonly)

Returns the value of attribute sort_order.



9
10
11
# File 'lib/zoho_crm/record/list_service.rb', line 9

def sort_order
  @sort_order
end