Class: BaseCRM::AssociatedContactsService

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

Constant Summary collapse

OPTS_KEYS_TO_PERSIST =
Set[:contact_id, :role]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AssociatedContactsService


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

def initialize(client)
  @client = client
end

Instance Method Details

#all(deal_id) ⇒ Enumerable

Retrieve deal's associated contacts

get '/deals/deal_id/associated_contacts'

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


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

def all(deal_id)
  PaginatedResource.new(self, deal_id)
end

#create(deal_id, associated_contact) ⇒ AssociatedContact

Create an associated contact

post '/deals/deal_id/associated_contacts'

Creates a deal's associated contact and its role If the specified deal or contact does not exist, the request will return an error


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

def create(deal_id, associated_contact)
  validate_type!(associated_contact)

  attributes = sanitize(associated_contact)
  _, _, root = @client.post("/deals/#{deal_id}/associated_contacts", attributes)

  AssociatedContact.new(root[:data])
end

#destroy(deal_id, contact_id) ⇒ Boolean

Remove an associated contact

delete '/deals/deal_id/associated_contacts/contact_id'

Remove a deal's associated contact If a deal with the supplied unique identifier does not exist, it returns an error This operation cannot be undone


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

def destroy(deal_id, contact_id)
  status, _, _ = @client.delete("/deals/#{deal_id}/associated_contacts/#{contact_id}")
  status == 204
end

#where(deal_id, options = {}) ⇒ Array<AssociatedContact>

Retrieve deal's associated contacts

get '/deals/deal_id/associated_contacts'

Returns all deal associated contacts

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. Default limit is 25 and the maximum number that can be returned is 100.


32
33
34
35
36
# File 'lib/basecrm/services/associated_contacts_service.rb', line 32

def where(deal_id, options = {})
  _, _, root = @client.get("/deals/#{deal_id}/associated_contacts", options)

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