nylas 6.7.0 → 6.8.0

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.
@@ -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
@@ -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
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/api_operations"
5
+
6
+ module Nylas
7
+ # Nylas Policies API (beta)
8
+ #
9
+ # Policies define message limits, spam-detection settings, options, and linked
10
+ # rules for Nylas Agent Accounts. `application_id` and `organization_id` are
11
+ # derived from the API key / gateway headers and are read-only.
12
+ #
13
+ # Policy objects (the Hash returned/accepted by these methods) carry these keys:
14
+ # - +id+ [String] Policy UUID. Read-only; server-assigned on create.
15
+ # - +name+ [String] 1-256 chars. Required on create.
16
+ # - +application_id+ [String] Read-only; derived from the API key.
17
+ # - +organization_id+ [String] Read-only; derived from the API key.
18
+ # - +rules+ [Array<String>] Linked rule IDs.
19
+ # - +created_at+ [Integer] Unix timestamp (seconds). Read-only.
20
+ # - +updated_at+ [Integer] Unix timestamp (seconds). Read-only.
21
+ # - +limits+ [Hash] Per-policy limits. Returned as *effective* values resolved
22
+ # against the org's billing plan, which may differ from what was sent. Keys:
23
+ # - +limit_attachment_size_limit+ [Integer] Bytes; >= 0, <= plan max.
24
+ # - +limit_attachment_count_limit+ [Integer] >= 0, <= plan max.
25
+ # - +limit_attachment_allowed_types+ [Array<String>] MIME types from the plan allow-list.
26
+ # - +limit_size_total_mime+ [Integer] Bytes; >= 0, <= plan max.
27
+ # - +limit_storage_total+ [Integer] Bytes. Unlimited-capable: -1 = unlimited.
28
+ # - +limit_count_daily_message_received+ [Integer] Per-grant daily received-message
29
+ # cap. Unlimited-capable: -1 = unlimited.
30
+ # - +limit_count_daily_email_sent+ [Integer] Per-grant daily sent-email cap.
31
+ # Unlimited-capable: -1 = unlimited.
32
+ # - +limit_inbox_retention_period+ [Integer] Days. Unlimited-capable: -1. Must be
33
+ # greater than spam retention when both set.
34
+ # - +limit_spam_retention_period+ [Integer] Days. Unlimited-capable: -1. Must be
35
+ # shorter than inbox retention when both set.
36
+ # - +options+ [Hash] Policy options. Keys:
37
+ # - +additional_folders+ [Array<String>] Only allowed when the plan permits.
38
+ # - +use_cidr_aliasing+ [Boolean] Only allowed when the plan permits.
39
+ # - +spam_detection+ [Hash] Spam-detection settings. Keys:
40
+ # - +use_list_dnsbl+ [Boolean] Always present in responses (false when unset).
41
+ # - +use_header_anomaly_detection+ [Boolean] Always present in responses (false when unset).
42
+ # - +spam_sensitivity+ [Float] 0.1-5.0 inclusive. Default 1.0.
43
+ #
44
+ # The unlimited sentinel for unlimited-capable fields is -1 only; values < -1 are
45
+ # rejected, and -1 is honored only when the plan permits unlimited for that field.
46
+ class Policies < Resource
47
+ include ApiOperations::Get
48
+ include ApiOperations::Post
49
+ include ApiOperations::Put
50
+ include ApiOperations::Delete
51
+
52
+ # Return all policies.
53
+ #
54
+ # The list envelope is flat: the data array is the policies themselves and
55
+ # +next_cursor+ is a top-level sibling. +next_cursor+ is present on every
56
+ # non-empty page (including the last) and is not a has-more flag; page until
57
+ # an empty data array is returned.
58
+ #
59
+ # @param query_params [Hash, nil] Query params to pass to the request
60
+ # (e.g. +limit+ — default 10, no server max; +page_token+ — opaque cursor).
61
+ # @return [Array(Array(Hash), String, String, Hash)] The list of policies,
62
+ # API Request ID, next cursor, and response headers.
63
+ def list(query_params: nil)
64
+ get_list(
65
+ path: "#{api_uri}/v3/policies",
66
+ query_params: query_params
67
+ )
68
+ end
69
+
70
+ # Return a policy.
71
+ #
72
+ # @param policy_id [String] The id of the policy to return.
73
+ # @return [Array(Hash, String, Hash)] The policy, API request ID, and response headers.
74
+ def find(policy_id:)
75
+ get(
76
+ path: "#{api_uri}/v3/policies/#{policy_id}"
77
+ )
78
+ end
79
+
80
+ # Create a policy.
81
+ #
82
+ # @param request_body [Hash] The values to create the policy with. Honored keys:
83
+ # +name+ (required), +options+, +limits+, +rules+, +spam_detection+. Any
84
+ # +id+/+created_at+/+updated_at+/+application_id+/+organization_id+ are ignored.
85
+ # Omitted +limits+/+options+/+spam_detection+ sub-fields fall back to plan defaults.
86
+ # @return [Array(Hash, String, Hash)] The created policy, API Request ID, and response headers.
87
+ def create(request_body:)
88
+ post(
89
+ path: "#{api_uri}/v3/policies",
90
+ request_body: request_body
91
+ )
92
+ end
93
+
94
+ # Update a policy.
95
+ #
96
+ # The route verb is PUT, but the update is a partial nested merge: provided
97
+ # sub-objects (+limits+/+options+/+spam_detection+) are merged field-by-field
98
+ # onto the stored policy. Send only the fields you intend to change.
99
+ #
100
+ # @param policy_id [String] The id of the policy to update.
101
+ # @param request_body [Hash] The values to update the policy with. Honored keys:
102
+ # +name+, +options+, +limits+, +rules+, +spam_detection+. Any
103
+ # +id+/+created_at+/+updated_at+/+application_id+/+organization_id+ are ignored.
104
+ # @return [Array(Hash, String)] The updated policy and API Request ID.
105
+ def update(policy_id:, request_body:)
106
+ put(
107
+ path: "#{api_uri}/v3/policies/#{policy_id}",
108
+ request_body: request_body
109
+ )
110
+ end
111
+
112
+ # Delete a policy.
113
+ #
114
+ # @param policy_id [String] The id of the policy to delete.
115
+ # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
116
+ def destroy(policy_id:)
117
+ _, request_id = delete(
118
+ path: "#{api_uri}/v3/policies/#{policy_id}"
119
+ )
120
+
121
+ [true, request_id]
122
+ end
123
+ end
124
+ end
@@ -8,7 +8,7 @@ module Nylas
8
8
  class RedirectUris < Resource
