Class: Nylas::Contacts

Inherits:
Resource show all
Includes:
ApiOperations::Delete, ApiOperations::Get, ApiOperations::Post, ApiOperations::Put
Defined in:
lib/nylas/resources/contacts.rb

Overview

Nylas Contact API

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Instance Method Details

#create(identifier:, request_body:) ⇒ Array(Hash, String)

Create a contact.

Parameters:

  • identifier (String)

    Grant ID or email account in which to create the object.

  • request_body (Hash)

    The values to create the contact with. The optional metadata hash is stored by Nylas, not by the provider.

Returns:

  • (Array(Hash, String))

    The created contact and API Request ID.



48
49
50
51
52
53
# File 'lib/nylas/resources/contacts.rb', line 48

def create(identifier:, request_body:)
  post(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts",
    request_body: request_body
  )
end

#destroy(identifier:, contact_id:) ⇒ Array(TrueClass, String)

Delete a contact.

Parameters:

  • identifier (String)

    Grant ID or email account from which to delete an object.

  • contact_id (String)

    The id of the contact to delete.

Returns:

  • (Array(TrueClass, String))

    True and the API Request ID for the delete operation.



75
76
77
78
79
80
81
# File 'lib/nylas/resources/contacts.rb', line 75

def destroy(identifier:, contact_id:)
  _, request_id = delete(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}"
  )

  [true, request_id]
end

#find(identifier:, contact_id:, query_params: nil) ⇒ Array(Hash, String)

Return a contact.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • contact_id (String)

    The id of the contact to return.

  • query_params (Hash, nil) (defaults to: nil)

    Query params to pass to the request.

Returns:

  • (Array(Hash, String))

    The contact and API request ID.



35
36
37
38
39
40
# File 'lib/nylas/resources/contacts.rb', line 35

def find(identifier:, contact_id:, query_params: nil)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}",
    query_params: query_params
  )
end

#list(identifier:, query_params: nil) ⇒ Array(Array(Hash), String, String)

Return all contacts.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • query_params (Hash, nil) (defaults to: nil)

    Query params to pass to the request. Use metadata_pair: { key1: "value" } to filter by one indexed metadata key (key1 through key5). Metadata filters cannot be combined with provider-side contact filters.

Returns:

  • (Array(Array(Hash), String, String))

    The list of contacts, API Request ID, and next cursor.



22
23
24
25
26
27
# File 'lib/nylas/resources/contacts.rb', line 22

def list(identifier:, query_params: nil)
  get_list(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts",
    query_params: query_params
  )
end

#list_groups(identifier:, query_params: nil) ⇒ Array(Array(Hash), String, String)

Return all contact groups.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • query_params (Hash, nil) (defaults to: nil)

    Query params to pass to the request.

Returns:

  • (Array(Array(Hash), String, String))

    The list of contact groups and API Request ID.



88
89
90
91
92
93
# File 'lib/nylas/resources/contacts.rb', line 88

def list_groups(identifier:, query_params: nil)
  get_list(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts/groups",
    query_params: query_params
  )
end

#update(identifier:, contact_id:, request_body:) ⇒ Array(Hash, String)

Update a contact.

Parameters:

  • identifier (String)

    Grant ID or email account in which to update an object.

  • contact_id (String)

    The id of the contact to update.

  • request_body (Hash)

    The values to update the contact with. Omitting metadata or setting it to nil preserves existing metadata, a hash replaces it, and an empty hash clears it.

Returns:

  • (Array(Hash, String))

    The updated contact and API Request ID.



63
64
65
66
67
68
# File 'lib/nylas/resources/contacts.rb', line 63

def update(identifier:, contact_id:, request_body:)
  put(
    path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}",
    request_body: request_body
  )
end