Class: BaseCRM::CallsService

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

Constant Summary collapse

OPTS_KEYS_TO_PERSIST =
Set[:user_id, :summary, :recording_url, :outcome_id, :duration, :phone_number, :incoming, :missed, :external_id, :resource_id, :resource_type, :associated_deal_ids, :made_at]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ CallsService

Returns a new instance of CallsService.



7
8
9
# File 'lib/basecrm/services/calls_service.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#allEnumerable

Retrieve all calls

get ‘/calls’

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

Returns:

  • (Enumerable)

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



17
18
19
# File 'lib/basecrm/services/calls_service.rb', line 17

def all
  PaginatedResource.new(self)
end

#create(call) ⇒ Call

Create a call

post ‘/calls’

Create a new call

Parameters:

  • call (Call, Hash)

    Either object of the Call type or Hash. This object’s attributes describe the object to be created.

Returns:

  • (Call)

    The resulting object represting created resource.



50
51
52
53
54
55
56
57
# File 'lib/basecrm/services/calls_service.rb', line 50

def create(call)
  validate_type!(call)

  attributes = sanitize(call)
  _, _, root = @client.post("/calls", attributes)

  Call.new(root[:data])
end

#destroy(id) ⇒ Boolean

Delete a call

delete ‘/calls/BaseCRM#id

Delete an existing call If the specified call does not exist, this query returns an error This operation cannot be undone

Parameters:

  • id (Integer)

    Unique identifier of a Call

Returns:

  • (Boolean)

    Status of the operation.



106
107
108
109
# File 'lib/basecrm/services/calls_service.rb', line 106

def destroy(id)
  status, _, _ = @client.delete("/calls/#{id}")
  status == 204
end

#find(id) ⇒ Call

Retrieve a single call

get ‘/calls/BaseCRM#id

Returns a single call available to the user, according to the unique call ID provided If the specified call does not exist, this query returns an error

Parameters:

  • id (Integer)

    Unique identifier of a Call

Returns:

  • (Call)

    Searched resource object.



69
70
71
72
73
# File 'lib/basecrm/services/calls_service.rb', line 69

def find(id)
  _, _, root = @client.get("/calls/#{id}")

  Call.new(root[:data])
end

#update(call) ⇒ Call

Update a call

put ‘/calls/BaseCRM#id

Allows to attach a Contact or Lead to an existing Call, or change it’s current association

Parameters:

  • call (Call, Hash)

    Either object of the Call type or Hash. This object’s attributes describe the object to be updated.

Returns:

  • (Call)

    The resulting object represting updated resource.



84
85
86
87
88
89
90
91
92
93
# File 'lib/basecrm/services/calls_service.rb', line 84

def update(call)
  validate_type!(call)
  params = extract_params!(call, :id)
  id = params[:id]

  attributes = sanitize(call)
  _, _, root = @client.put("/calls/#{id}", attributes)

  Call.new(root[:data])
end

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

Retrieve all calls

get ‘/calls’

Returns all calls available to the user, according to the parameters provided Calls are always sorted by made_at in descending order

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.

  • :ids (String)

    Comma-separated list of call IDs to be returned in request.

  • :resource_id (Integer)

    Unique identifier of the resource the call is attached to.

  • :resource_type (String)

    Name of the resource type the call is attached to.

Returns:

  • (Array<Call>)

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



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

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

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