Class: ZohoCrm::Record::SearchService

Inherits:
BaseService
  • Object
show all
Includes:
Enumerable
Defined in:
lib/zoho_crm/record/search_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:, page: 1, per_page: Float::INFINITY, sort_by: 'id', sort_order: 'desc', email: nil, phone: nil, criteria: nil, word: nil) ⇒ SearchService

List records.

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

Examples

service = ZohoCrm::Record::SearchService.call(module_name: 'Contacts', email: '[email protected]').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::SearchService.call(module_name: 'Contacts', email: '[email protected]', page: 1, per_page: 10).each { _1 }

Sort by column.

ZohoCrm::Record::SearchService.call(module_name: 'Contacts', email: '[email protected]', sort_by: 'Modified_Time', sort_order: 'asc').map { _1 }

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

Search by email.

ZohoCrm::Record::SearchService.call(module_name: 'Contacts', email: '[email protected]').map { _1 }

Search by phone.

ZohoCrm::Record::SearchService.call(module_name: 'Contacts', phone: '0123456789').map { _1 }

Search by criteria.

ZohoCrm::Record::SearchService.call(module_name: 'Contacts', criteria: 'Created_Time:between:2025-01-01T06:00:00+00:00,2025-01-30T06:00:00+00:00').map { _1 }

Search by word.

ZohoCrm::Record::SearchService.call(module_name: 'Contacts', word: 'eric').map { _1 }

GET /crm/v7/:module_name



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zoho_crm/record/search_service.rb', line 56

def initialize(module_name:, page: 1, per_page: Float::INFINITY, sort_by: 'id', sort_order: 'desc', email: nil, phone: nil, criteria: nil, word: nil)
  @module_name = module_name
  @sort_by     = sort_by
  @sort_order  = sort_order
  @email       = email
  @phone       = phone
  @criteria    = criteria
  @word        = word

  super(
    path:         "#{module_name}/search",
    list_key:     'data',
    facade_klass: ZohoCrm::Record::Facade,
    page:         page,
    per_page:     per_page
  )
end

Instance Attribute Details

#criteriaObject (readonly)

Returns the value of attribute criteria.



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

def criteria
  @criteria
end

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



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

def module_name
  @module_name
end

#phoneObject (readonly)

Returns the value of attribute phone.



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

def phone
  @phone
end

#sort_byObject (readonly)

Returns the value of attribute sort_by.



9
10
11
# File 'lib/zoho_crm/record/search_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/search_service.rb', line 9

def sort_order
  @sort_order
end

#wordObject (readonly)

Returns the value of attribute word.



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

def word
  @word
end