Class: BaseCRM::VisitsService

Inherits:
Object
  • Object
show all
Defined in:
lib/basecrm/services/visits_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ VisitsService

Returns a new instance of VisitsService.



5
6
7
# File 'lib/basecrm/services/visits_service.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#allEnumerable

Retrieve visits

get ‘/visits’

If you want to use filtering or sorting (see #where).

Returns:

  • (Enumerable)

    Paginated resource you can use to iterate over all the resources.



15
16
17
# File 'lib/basecrm/services/visits_service.rb', line 15

def all
  PaginatedResource.new(self)
end

#where(options = {}) ⇒ Array<Visit>

Retrieve visits

get ‘/visits’

Returns Visits, according to the parameters provided

Parameters:

  • options (Hash) (defaults to: {})

    Search options

Options Hash (options):

  • :page (Integer) — default: 1

    Page number to start from. Page numbering starts at 1, and omitting the ‘page` parameter will return the first page.

  • :per_page (Integer) — default: 25

    Number of records to return per page. The default limit is 25 and the maximum number that can be returned at one time is 100.

  • :outcome_id (Integer)

    Unique identifier of a visit outcome.

  • :creator_id (Integer)

    Unique identifier of a user who created a visit.

  • :resource_id (Integer)

    Unique identifier of a resource the visit is attached to. Requires also resource_type to be specified.

  • :resource_type (String)

    Name of a resource type the visit is attached to. Requires also resource_id to be specified.

  • :rep_location_verification_status (String)

    The status of the location verification of the device that created the visit (sales representative).

  • :sort_by (String) — default: id:asc

    A field to sort by. Default ordering is ascending. If you want to change the sort order to descending, append :desc to the filed e.g. sort_by=visited_at:desc.

Returns:

  • (Array<Visit>)

    The list of Visits for the first page, unless otherwise specified.



35
36
37
38
39
# File 'lib/basecrm/services/visits_service.rb', line 35

def where(options = {})
  _, _, root = @client.get("/visits", options)

  root[:items].map{ |item| Visit.new(item[:data]) }
end