9
9
  include ApiOperations::Get
10
10
  include ApiOperations::Post
11
- include ApiOperations::Put
11
+ include ApiOperations::Patch
12
12
  include ApiOperations::Delete
13
13
 
14
14
  # Return all redirect uris.
@@ -47,7 +47,7 @@ module Nylas
47
47
  # @param request_body [Hash] The values to update the redirect uri with
48
48
  # @return [Array(Hash, String)] The updated redirect uri and API Request ID.
49
49
  def update(redirect_uri_id:, request_body:)
50
- put(
50
+ patch(
51
51
  path: "#{api_uri}/v3/applications/redirect-uris/#{redirect_uri_id}",
52
52
  request_body: request_body
53
53
  )
@@ -0,0 +1,161 @@
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 'trigger' values for a Rule.
8
+ module RuleTrigger
9
+ INBOUND = "inbound"
10
+ OUTBOUND = "outbound"
11
+ end
12
+
13
+ # Module representing the possible 'match.operator' values for a Rule.
14
+ module RuleMatchOperator
15
+ ANY = "any"
16
+ ALL = "all"
17
+ end
18
+
19
+ # Module representing the possible condition 'field' values for a Rule.
20
+ module RuleConditionField
21
+ FROM_ADDRESS = "from.address"
22
+ FROM_DOMAIN = "from.domain"
23
+ FROM_TLD = "from.tld"
24
+ RECIPIENT_ADDRESS = "recipient.address"
25
+ RECIPIENT_DOMAIN = "recipient.domain"
26
+ RECIPIENT_TLD = "recipient.tld"
27
+ OUTBOUND_TYPE = "outbound.type"
28
+ end
29
+
30
+ # Module representing the possible condition 'operator' values for a Rule.
31
+ module RuleConditionOperator
32
+ IS = "is"
33
+ IS_NOT = "is_not"
34
+ CONTAINS = "contains"
35
+ IN_LIST = "in_list"
36
+ end
37
+
38
+ # Module representing the possible 'outbound.type' condition values for a Rule.
39
+ module RuleOutboundType
40
+ COMPOSE = "compose"
41
+ REPLY = "reply"
42
+ end
43
+
44
+ # Module representing the possible action 'type' values for a Rule.
45
+ module RuleActionType
46
+ BLOCK = "block"
47
+ MARK_AS_SPAM = "mark_as_spam"
48
+ ASSIGN_TO_FOLDER = "assign_to_folder"
49
+ MARK_AS_READ = "mark_as_read"
50
+ MARK_AS_STARRED = "mark_as_starred"
51
+ ARCHIVE = "archive"
52
+ TRASH = "trash"
53
+ end
54
+
55
+ # Module representing the possible 'evaluation_stage' values in a rule evaluation.
56
+ module RuleEvaluationStage
57
+ SMTP_RCPT = "smtp_rcpt"
58
+ INBOX_PROCESSING = "inbox_processing"
59
+ OUTBOUND_SEND = "outbound_send"
60
+ end
61
+
62
+ # Nylas Rules API
63
+ class Rules < Resource
64
+ include ApiOperations::Get
65
+ include ApiOperations::Post
66
+ include ApiOperations::Put
67
+ include ApiOperations::Delete
68
+
69
+ # Return all rules.
70
+ #
71
+ # The list endpoint returns a nested envelope
72
+ # ({ request_id, data: { items: [...], next_cursor } }), so the items and
73
+ # cursor are unwrapped here defensively rather than via the standard
74
+ # get_list helper, which would mis-read the nested shape.
75
+ #
76
+ # @param query_params [Hash, nil] Query params to pass to the request.
77
+ # @return [Array(Array(Hash), String, String, Hash)]
78
+ # The list of rules, API Request ID, next cursor, and response headers.
79
+ def list(query_params: nil)
80
+ response = get_raw(
81
+ path: "#{api_uri}/v3/rules",
82
+ query_params: query_params
83
+ )
84
+
85
+ data = response[:data]
86
+ # Unwrap only when the envelope actually carries an :items key. Go's
87
+ # ListWithCursorResult serializes a nil slice as "items": null, so coerce
88
+ # that to [] rather than falling back to the envelope hash itself.
89
+ items = if data.is_a?(Hash) && data.key?(:items)
90
+ data[:items] || []
91
+ else
92
+ data
93
+ end
94
+ next_cursor = data.is_a?(Hash) ? data[:next_cursor] : response[:next_cursor]
95
+
96
+ [items, response[:request_id], next_cursor, response[:headers]]
97
+ end
98
+
99
+ # Return a rule.
100
+ #
101
+ # @param rule_id [String] The id of the rule to return.
102
+ # @return [Array(Hash, String, Hash)] The rule, API request ID, and response headers.
103
+ def find(rule_id:)
104
+ get(
105
+ path: "#{api_uri}/v3/rules/#{rule_id}"
106
+ )
107
+ end
108
+
109
+ # Create a rule.
110
+ #
111
+ # @param request_body [Hash] The values to create the rule with.
112
+ # @return [Array(Hash, String)] The created rule and API Request ID.
113
+ def create(request_body:)
114
+ post(
115
+ path: "#{api_uri}/v3/rules",
116
+ request_body: request_body
117
+ )
118
+ end
119
+
120
+ # Update a rule. Only the provided fields are changed (partial update).
121
+ #
122
+ # @param rule_id [String] The id of the rule to update.
123
+ # @param request_body [Hash] The values to update the rule with.
124
+ # @return [Array(Hash, String)] The updated rule and API Request ID.
125
+ def update(rule_id:, request_body:)
126
+ put(
127
+ path: "#{api_uri}/v3/rules/#{rule_id}",
128
+ request_body: request_body
129
+ )
130
+ end
131
+
132
+ # Delete a rule.
133
+ #
134
+ # @param rule_id [String] The id of the rule to delete.
135
+ # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
136
+ def destroy(rule_id:)
137
+ _, request_id = delete(
138
+ path: "#{api_uri}/v3/rules/#{rule_id}"
139
+ )
140
+
141
+ [true, request_id]
142
+ end
143
+
144
+ # Return all rule evaluations for a grant.
145
+ #
146
+ # This endpoint returns a flat array with no cursor, so the standard
147
+ # get_list helper is used (next_cursor is always nil).
148
+ #
149
+ # @param grant_id [String] The id of the grant to query rule evaluations for.
150
+ # @param query_params [Hash, nil] Query params to pass to the request.
151
+ # @return [Array(Array(Hash), String, String, Hash)]
152
+ # The list of rule evaluations, API Request ID, next cursor (always nil
153
+ # for this endpoint), and response headers.
154
+ def list_evaluations(grant_id:, query_params: nil)
155
+ get_list(
156
+ path: "#{api_uri}/v3/grants/#{grant_id}/rule-evaluations",
157
+ query_params: query_params
158
+ )
159
+ end
160
+ end
161
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
4
3
  require_relative "resource"
5
4
  require_relative "../handler/api_operations"
6
5
 
@@ -115,14 +114,14 @@ module Nylas
115
114
  # @return [String] The challenge parameter
116
115
  def self.extract_challenge_parameter(url)
117
116
  url_object = URI.parse(url)
118
- query = CGI.parse(url_object.query || "")
117
+ params = URI.decode_www_form(url_object.query || "")
118
+ challenge_pair = params.find { |k, _| k == "challenge" }
119
119
 
120
- challenge_parameter = query["challenge"]
121
- if challenge_parameter.nil? || challenge_parameter.empty? || challenge_parameter.first.nil?
120
+ if challenge_pair.nil? || challenge_pair.last.to_s.empty?
122
121
  raise "Invalid URL or no challenge parameter found."
123
122
  end
124
123
 
125
- challenge_parameter.first
124
+ challenge_pair.last
126
125
  end
127
126
  end
128
127
  end