Module: Insightly2::DSL::Contacts

Included in:
Insightly2::DSL
Defined in:
lib/insightly2/dsl/contacts.rb

Instance Method Summary collapse

Instance Method Details

#create_contact(contact: nil) ⇒ Insightly2::Resources::Contact?

POST /v2.1/Contacts Creates a contact.

Parameters:

  • contact (Hash) (defaults to: nil)

    The contact to create.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



71
72
73
74
# File 'lib/insightly2/dsl/contacts.rb', line 71

def create_contact(contact: nil)
  raise ArgumentError, "Contact cannot be blank" if contact.blank?
  Resources::Contact.parse(request(:post, "Contacts", contact))
end

#create_contact_image(id: nil, filename: nil) ⇒ Faraday::Response

POST /v2.1/Contacts/c_id/Image/filename Adds a contact’s image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

  • filename (String) (defaults to: nil)

    The name of image file to be attached to the contact.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



82
83
84
85
86
# File 'lib/insightly2/dsl/contacts.rb', line 82

def create_contact_image(id: nil, filename: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Filename cannot be blank" if filename.blank?
  request(:post, "Contacts/#{id}/Image/#{filename}")
end

#delete_contact(id: nil) ⇒ Faraday::Response

DELETE /v2.1/Contacts/id Deletes a contact.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact to delete.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



115
116
117
118
# File 'lib/insightly2/dsl/contacts.rb', line 115

def delete_contact(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:delete, "Contacts/#{id}")
end

#delete_contact_image(id: nil) ⇒ Faraday::Response

DELETE /v2.1/Contacts/c_id/Image Deletes a contact’s image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact with the image to delete.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



125
126
127
128
# File 'lib/insightly2/dsl/contacts.rb', line 125

def delete_contact_image(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:delete, "Contacts/#{id}/Image")
end

#get_contact(id: nil) ⇒ Insightly2::Resources::Contact?

GET /v2.1/Contacts/id Gets a contact by id.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



10
11
12
13
# File 'lib/insightly2/dsl/contacts.rb', line 10

def get_contact(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Contact.parse(request(:get, "Contacts/#{id}"))
end

#get_contact_emails(id: nil) ⇒ Array?

GET /v2.1/Contacts/c_id/Emails Gets a contact’s emails.

Parameters:

  • id (id:) (defaults to: nil)

    of the contact.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



20
21
22
23
# File 'lib/insightly2/dsl/contacts.rb', line 20

def get_contact_emails(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Email.parse(request(:get, "Contacts/#{id}/Emails"))
end

#get_contact_image(id: nil) ⇒ Faraday::Response

GET /v2.1/Contacts/c_id/Image Gets a contact’s image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



30
31
32
33
# File 'lib/insightly2/dsl/contacts.rb', line 30

def get_contact_image(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:get, "Contacts/#{id}/Image")
end

#get_contact_notes(id: nil) ⇒ Array?

GET /v2.1/Contacts/c_id/Notes Gets a contact’s notes.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



40
41
42
43
# File 'lib/insightly2/dsl/contacts.rb', line 40

def get_contact_notes(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Note.parse(request(:get, "Contacts/#{id}/Notes"))
end

#get_contact_tasks(id: nil) ⇒ Array?

GET /v2.1/Contacts/c_id/Tasks Gets a contact’s tasks.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



50
51
52
53
# File 'lib/insightly2/dsl/contacts.rb', line 50

def get_contact_tasks(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Task.parse(request(:get, "Contacts/#{id}/Tasks"))
end

#get_contacts(ids: [], email: '', tag: '') ⇒ Array?

GET /v2.1/Contacts?ids=ids&email=email&tag=tag Get a list of contacts.

Parameters:

  • ids (Array) (defaults to: [])

    The contact ids of the contacts to return (optional).

  • email (String) (defaults to: '')

    The email address of the contact to return (optional).

  • tag (String) (defaults to: '')

    The tag that has been applied to contacts (optional).

Returns:

  • (Array, nil)

    .



61
62
63
64
# File 'lib/insightly2/dsl/contacts.rb', line 61

def get_contacts(ids: [], email: '', tag: '')
  url = Utils::UrlHelper.build_url(path: "Contacts", params: {ids: ids.join(','), email: email, tag: tag})
  Resources::Contact.parse(request(:get, url))
end

#update_contact(contact: nil) ⇒ Insightly2::Resources::Contact?

PUT /v2.1/Contacts Updates a contact.

Parameters:

  • contact (Hash) (defaults to: nil)

    The contact to update.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



93
94
95
96
# File 'lib/insightly2/dsl/contacts.rb', line 93

def update_contact(contact: nil)
  raise ArgumentError, "Contact cannot be blank" if contact.blank?
  Resources::Contact.parse(request(:put, "Contacts", contact))
end

#update_contact_image(id: nil, filename: nil) ⇒ Faraday::Response

PUT /v2.1/Contacts/c_id/Image/filename Updates a contact’s image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    The ID of the contact.

  • filename (String) (defaults to: nil)

    The name of image file to be attached to the contact.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



104
105
106
107
108
# File 'lib/insightly2/dsl/contacts.rb', line 104

def update_contact_image(id: nil, filename: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Filename cannot be blank" if filename.blank?
  request(:put, "Contacts/#{id}/Image/#{filename}")
end