Class: Nylas::Domains

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

Overview

Nylas Manage Domains API

These endpoints require Nylas Service Account request signing. Pass headers containing X-Nylas-Kid, X-Nylas-Timestamp, X-Nylas-Nonce, and X-Nylas-Signature generated for the exact request being sent.

Constant Summary collapse

REQUIRED_SERVICE_ACCOUNT_HEADERS =
%w[
  X-Nylas-Kid
  X-Nylas-Timestamp
  X-Nylas-Nonce
  X-Nylas-Signature
].freeze
DOMAINS_PATH =
"/v3/admin/domains"

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Instance Method Details

#create(request_body:, headers: nil, signer: nil) ⇒ Array(Hash, String, Hash)

Create a domain.

Parameters:

  • request_body (Hash)

    The values to create the domain with. Requires name and domain_address.

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(Hash, String, Hash))

    The created domain, API Request ID, and response headers.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/nylas/resources/domains.rb', line 101

def create(request_body:, headers: nil, signer: nil)
  request_headers, serialized_body = signed_request_headers(
    method: :post,
    relative_path: DOMAINS_PATH,
    body: request_body,
    headers: headers,
    signer: signer
  )

  request = {
    path: full_path(DOMAINS_PATH),
    request_body: serialized_body.nil? ? request_body : nil,
    headers: request_headers
  }
  request[:serialized_json_body] = serialized_body unless serialized_body.nil?
  post(**request)
end

#destroy(domain_id:, headers: nil, signer: nil) ⇒ Array(TrueClass, String)

Delete a domain.

Parameters:

  • domain_id (String)

    The identifier of the domain to delete. Accepts either a UUID or a domain address (FQDN/email format).

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(TrueClass, String))

    True and the API Request ID for the delete operation.



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/nylas/resources/domains.rb', line 154

def destroy(domain_id:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
  request_headers, = signed_request_headers(method: :delete, relative_path: relative_path,
                                            headers: headers, signer: signer)

  _, request_id = delete(
    path: full_path(relative_path),
    headers: request_headers
  )

  [true, request_id]
end

#find(domain_id:, headers: nil, signer: nil) ⇒ Array(Hash, String, Hash)

Return a domain.

Parameters:

  • domain_id (String)

    The identifier of the domain to return. Accepts either a UUID or a domain address (FQDN/email format).

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(Hash, String, Hash))

    The domain, API request ID, and response headers.



83
84
85
86
87
88
89
90
91
92
# File 'lib/nylas/resources/domains.rb', line 83

def find(domain_id:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
  request_headers, = signed_request_headers(method: :get, relative_path: relative_path,
                                            headers: headers, signer: signer)

  get(
    path: full_path(relative_path),
    headers: request_headers
  )
end

#info(domain_id:, request_body:, headers: nil, signer: nil) ⇒ Array(Hash, String, Hash)

Get the DNS record info for a domain verification type.

Parameters:

  • domain_id (String)

    The identifier of the domain. Accepts either a UUID or a domain address (FQDN/email format).

  • request_body (Hash)

    The verification attempt values. Requires type.

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(Hash, String, Hash))

    The domain verification result, API Request ID, and response headers.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/nylas/resources/domains.rb', line 176

def info(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}/info"
  request_headers, serialized_body = signed_request_headers(
    method: :post,
    relative_path: relative_path,
    body: request_body,
    headers: headers,
    signer: signer
  )

  request = {
    path: full_path(relative_path),
    request_body: serialized_body.nil? ? request_body : nil,
    headers: request_headers
  }
  request[:serialized_json_body] = serialized_body unless serialized_body.nil?
  post(**request)
end

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

Return all domains for the caller's organization.

Parameters:

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

    Query params to pass to the request. Supported keys: limit, page_token.

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

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

    The list of domains, API Request ID, next cursor, and response headers.



65
66
67
68
69
70
71
72
73
74
# File 'lib/nylas/resources/domains.rb', line 65

def list(headers: nil, query_params: nil, signer: nil)
  request_headers, = signed_request_headers(method: :get, relative_path: DOMAINS_PATH,
                                            headers: headers, signer: signer)

  get_list(
    path: full_path(DOMAINS_PATH),
    query_params: query_params,
    headers: request_headers
  )
end

#update(domain_id:, request_body:, headers: nil, signer: nil) ⇒ Array(Hash, String)

Update a domain.

Parameters:

  • domain_id (String)

    The identifier of the domain to update. Accepts either a UUID or a domain address (FQDN/email format).

  • request_body (Hash)

    The values to update the domain with. The response echoes only the updated fields, not a full domain object.

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(Hash, String))

    The updated domain fields and API Request ID.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/nylas/resources/domains.rb', line 128

def update(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
  request_headers, serialized_body = signed_request_headers(
    method: :put,
    relative_path: relative_path,
    body: request_body,
    headers: headers,
    signer: signer
  )

  request = {
    path: full_path(relative_path),
    request_body: serialized_body.nil? ? request_body : nil,
    headers: request_headers
  }
  request[:serialized_json_body] = serialized_body unless serialized_body.nil?
  put(**request)
end

#verify(domain_id:, request_body:, headers: nil, signer: nil) ⇒ Array(Hash, String, Hash)

Trigger a DNS verification check for a domain verification type.

Parameters:

  • domain_id (String)

    The identifier of the domain. Accepts either a UUID or a domain address (FQDN/email format).

  • request_body (Hash)

    The verification attempt values. Requires type.

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

    Nylas Service Account request signing headers.

  • signer (ServiceAccountSigner, nil) (defaults to: nil)

    Signer to generate Nylas Service Account headers.

Returns:

  • (Array(Hash, String, Hash))

    The domain verification result, API Request ID, and response headers.



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/nylas/resources/domains.rb', line 204

def verify(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}/verify"
  request_headers, serialized_body = signed_request_headers(
    method: :post,
    relative_path: relative_path,
    body: request_body,
    headers: headers,
    signer: signer
  )

  request = {
    path: full_path(relative_path),
    request_body: serialized_body.nil? ? request_body : nil,
    headers: request_headers
  }
  request[:serialized_json_body] = serialized_body unless serialized_body.nil?
  post(**request)
end