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.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/nylas/resources/domains.rb', line 90

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.



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/nylas/resources/domains.rb', line 143

def destroy(domain_id:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{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.



72
73
74
75
76
77
78
79
80
81
# File 'lib/nylas/resources/domains.rb', line 72

def find(domain_id:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{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.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/nylas/resources/domains.rb', line 165

def info(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{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: domain (filter by exact domain address), region, 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.



54
55
56
57
58
59
60
61
62
63
# File 'lib/nylas/resources/domains.rb', line 54

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.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/nylas/resources/domains.rb', line 117

def update(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{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.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/nylas/resources/domains.rb', line 193

def verify(domain_id:, request_body:, headers: nil, signer: nil)
  relative_path = "#{DOMAINS_PATH}/#{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