Class: BaseCRM::ContactsService
- Inherits:
-
Object
- Object
- BaseCRM::ContactsService
- Defined in:
- lib/basecrm/services/contacts_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:address, :contact_id, :custom_fields, :customer_status, :description, :email, :facebook, :fax, :first_name, :industry, :is_organization, :last_name, :linkedin, :mobile, :name, :owner_id, :phone, :prospect_status, :skype, :tags, :title, :twitter, :website]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all contacts.
-
#create(contact) ⇒ Contact
Create a contact.
-
#destroy(id) ⇒ Boolean
Delete a contact.
-
#find(id) ⇒ Contact
Retrieve a single contact.
-
#initialize(client) ⇒ ContactsService
constructor
A new instance of ContactsService.
-
#update(contact) ⇒ Contact
Update a contact.
-
#where(options = {}) ⇒ Array<Contact>
Retrieve all contacts.
Constructor Details
#initialize(client) ⇒ ContactsService
Returns a new instance of ContactsService.
7 8 9 |
# File 'lib/basecrm/services/contacts_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all contacts
get ‘/contacts’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/contacts_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(contact) ⇒ Contact
Create a contact
post ‘/contacts’
Create a new contact A contact may represent a single individual or an organization
58 59 60 61 62 63 64 65 |
# File 'lib/basecrm/services/contacts_service.rb', line 58 def create(contact) validate_type!(contact) attributes = sanitize(contact) _, _, root = @client.post("/contacts", attributes) Contact.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a contact
delete ‘/contacts/BaseCRM#id’
Delete an existing contact If the specified contact does not exist, the request will return an error This operation cannot be undone
117 118 119 120 |
# File 'lib/basecrm/services/contacts_service.rb', line 117 def destroy(id) status, _, _ = @client.delete("/contacts/#{id}") status == 204 end |
#find(id) ⇒ Contact
Retrieve a single contact
get ‘/contacts/BaseCRM#id’
Returns a single contact available to the user, according to the unique contact ID provided If the specified contact does not exist, the request will return an error
77 78 79 80 81 |
# File 'lib/basecrm/services/contacts_service.rb', line 77 def find(id) _, _, root = @client.get("/contacts/#{id}") Contact.new(root[:data]) end |
#update(contact) ⇒ Contact
Update a contact
put ‘/contacts/BaseCRM#id’
Updates contact information If the specified contact does not exist, the request will return an error Notice When updating contact tags, you need to provide all tags Any missing tag will be removed from a contact’s tags
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/basecrm/services/contacts_service.rb', line 95 def update(contact) validate_type!(contact) params = extract_params!(contact, :id) id = params[:id] attributes = sanitize(contact) _, _, root = @client.put("/contacts/#{id}", attributes) Contact.new(root[:data]) end |
#where(options = {}) ⇒ Array<Contact>
Retrieve all contacts
get ‘/contacts’
Returns all contacts available to the user according to the parameters provided
42 43 44 45 46 |
# File 'lib/basecrm/services/contacts_service.rb', line 42 def where( = {}) _, _, root = @client.get("/contacts", ) root[:items].map{ |item| Contact.new(item[:data]) } end |