Class: BaseCRM::AssociatedContactsService
- Inherits:
-
Object
- Object
- BaseCRM::AssociatedContactsService
- Defined in:
- lib/basecrm/services/associated_contacts_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:contact_id, :role]
Instance Method Summary collapse
-
#all(deal_id) ⇒ Enumerable
Retrieve deal’s associated contacts.
-
#create(deal_id, associated_contact) ⇒ AssociatedContact
Create an associated contact.
-
#destroy(deal_id, contact_id) ⇒ Boolean
Remove an associated contact.
-
#initialize(client) ⇒ AssociatedContactsService
constructor
A new instance of AssociatedContactsService.
-
#where(deal_id, options = {}) ⇒ Array<AssociatedContact>
Retrieve deal’s associated contacts.
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).
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
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
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
32 33 34 35 36 |
# File 'lib/basecrm/services/associated_contacts_service.rb', line 32 def where(deal_id, = {}) _, _, root = @client.get("/deals/#{deal_id}/associated_contacts", ) root[:items].map{ |item| AssociatedContact.new(item[:data]) } end |