nylas 6.2.3 → 6.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nylas/client.rb +43 -0
- data/lib/nylas/errors.rb +6 -4
- data/lib/nylas/handler/api_operations.rb +45 -27
- data/lib/nylas/handler/http_client.rb +265 -26
- data/lib/nylas/handler/service_account_signer.rb +112 -0
- data/lib/nylas/resources/applications.rb +14 -0
- data/lib/nylas/resources/bookings.rb +4 -2
- data/lib/nylas/resources/calendars.rb +10 -3
- data/lib/nylas/resources/domains.rb +269 -0
- data/lib/nylas/resources/events.rb +17 -1
- data/lib/nylas/resources/folders.rb +5 -0
- data/lib/nylas/resources/lists.rb +36 -0
- data/lib/nylas/resources/messages.rb +24 -1
- data/lib/nylas/resources/notetakers.rb +142 -0
- data/lib/nylas/resources/policies.rb +124 -0
- data/lib/nylas/resources/redirect_uris.rb +2 -2
- data/lib/nylas/resources/rules.rb +161 -0
- data/lib/nylas/resources/webhooks.rb +5 -4
- data/lib/nylas/resources/workspaces.rb +111 -0
- data/lib/nylas/utils/file_utils.rb +7 -3
- data/lib/nylas/version.rb +1 -1
- data/lib/nylas.rb +8 -15
- metadata +48 -23
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "base64"
|
|
4
|
+
require "json"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "securerandom"
|
|
7
|
+
|
|
8
|
+
module Nylas
|
|
9
|
+
# Builds Nylas Service Account request signing headers for organization admin APIs.
|
|
10
|
+
#
|
|
11
|
+
# @see https://developer.nylas.com/docs/v3/auth/nylas-service-account/
|
|
12
|
+
class ServiceAccountSigner
|
|
13
|
+
NONCE_ALPHABET = ("a".."z").to_a.concat(("A".."Z").to_a, ("0".."9").to_a).freeze
|
|
14
|
+
DEFAULT_NONCE_LENGTH = 20
|
|
15
|
+
SIGNED_BODY_METHODS = %w[post put patch].freeze
|
|
16
|
+
|
|
17
|
+
attr_reader :private_key_id
|
|
18
|
+
|
|
19
|
+
# @param private_key_pem [String] RSA private key in PEM format.
|
|
20
|
+
# @param private_key_id [String] Value for the X-Nylas-Kid header.
|
|
21
|
+
def initialize(private_key_pem:, private_key_id:)
|
|
22
|
+
@private_key = self.class.load_rsa_private_key(private_key_pem)
|
|
23
|
+
@private_key_id = private_key_id
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns deterministic JSON with keys sorted at every object level and no extra whitespace.
|
|
27
|
+
#
|
|
28
|
+
# @param data [Hash, Array, String, Numeric, true, false, nil] Data to serialize.
|
|
29
|
+
# @return [String] Canonical JSON string.
|
|
30
|
+
def self.canonical_json(data)
|
|
31
|
+
JSON.generate(canonicalize(data))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Loads an RSA private key from a PEM string.
|
|
35
|
+
#
|
|
36
|
+
# @param private_key_pem [String] RSA private key in PEM format.
|
|
37
|
+
# @return [OpenSSL::PKey::RSA]
|
|
38
|
+
def self.load_rsa_private_key(private_key_pem)
|
|
39
|
+
key = OpenSSL::PKey::RSA.new(private_key_pem)
|
|
40
|
+
raise ArgumentError, "Private key must be RSA private key" unless key.private?
|
|
41
|
+
raise ArgumentError, "Private key must be at least 2048 bits" if key.n.num_bits < 2048
|
|
42
|
+
|
|
43
|
+
key
|
|
44
|
+
rescue OpenSSL::PKey::PKeyError
|
|
45
|
+
raise ArgumentError, "Private key must be RSA PEM"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Generates a cryptographically secure alphanumeric nonce.
|
|
49
|
+
#
|
|
50
|
+
# @param length [Integer] Length of the nonce to generate.
|
|
51
|
+
# @return [String] Generated nonce.
|
|
52
|
+
def self.generate_nonce(length = DEFAULT_NONCE_LENGTH)
|
|
53
|
+
Array.new(length) { NONCE_ALPHABET[SecureRandom.random_number(NONCE_ALPHABET.length)] }.join
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Builds signed headers and, for JSON body methods, the exact canonical body to send.
|
|
57
|
+
#
|
|
58
|
+
# @param method [String, Symbol] HTTP method.
|
|
59
|
+
# @param path [String] Relative request path, for example "/v3/admin/domains".
|
|
60
|
+
# @param body [Hash, nil] Request body for POST/PUT/PATCH requests.
|
|
61
|
+
# @param timestamp [Integer, nil] Optional Unix timestamp in seconds, mainly for tests.
|
|
62
|
+
# @param nonce [String, nil] Optional nonce, mainly for tests.
|
|
63
|
+
# @return [Array(Hash, String)] Signed headers and optional serialized JSON body.
|
|
64
|
+
def build_headers(method:, path:, body: nil, timestamp: nil, nonce: nil)
|
|
65
|
+
timestamp ||= Time.now.to_i
|
|
66
|
+
nonce ||= self.class.generate_nonce
|
|
67
|
+
method_value = method.to_s.downcase
|
|
68
|
+
serialized_body = nil
|
|
69
|
+
|
|
70
|
+
if SIGNED_BODY_METHODS.include?(method_value) && !body.nil?
|
|
71
|
+
serialized_body = self.class.canonical_json(body)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
envelope = {
|
|
75
|
+
method: method_value,
|
|
76
|
+
nonce: nonce,
|
|
77
|
+
path: path,
|
|
78
|
+
timestamp: timestamp
|
|
79
|
+
}
|
|
80
|
+
envelope[:payload] = serialized_body if serialized_body
|
|
81
|
+
|
|
82
|
+
signature = @private_key.sign(OpenSSL::Digest.new("SHA256"), self.class.canonical_json(envelope))
|
|
83
|
+
|
|
84
|
+
[
|
|
85
|
+
{
|
|
86
|
+
"X-Nylas-Kid" => private_key_id,
|
|
87
|
+
"X-Nylas-Nonce" => nonce,
|
|
88
|
+
"X-Nylas-Timestamp" => timestamp.to_s,
|
|
89
|
+
"X-Nylas-Signature" => Base64.strict_encode64(signature)
|
|
90
|
+
},
|
|
91
|
+
serialized_body
|
|
92
|
+
]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class << self
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def canonicalize(value)
|
|
99
|
+
case value
|
|
100
|
+
when Hash
|
|
101
|
+
value.keys.sort_by(&:to_s).each_with_object({}) do |key, result|
|
|
102
|
+
result[key.to_s] = canonicalize(value[key])
|
|
103
|
+
end
|
|
104
|
+
when Array
|
|
105
|
+
value.map { |item| canonicalize(item) }
|
|
106
|
+
else
|
|
107
|
+
value
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -8,6 +8,7 @@ module Nylas
|
|
|
8
8
|
# Application
|
|
9
9
|
class Applications < Resource
|
|
10
10
|
include ApiOperations::Get
|
|
11
|
+
include ApiOperations::Patch
|
|
11
12
|
|
|
12
13
|
attr_reader :redirect_uris
|
|
13
14
|
|
|
@@ -23,5 +24,18 @@ module Nylas
|
|
|
23
24
|
def get_details
|
|
24
25
|
get(path: "#{api_uri}/v3/applications")
|
|
25
26
|
end
|
|
27
|
+
|
|
28
|
+
# Update application details.
|
|
29
|
+
#
|
|
30
|
+
# @param request_body [Hash] The values to update the application with. Include
|
|
31
|
+
# +callback_uris+ entries with +id+ when preserving or updating existing
|
|
32
|
+
# callback URIs.
|
|
33
|
+
# @return [Array(Hash, String)] The updated application details and API Request ID.
|
|
34
|
+
def update(request_body:)
|
|
35
|
+
patch(
|
|
36
|
+
path: "#{api_uri}/v3/applications",
|
|
37
|
+
request_body: request_body
|
|
38
|
+
)
|
|
39
|
+
end
|
|
26
40
|
end
|
|
27
41
|
end
|
|
@@ -64,11 +64,13 @@ module Nylas
|
|
|
64
64
|
# Delete a booking.
|
|
65
65
|
# @param booking_id [String] The id of the booking to delete.
|
|
66
66
|
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
67
|
+
# @param request_body [Hash, nil] Optional body params (e.g. cancellation_reason).
|
|
67
68
|
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
|
68
|
-
def destroy(booking_id:, query_params: nil)
|
|
69
|
+
def destroy(booking_id:, query_params: nil, request_body: nil)
|
|
69
70
|
_, request_id = delete(
|
|
70
71
|
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
|
|
71
|
-
query_params: query_params
|
|
72
|
+
query_params: query_params,
|
|
73
|
+
request_body: request_body
|
|
72
74
|
)
|
|
73
75
|
|
|
74
76
|
[true, request_id]
|
|
@@ -39,6 +39,7 @@ module Nylas
|
|
|
39
39
|
#
|
|
40
40
|
# @param identifier [String] Grant ID or email account in which to create the object.
|
|
41
41
|
# @param request_body [Hash] The values to create the calendar with.
|
|
42
|
+
# This can include a `notetaker` object with settings and calendar sync rules for the Notetaker bot.
|
|
42
43
|
# @return [Array(Hash, String)] The created calendar and API Request ID.
|
|
43
44
|
def create(identifier:, request_body:)
|
|
44
45
|
post(
|
|
@@ -52,7 +53,8 @@ module Nylas
|
|
|
52
53
|
# @param identifier [String] Grant ID or email account in which to update an object.
|
|
53
54
|
# @param calendar_id [String] The id of the calendar to update.
|
|
54
55
|
# Use "primary" to refer to the primary calendar associated with grant.
|
|
55
|
-
# @param request_body [Hash] The values to update the calendar with
|
|
56
|
+
# @param request_body [Hash] The values to update the calendar with.
|
|
57
|
+
# This can include a `notetaker` object with settings and calendar sync rules for the Notetaker bot.
|
|
56
58
|
# @return [Array(Hash, String)] The updated calendar and API Request ID.
|
|
57
59
|
def update(identifier:, calendar_id:, request_body:)
|
|
58
60
|
put(
|
|
@@ -88,8 +90,13 @@ module Nylas
|
|
|
88
90
|
|
|
89
91
|
# Get the free/busy schedule for a list of email addresses.
|
|
90
92
|
#
|
|
91
|
-
# @param identifier [
|
|
92
|
-
# @param request_body [Hash] Request body to pass to the request.
|
|
93
|
+
# @param identifier [String] The identifier of the grant to act upon.
|
|
94
|
+
# @param request_body [Hash] Request body to pass to the request. Supported keys:
|
|
95
|
+
# - `:start_time` [Integer] Unix timestamp for the start time to check free/busy for.
|
|
96
|
+
# - `:end_time` [Integer] Unix timestamp for the end time to check free/busy for.
|
|
97
|
+
# - `:emails` [Array<String>] List of email addresses to check free/busy for.
|
|
98
|
+
# - `:tentative_as_busy` [Boolean, nil] When set to `false`, treats tentative calendar events as
|
|
99
|
+
# `busy: false`. Only applicable for Microsoft and EWS calendar providers. Defaults to `true`.
|
|
93
100
|
# @return [Array(Array(Hash), String)] The free/busy response.
|
|
94
101
|
def get_free_busy(identifier:, request_body:)
|
|
95
102
|
post(
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "resource"
|
|
4
|
+
require_relative "../handler/api_operations"
|
|
5
|
+
require_relative "../handler/service_account_signer"
|
|
6
|
+
require "uri"
|
|
7
|
+
|
|
8
|
+
module Nylas
|
|
9
|
+
# Module representing the possible 'type' values in a domain verification request.
|
|
10
|
+
# @see https://developer.nylas.com/docs/reference/api/manage-domains/
|
|
11
|
+
module DomainVerificationRequestType
|
|
12
|
+
OWNERSHIP = "ownership"
|
|
13
|
+
MX = "mx"
|
|
14
|
+
SPF = "spf"
|
|
15
|
+
DKIM = "dkim"
|
|
16
|
+
FEEDBACK = "feedback"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Module representing the possible 'type' values in a domain verification result.
|
|
20
|
+
# @see https://developer.nylas.com/docs/reference/api/manage-domains/
|
|
21
|
+
module DomainVerificationType
|
|
22
|
+
OWNERSHIP = DomainVerificationRequestType::OWNERSHIP
|
|
23
|
+
MX = DomainVerificationRequestType::MX
|
|
24
|
+
SPF = DomainVerificationRequestType::SPF
|
|
25
|
+
DKIM = DomainVerificationRequestType::DKIM
|
|
26
|
+
FEEDBACK = DomainVerificationRequestType::FEEDBACK
|
|
27
|
+
DMARC = "dmarc"
|
|
28
|
+
ARC = "arc"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Module representing the possible 'status' values in a domain verification result.
|
|
32
|
+
module DomainVerificationStatus
|
|
33
|
+
PENDING = "pending"
|
|
34
|
+
DONE = "done"
|
|
35
|
+
FAILED = "failed"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Nylas Manage Domains API
|
|
39
|
+
#
|
|
40
|
+
# These endpoints require Nylas Service Account request signing. Pass headers
|
|
41
|
+
# containing `X-Nylas-Kid`, `X-Nylas-Timestamp`, `X-Nylas-Nonce`, and
|
|
42
|
+
# `X-Nylas-Signature` generated for the exact request being sent.
|
|
43
|
+
class Domains < Resource
|
|
44
|
+
include ApiOperations::Get
|
|
45
|
+
include ApiOperations::Post
|
|
46
|
+
include ApiOperations::Put
|
|
47
|
+
include ApiOperations::Delete
|
|
48
|
+
|
|
49
|
+
REQUIRED_SERVICE_ACCOUNT_HEADERS = %w[
|
|
50
|
+
X-Nylas-Kid
|
|
51
|
+
X-Nylas-Timestamp
|
|
52
|
+
X-Nylas-Nonce
|
|
53
|
+
X-Nylas-Signature
|
|
54
|
+
].freeze
|
|
55
|
+
DOMAINS_PATH = "/v3/admin/domains"
|
|
56
|
+
|
|
57
|
+
# Return all domains for the caller's organization.
|
|
58
|
+
#
|
|
59
|
+
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
60
|
+
# Supported keys: `limit`, `page_token`.
|
|
61
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
62
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
63
|
+
# @return [Array(Array(Hash), String, String, Hash)]
|
|
64
|
+
# The list of domains, API Request ID, next cursor, and response headers.
|
|
65
|
+
def list(headers: nil, query_params: nil, signer: nil)
|
|
66
|
+
request_headers, = signed_request_headers(method: :get, relative_path: DOMAINS_PATH,
|
|
67
|
+
headers: headers, signer: signer)
|
|
68
|
+
|
|
69
|
+
get_list(
|
|
70
|
+
path: full_path(DOMAINS_PATH),
|
|
71
|
+
query_params: query_params,
|
|
72
|
+
headers: request_headers
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Return a domain.
|
|
77
|
+
#
|
|
78
|
+
# @param domain_id [String] The identifier of the domain to return.
|
|
79
|
+
# Accepts either a UUID or a domain address (FQDN/email format).
|
|
80
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
81
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
82
|
+
# @return [Array(Hash, String, Hash)] The domain, API request ID, and response headers.
|
|
83
|
+
def find(domain_id:, headers: nil, signer: nil)
|
|
84
|
+
relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
|
|
85
|
+
request_headers, = signed_request_headers(method: :get, relative_path: relative_path,
|
|
86
|
+
headers: headers, signer: signer)
|
|
87
|
+
|
|
88
|
+
get(
|
|
89
|
+
path: full_path(relative_path),
|
|
90
|
+
headers: request_headers
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Create a domain.
|
|
95
|
+
#
|
|
96
|
+
# @param request_body [Hash] The values to create the domain with.
|
|
97
|
+
# Requires `name` and `domain_address`.
|
|
98
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
99
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
100
|
+
# @return [Array(Hash, String, Hash)] The created domain, API Request ID, and response headers.
|
|
101
|
+
def create(request_body:, headers: nil, signer: nil)
|
|
102
|
+
request_headers, serialized_body = signed_request_headers(
|
|
103
|
+
method: :post,
|
|
104
|
+
relative_path: DOMAINS_PATH,
|
|
105
|
+
body: request_body,
|
|
106
|
+
headers: headers,
|
|
107
|
+
signer: signer
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
request = {
|
|
111
|
+
path: full_path(DOMAINS_PATH),
|
|
112
|
+
request_body: serialized_body.nil? ? request_body : nil,
|
|
113
|
+
headers: request_headers
|
|
114
|
+
}
|
|
115
|
+
request[:serialized_json_body] = serialized_body unless serialized_body.nil?
|
|
116
|
+
post(**request)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Update a domain.
|
|
120
|
+
#
|
|
121
|
+
# @param domain_id [String] The identifier of the domain to update.
|
|
122
|
+
# Accepts either a UUID or a domain address (FQDN/email format).
|
|
123
|
+
# @param request_body [Hash] The values to update the domain with.
|
|
124
|
+
# The response echoes only the updated fields, not a full domain object.
|
|
125
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
126
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
127
|
+
# @return [Array(Hash, String)] The updated domain fields and API Request ID.
|
|
128
|
+
def update(domain_id:, request_body:, headers: nil, signer: nil)
|
|
129
|
+
relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
|
|
130
|
+
request_headers, serialized_body = signed_request_headers(
|
|
131
|
+
method: :put,
|
|
132
|
+
relative_path: relative_path,
|
|
133
|
+
body: request_body,
|
|
134
|
+
headers: headers,
|
|
135
|
+
signer: signer
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
request = {
|
|
139
|
+
path: full_path(relative_path),
|
|
140
|
+
request_body: serialized_body.nil? ? request_body : nil,
|
|
141
|
+
headers: request_headers
|
|
142
|
+
}
|
|
143
|
+
request[:serialized_json_body] = serialized_body unless serialized_body.nil?
|
|
144
|
+
put(**request)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Delete a domain.
|
|
148
|
+
#
|
|
149
|
+
# @param domain_id [String] The identifier of the domain to delete.
|
|
150
|
+
# Accepts either a UUID or a domain address (FQDN/email format).
|
|
151
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
152
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
153
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
|
154
|
+
def destroy(domain_id:, headers: nil, signer: nil)
|
|
155
|
+
relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}"
|
|
156
|
+
request_headers, = signed_request_headers(method: :delete, relative_path: relative_path,
|
|
157
|
+
headers: headers, signer: signer)
|
|
158
|
+
|
|
159
|
+
_, request_id = delete(
|
|
160
|
+
path: full_path(relative_path),
|
|
161
|
+
headers: request_headers
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
[true, request_id]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Get the DNS record info for a domain verification type.
|
|
168
|
+
#
|
|
169
|
+
# @param domain_id [String] The identifier of the domain.
|
|
170
|
+
# Accepts either a UUID or a domain address (FQDN/email format).
|
|
171
|
+
# @param request_body [Hash] The verification attempt values. Requires `type`.
|
|
172
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
173
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
174
|
+
# @return [Array(Hash, String, Hash)]
|
|
175
|
+
# The domain verification result, API Request ID, and response headers.
|
|
176
|
+
def info(domain_id:, request_body:, headers: nil, signer: nil)
|
|
177
|
+
relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}/info"
|
|
178
|
+
request_headers, serialized_body = signed_request_headers(
|
|
179
|
+
method: :post,
|
|
180
|
+
relative_path: relative_path,
|
|
181
|
+
body: request_body,
|
|
182
|
+
headers: headers,
|
|
183
|
+
signer: signer
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
request = {
|
|
187
|
+
path: full_path(relative_path),
|
|
188
|
+
request_body: serialized_body.nil? ? request_body : nil,
|
|
189
|
+
headers: request_headers
|
|
190
|
+
}
|
|
191
|
+
request[:serialized_json_body] = serialized_body unless serialized_body.nil?
|
|
192
|
+
post(**request)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Trigger a DNS verification check for a domain verification type.
|
|
196
|
+
#
|
|
197
|
+
# @param domain_id [String] The identifier of the domain.
|
|
198
|
+
# Accepts either a UUID or a domain address (FQDN/email format).
|
|
199
|
+
# @param request_body [Hash] The verification attempt values. Requires `type`.
|
|
200
|
+
# @param headers [Hash, nil] Nylas Service Account request signing headers.
|
|
201
|
+
# @param signer [ServiceAccountSigner, nil] Signer to generate Nylas Service Account headers.
|
|
202
|
+
# @return [Array(Hash, String, Hash)]
|
|
203
|
+
# The domain verification result, API Request ID, and response headers.
|
|
204
|
+
def verify(domain_id:, request_body:, headers: nil, signer: nil)
|
|
205
|
+
relative_path = "#{DOMAINS_PATH}/#{encoded_domain_id(domain_id)}/verify"
|
|
206
|
+
request_headers, serialized_body = signed_request_headers(
|
|
207
|
+
method: :post,
|
|
208
|
+
relative_path: relative_path,
|
|
209
|
+
body: request_body,
|
|
210
|
+
headers: headers,
|
|
211
|
+
signer: signer
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
request = {
|
|
215
|
+
path: full_path(relative_path),
|
|
216
|
+
request_body: serialized_body.nil? ? request_body : nil,
|
|
217
|
+
headers: request_headers
|
|
218
|
+
}
|
|
219
|
+
request[:serialized_json_body] = serialized_body unless serialized_body.nil?
|
|
220
|
+
post(**request)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
private
|
|
224
|
+
|
|
225
|
+
# Manage Domains uses Nylas Service Account signing headers instead of API-key bearer auth.
|
|
226
|
+
def api_key
|
|
227
|
+
nil
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def full_path(relative_path)
|
|
231
|
+
"#{api_uri}#{relative_path}"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def encoded_domain_id(domain_id)
|
|
235
|
+
URI.encode_www_form_component(domain_id)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def signed_request_headers(method:, relative_path:, headers:, signer:, body: nil)
|
|
239
|
+
request_headers = headers.nil? ? {} : headers.dup
|
|
240
|
+
serialized_body = body.nil? ? nil : Nylas::ServiceAccountSigner.canonical_json(body)
|
|
241
|
+
if signer
|
|
242
|
+
signer_headers, serialized_body = signer.build_headers(
|
|
243
|
+
method: method,
|
|
244
|
+
path: relative_path,
|
|
245
|
+
body: body
|
|
246
|
+
)
|
|
247
|
+
request_headers.merge!(signer_headers)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
validate_service_account_headers!(request_headers)
|
|
251
|
+
[request_headers, serialized_body]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def validate_service_account_headers!(headers)
|
|
255
|
+
header_values = headers || {}
|
|
256
|
+
normalized_headers = header_values.transform_keys do |key|
|
|
257
|
+
key.to_s.downcase
|
|
258
|
+
end
|
|
259
|
+
missing_headers = REQUIRED_SERVICE_ACCOUNT_HEADERS.select do |header|
|
|
260
|
+
normalized_headers[header.downcase].to_s.empty?
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
return if missing_headers.empty?
|
|
264
|
+
|
|
265
|
+
raise ArgumentError,
|
|
266
|
+
"Missing required service account authentication headers: #{missing_headers.join(', ')}"
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
@@ -40,6 +40,7 @@ module Nylas
|
|
|
40
40
|
#
|
|
41
41
|
# @param identifier [String] Grant ID or email account in which to create the object.
|
|
42
42
|
# @param request_body [Hash] The values to create the event with.
|
|
43
|
+
# This can include a `notetaker` object with settings for the Notetaker bot.
|
|
43
44
|
# @param query_params [Hash] The query parameters to include in the request.
|
|
44
45
|
# @return [Array(Hash, String)] The created event and API Request ID.
|
|
45
46
|
def create(identifier:, request_body:, query_params:)
|
|
@@ -54,7 +55,8 @@ module Nylas
|
|
|
54
55
|
#
|
|
55
56
|
# @param identifier [String] Grant ID or email account in which to update an object.
|
|
56
57
|
# @param event_id [String] The id of the event to update.
|
|
57
|
-
# @param request_body [Hash] The values to update the event with
|
|
58
|
+
# @param request_body [Hash] The values to update the event with.
|
|
59
|
+
# This can include a `notetaker` object with settings for the Notetaker bot.
|
|
58
60
|
# @param query_params [Hash] The query parameters to include in the request
|
|
59
61
|
# @return [Array(Hash, String)] The updated event and API Request ID.
|
|
60
62
|
def update(identifier:, event_id:, request_body:, query_params:)
|
|
@@ -94,5 +96,19 @@ module Nylas
|
|
|
94
96
|
request_body: request_body
|
|
95
97
|
)
|
|
96
98
|
end
|
|
99
|
+
|
|
100
|
+
# Returns a list of recurring events, recurring event exceptions, and single events
|
|
101
|
+
# from the specified calendar within a given time frame. This is useful when you
|
|
102
|
+
# want to import, store, and synchronize events from the time frame to your application
|
|
103
|
+
#
|
|
104
|
+
# @param identifier [String] Grant ID or email account to import events from.
|
|
105
|
+
# @param query_params [Hash] The query parameters to include in the request
|
|
106
|
+
# @return [(Array(Hash), String, String)] The list of events, API Request ID, and next cursor.
|
|
107
|
+
def list_import_events(identifier:, query_params:)
|
|
108
|
+
get_list(
|
|
109
|
+
path: "#{api_uri}/v3/grants/#{identifier}/events/import",
|
|
110
|
+
query_params: query_params
|
|
111
|
+
)
|
|
112
|
+
end
|
|
97
113
|
end
|
|
98
114
|
end
|
|
@@ -15,6 +15,11 @@ module Nylas
|
|
|
15
15
|
#
|
|
16
16
|
# @param identifier [String] Grant ID or email account to query.
|
|
17
17
|
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
18
|
+
# Supported parameters include:
|
|
19
|
+
# - single_level: (Boolean) For Microsoft accounts only. If true, retrieves folders from
|
|
20
|
+
# a single-level hierarchy only. If false (default), retrieves folders across a
|
|
21
|
+
# multi-level hierarchy.
|
|
22
|
+
# - include_hidden_folders [Boolean] (Microsoft only) When true, includes hidden folders.
|
|
18
23
|
# @return [Array(Array(Hash), String, String)] The list of folders, API Request ID, and next cursor.
|
|
19
24
|
def list(identifier:, query_params: nil)
|
|
20
25
|
get_list(
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "resource"
|
|
4
|
+
require_relative "../handler/api_operations"
|
|
5
|
+
|
|
6
|
+
module Nylas
|
|
7
|
+
# Module representing the possible 'type' values for a List.
|
|
8
|
+
module ListType
|
|
9
|
+
DOMAIN = "domain"
|
|
10
|
+
TLD = "tld"
|
|
11
|
+
ADDRESS = "address"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Nylas Lists API
|
|
15
|
+
#
|
|
16
|
+
# Lists are typed collections of domains, TLDs, or email addresses that can
|
|
17
|
+
# be referenced by Rules using the +in_list+ condition operator.
|
|
18
|
+
class Lists < Resource
|
|
19
|
+
include ApiOperations::Post
|
|
20
|
+
|
|
21
|
+
# Create a list for the application.
|
|
22
|
+
#
|
|
23
|
+
# @param request_body [Hash] The public values to create the list with.
|
|
24
|
+
# Supported keys: +name+ (required, 1-256 chars), +type+ (required; one of
|
|
25
|
+
# +domain+, +tld+, or +address+), and +description+ (optional). The server
|
|
26
|
+
# assigns identifiers, item counts, timestamps, and application ownership.
|
|
27
|
+
# @return [Array(Hash, String, Hash)] The created list, API Request ID, and
|
|
28
|
+
# response headers.
|
|
29
|
+
def create(request_body:)
|
|
30
|
+
post(
|
|
31
|
+
path: "#{api_uri}/v3/lists",
|
|
32
|
+
request_body: request_body
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -6,6 +6,19 @@ require_relative "../handler/api_operations"
|
|
|
6
6
|
require_relative "../utils/file_utils"
|
|
7
7
|
|
|
8
8
|
module Nylas
|
|
9
|
+
# Module representing the possible 'fields' values for Messages API requests.
|
|
10
|
+
# @see https://developer.nylas.com/docs/api/messages#get-/v3/grants/-identifier-/messages
|
|
11
|
+
module MessageFields
|
|
12
|
+
# Return the standard message payload (default)
|
|
13
|
+
STANDARD = "standard"
|
|
14
|
+
# Return messages and their custom headers
|
|
15
|
+
INCLUDE_HEADERS = "include_headers"
|
|
16
|
+
# Return messages and their tracking settings
|
|
17
|
+
INCLUDE_TRACKING_OPTIONS = "include_tracking_options"
|
|
18
|
+
# Return the grant_id, object, id, and raw_mime fields only
|
|
19
|
+
RAW_MIME = "raw_mime"
|
|
20
|
+
end
|
|
21
|
+
|
|
9
22
|
# Nylas Messages API
|
|
10
23
|
class Messages < Resource
|
|
11
24
|
include ApiOperations::Get
|
|
@@ -26,6 +39,11 @@ module Nylas
|
|
|
26
39
|
#
|
|
27
40
|
# @param identifier [String] Grant ID or email account to query.
|
|
28
41
|
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
42
|
+
# You can use the fields parameter to specify which data to return:
|
|
43
|
+
# - MessageFields::STANDARD (default): Returns the standard message payload
|
|
44
|
+
# - MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers
|
|
45
|
+
# - MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings
|
|
46
|
+
# - MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only
|
|
29
47
|
# @return [Array(Array(Hash), String, String)] The list of messages, API Request ID, and next cursor.
|
|
30
48
|
def list(identifier:, query_params: nil)
|
|
31
49
|
get_list(
|
|
@@ -39,6 +57,11 @@ module Nylas
|
|
|
39
57
|
# @param identifier [String] Grant ID or email account to query.
|
|
40
58
|
# @param message_id [String] The id of the message to return.
|
|
41
59
|
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
60
|
+
# You can use the fields parameter to specify which data to return:
|
|
61
|
+
# - MessageFields::STANDARD (default): Returns the standard message payload
|
|
62
|
+
# - MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers
|
|
63
|
+
# - MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings
|
|
64
|
+
# - MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only
|
|
42
65
|
# @return [Array(Hash, String)] The message and API request ID.
|
|
43
66
|
def find(identifier:, message_id:, query_params: nil)
|
|
44
67
|
get(
|
|
@@ -103,7 +126,7 @@ module Nylas
|
|
|
103
126
|
request_body: payload
|
|
104
127
|
)
|
|
105
128
|
|
|
106
|
-
opened_files.each(
|
|
129
|
+
opened_files.each { |file| file.close if file.respond_to?(:close) }
|
|
107
130
|
|
|
108
131
|
response
|
|
109
132
|
end
|