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

Returns a new instance of 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/BaseCRM#deal_id/associated_contacts’

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/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/BaseCRM#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

Parameters:

  • deal_id (Integer)

    Unique identifier of a Deal

  • associated_contact (AssociatedContact, Hash)

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

Returns:



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/BaseCRM#deal_id/associated_contacts/BaseCRM#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

Parameters:

  • deal_id (Integer)

    Unique identifier of a Deal

  • contact_id (Integer)

    Unique identifier of a Contact

Returns:

  • (Boolean)

    Status of the operation.



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/BaseCRM#deal_id/associated_contacts’

Returns all deal associated contacts

Parameters:

  • deal_id (Integer)

    Unique identifier of a Deal

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

Returns:

  • (Array<AssociatedContact>)

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



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