Class: Mailtrap::ContactsAPI

Inherits:
Object
  • Object
show all
Includes:
BaseAPI
Defined in:
lib/mailtrap/contacts_api.rb

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included, #initialize

Instance Method Details

#add_to_lists(contact_id, contact_list_ids = []) ⇒ Contact

Adds a contact to specified lists

Parameters:

  • contact_id (String)

    The contact ID or email address

  • contact_list_ids (Array<Integer>) (defaults to: [])

    Array of list IDs to add the contact to

Returns:

  • (Contact)

    Updated contact object

Raises:



59
60
61
# File 'lib/mailtrap/contacts_api.rb', line 59

def add_to_lists(contact_id, contact_list_ids = [])
  update_lists(contact_id, list_ids_included: contact_list_ids)
end

#create(options) ⇒ Contact

Creates a new contact

Parameters:

  • options (Hash)

    The parameters to create

Options Hash (options):

  • :email (String)

    The contact’s email address

  • :fields (Hash)

    The contact’s fields

  • :list_ids (Array<Integer>)

    The contact’s list IDs

Returns:

  • (Contact)

    Created contact object

Raises:



29
30
31
# File 'lib/mailtrap/contacts_api.rb', line 29

def create(options)
  base_create(options)
end

#delete(contact_id) ⇒ Object

Deletes a contact

Parameters:

  • contact_id (String)

    The contact ID

Returns:

  • nil

Raises:



37
38
39
# File 'lib/mailtrap/contacts_api.rb', line 37

def delete(contact_id)
  base_delete(contact_id)
end

#get(contact_id) ⇒ Contact

Retrieves a specific contact

Parameters:

  • contact_id (String)

    The contact identifier, which can be either a UUID or an email address

Returns:

Raises:



17
18
19
# File 'lib/mailtrap/contacts_api.rb', line 17

def get(contact_id)
  base_get(contact_id)
end

#remove_from_lists(contact_id, contact_list_ids = []) ⇒ Contact

Removes a contact from specified lists

Parameters:

  • contact_id (String)

    The contact ID or email address

  • contact_list_ids (Array<Integer>) (defaults to: [])

    Array of list IDs to remove the contact from

Returns:

  • (Contact)

    Updated contact object

Raises:



68
69
70
# File 'lib/mailtrap/contacts_api.rb', line 68

def remove_from_lists(contact_id, contact_list_ids = [])
  update_lists(contact_id, list_ids_excluded: contact_list_ids)
end

#upsert(contact_id, options) ⇒ Contact

Updates an existing contact or creates a new one if it doesn’t exist

Parameters:

  • contact_id (String)

    The contact ID or email address

  • options (Hash)

    The parameters to update

Options Hash (options):

  • :email (String)

    The contact’s email address

  • :fields (Hash)

    The contact’s fields

  • :unsubscribed (Boolean)

    Whether to unsubscribe the contact

Returns:

  • (Contact)

    Updated contact object

Raises:



50
51
52
# File 'lib/mailtrap/contacts_api.rb', line 50

def upsert(contact_id, options)
  base_update(contact_id, options, %i[email fields unsubscribed])
end