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,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "resource"
|
|
4
|
+
require_relative "../handler/api_operations"
|
|
5
|
+
|
|
6
|
+
module Nylas
|
|
7
|
+
# Nylas Notetaker API
|
|
8
|
+
class Notetakers < Resource
|
|
9
|
+
include ApiOperations::Get
|
|
10
|
+
include ApiOperations::Post
|
|
11
|
+
include ApiOperations::Put
|
|
12
|
+
include ApiOperations::Delete
|
|
13
|
+
include ApiOperations::Patch
|
|
14
|
+
|
|
15
|
+
# Return all notetakers.
|
|
16
|
+
#
|
|
17
|
+
# @param identifier [String, nil] Grant ID or email account to query.
|
|
18
|
+
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
19
|
+
# @return [Array(Array(Hash), String, String)] The list of notetakers, API Request ID, and next cursor.
|
|
20
|
+
def list(identifier: nil, query_params: nil)
|
|
21
|
+
path = identifier ? "#{api_uri}/v3/grants/#{identifier}/notetakers" : "#{api_uri}/v3/notetakers"
|
|
22
|
+
|
|
23
|
+
get_list(
|
|
24
|
+
path: path,
|
|
25
|
+
query_params: query_params
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Return a notetaker.
|
|
30
|
+
#
|
|
31
|
+
# @param notetaker_id [String] The id of the notetaker to return.
|
|
32
|
+
# @param identifier [String, nil] Grant ID or email account to query.
|
|
33
|
+
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
34
|
+
# @return [Array(Hash, String)] The notetaker and API request ID.
|
|
35
|
+
def find(notetaker_id:, identifier: nil, query_params: nil)
|
|
36
|
+
base_path = "#{api_uri}/v3"
|
|
37
|
+
path = if identifier
|
|
38
|
+
"#{base_path}/grants/#{identifier}/notetakers/#{notetaker_id}"
|
|
39
|
+
else
|
|
40
|
+
"#{base_path}/notetakers/#{notetaker_id}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
get(
|
|
44
|
+
path: path,
|
|
45
|
+
query_params: query_params
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Invite a notetaker to a meeting.
|
|
50
|
+
#
|
|
51
|
+
# @param request_body [Hash] The values to create the notetaker with.
|
|
52
|
+
# @param identifier [String, nil] Grant ID or email account in which to create the object.
|
|
53
|
+
# @return [Array(Hash, String)] The created notetaker and API Request ID.
|
|
54
|
+
def create(request_body:, identifier: nil)
|
|
55
|
+
path = identifier ? "#{api_uri}/v3/grants/#{identifier}/notetakers" : "#{api_uri}/v3/notetakers"
|
|
56
|
+
|
|
57
|
+
post(
|
|
58
|
+
path: path,
|
|
59
|
+
request_body: request_body
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Update a scheduled notetaker.
|
|
64
|
+
#
|
|
65
|
+
# @param notetaker_id [String] The id of the notetaker to update.
|
|
66
|
+
# @param request_body [Hash] The values to update the notetaker with
|
|
67
|
+
# @param identifier [String, nil] Grant ID or email account in which to update an object.
|
|
68
|
+
# @return [Array(Hash, String)] The updated notetaker and API Request ID.
|
|
69
|
+
def update(notetaker_id:, request_body:, identifier: nil)
|
|
70
|
+
base_path = "#{api_uri}/v3"
|
|
71
|
+
path = if identifier
|
|
72
|
+
"#{base_path}/grants/#{identifier}/notetakers/#{notetaker_id}"
|
|
73
|
+
else
|
|
74
|
+
"#{base_path}/notetakers/#{notetaker_id}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
patch(
|
|
78
|
+
path: path,
|
|
79
|
+
request_body: request_body
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Download notetaker media.
|
|
84
|
+
#
|
|
85
|
+
# @param notetaker_id [String] The id of the notetaker to download media from.
|
|
86
|
+
# @param identifier [String, nil] Grant ID or email account to query.
|
|
87
|
+
# @param query_params [Hash, nil] Query params to pass to the request.
|
|
88
|
+
# @return [Array(Hash, String)] The media data and API request ID.
|
|
89
|
+
def download_media(notetaker_id:, identifier: nil, query_params: nil)
|
|
90
|
+
base_path = "#{api_uri}/v3"
|
|
91
|
+
path = if identifier
|
|
92
|
+
"#{base_path}/grants/#{identifier}/notetakers/#{notetaker_id}/media"
|
|
93
|
+
else
|
|
94
|
+
"#{base_path}/notetakers/#{notetaker_id}/media"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
get(
|
|
98
|
+
path: path,
|
|
99
|
+
query_params: query_params
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Remove a notetaker from a meeting.
|
|
104
|
+
#
|
|
105
|
+
# @param notetaker_id [String] The id of the notetaker to remove.
|
|
106
|
+
# @param identifier [String, nil] Grant ID or email account to query.
|
|
107
|
+
# @return [Array(Hash, String)] The response data and API request ID.
|
|
108
|
+
def leave(notetaker_id:, identifier: nil)
|
|
109
|
+
base_path = "#{api_uri}/v3"
|
|
110
|
+
path = if identifier
|
|
111
|
+
"#{base_path}/grants/#{identifier}/notetakers/#{notetaker_id}/leave"
|
|
112
|
+
else
|
|
113
|
+
"#{base_path}/notetakers/#{notetaker_id}/leave"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
post(
|
|
117
|
+
path: path,
|
|
118
|
+
request_body: {}
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Cancel a scheduled notetaker.
|
|
123
|
+
#
|
|
124
|
+
# @param notetaker_id [String] The id of the notetaker to cancel.
|
|
125
|
+
# @param identifier [String, nil] Grant ID or email account from which to delete an object.
|
|
126
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the cancel operation.
|
|
127
|
+
def cancel(notetaker_id:, identifier: nil)
|
|
128
|
+
base_path = "#{api_uri}/v3"
|
|
129
|
+
path = if identifier
|
|
130
|
+
"#{base_path}/grants/#{identifier}/notetakers/#{notetaker_id}/cancel"
|
|
131
|
+
else
|
|
132
|
+
"#{base_path}/notetakers/#{notetaker_id}/cancel"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
_, request_id = delete(
|
|
136
|
+
path: path
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
[true, request_id]
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
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::
|
|
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
|
-
|
|
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
|
|
@@ -22,6 +22,7 @@ module Nylas
|
|
|
22
22
|
MESSAGE_CREATED = "message.created"
|
|
23
23
|
MESSAGE_UPDATED = "message.updated"
|
|
24
24
|
MESSAGE_OPENED = "message.opened"
|
|
25
|
+
MESSAGE_BOUNCE_DETECTED = "message.bounce_detected"
|
|
25
26
|
MESSAGE_LINK_CLICKED = "message.link_clicked"
|
|
26
27
|
THREAD_REPLIED = "thread.replied"
|
|
27
28
|
FOLDER_CREATED = "folder.created"
|
|
@@ -113,14 +114,14 @@ module Nylas
|
|
|
113
114
|
# @return [String] The challenge parameter
|
|
114
115
|
def self.extract_challenge_parameter(url)
|
|
115
116
|
url_object = URI.parse(url)
|
|
116
|
-
|
|
117
|
+
params = URI.decode_www_form(url_object.query || "")
|
|
118
|
+
challenge_pair = params.find { |k, _| k == "challenge" }
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
if challenge_parameter.nil? || challenge_parameter.empty? || challenge_parameter.first.nil?
|
|
120
|
+
if challenge_pair.nil? || challenge_pair.last.to_s.empty?
|
|
120
121
|
raise "Invalid URL or no challenge parameter found."
|
|
121
122
|
end
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
challenge_pair.last
|
|
124
125
|
end
|
|
125
126
|
end
|
|
126
127
|
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "resource"
|
|
4
|
+
require_relative "../handler/api_operations"
|
|
5
|
+
|
|
6
|
+
module Nylas
|
|
7
|
+
# Nylas Workspaces API
|
|
8
|
+
#
|
|
9
|
+
# A workspace groups grants in a Nylas application by email domain. Grants can be
|
|
10
|
+
# auto-grouped (by matching email domain) or manually assigned/removed.
|
|
11
|
+
class Workspaces < Resource
|
|
12
|
+
include ApiOperations::Get
|
|
13
|
+
include ApiOperations::Post
|
|
14
|
+
include ApiOperations::Patch
|
|
15
|
+
include ApiOperations::Delete
|
|
16
|
+
|
|
17
|
+
# Return all workspaces for the application.
|
|
18
|
+
#
|
|
19
|
+
# The list endpoint is not paginated; +data+ is a flat array of workspaces.
|
|
20
|
+
#
|
|
21
|
+
# @return [Array(Array(Hash), String, Hash)] The list of workspaces, API Request ID,
|
|
22
|
+
# and response headers.
|
|
23
|
+
def list
|
|
24
|
+
get(
|
|
25
|
+
path: "#{api_uri}/v3/workspaces"
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Return a workspace.
|
|
30
|
+
#
|
|
31
|
+
# @param workspace_id [String] The id of the workspace to return. Accepts a workspace
|
|
32
|
+
# UUID or an email domain.
|
|
33
|
+
# @return [Array(Hash, String, Hash)] The workspace, API Request ID, and response headers.
|
|
34
|
+
def find(workspace_id:)
|
|
35
|
+
get(
|
|
36
|
+
path: "#{api_uri}/v3/workspaces/#{workspace_id}"
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Create a workspace.
|
|
41
|
+
#
|
|
42
|
+
# @param request_body [Hash] The values to create the workspace with. Only +name+ is
|
|
43
|
+
# required.
|
|
44
|
+
# @return [Array(Hash, String, Hash)] The created workspace, API Request ID, and
|
|
45
|
+
# response headers.
|
|
46
|
+
def create(request_body:)
|
|
47
|
+
post(
|
|
48
|
+
path: "#{api_uri}/v3/workspaces",
|
|
49
|
+
request_body: request_body
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Update a workspace.
|
|
54
|
+
#
|
|
55
|
+
# The API exposes update via PATCH only (there is no PUT route). The workspace must be
|
|
56
|
+
# addressed by its UUID; a domain path param is not accepted on update.
|
|
57
|
+
#
|
|
58
|
+
# @param workspace_id [String] The UUID of the workspace to update.
|
|
59
|
+
# @param request_body [Hash] The values to update the workspace with.
|
|
60
|
+
# @return [Array(Hash, String)] The updated workspace and API Request ID.
|
|
61
|
+
def update(workspace_id:, request_body:)
|
|
62
|
+
patch(
|
|
63
|
+
path: "#{api_uri}/v3/workspaces/#{workspace_id}",
|
|
64
|
+
request_body: request_body
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Delete a workspace.
|
|
69
|
+
#
|
|
70
|
+
# @param workspace_id [String] The id of the workspace to delete. Accepts a workspace
|
|
71
|
+
# UUID or an email domain.
|
|
72
|
+
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
|
|
73
|
+
def destroy(workspace_id:)
|
|
74
|
+
_, request_id = delete(
|
|
75
|
+
path: "#{api_uri}/v3/workspaces/#{workspace_id}"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
[true, request_id]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Auto-group grants into workspaces by matching email domain.
|
|
82
|
+
#
|
|
83
|
+
# Runs as a background job and returns immediately with a job ID. Rate limited to one
|
|
84
|
+
# call per minute per application.
|
|
85
|
+
#
|
|
86
|
+
# @param request_body [Hash] Optional filters to scope which grants are grouped,
|
|
87
|
+
# including +after_created_at+, +invalid_also+, and +specific_domain+.
|
|
88
|
+
# @return [Array(Hash, String, Hash)] The job info, API Request ID, and response headers.
|
|
89
|
+
def auto_group(request_body: nil)
|
|
90
|
+
post(
|
|
91
|
+
path: "#{api_uri}/v3/workspaces/auto-group",
|
|
92
|
+
request_body: request_body
|
|
93
|
+
)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Manually assign grants to or remove grants from a workspace.
|
|
97
|
+
#
|
|
98
|
+
# @param workspace_id [String] The id of the workspace to update. Accepts a workspace
|
|
99
|
+
# UUID or an email domain.
|
|
100
|
+
# @param request_body [Hash] The grants to assign and/or remove (+assign_grants+,
|
|
101
|
+
# +remove_grants+).
|
|
102
|
+
# @return [Array(Hash, String, Hash)] The assignment result, API Request ID, and
|
|
103
|
+
# response headers.
|
|
104
|
+
def manual_assign(workspace_id:, request_body:)
|
|
105
|
+
post(
|
|
106
|
+
path: "#{api_uri}/v3/workspaces/#{workspace_id}/manual-assign",
|
|
107
|
+
request_body: request_body
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -28,12 +28,13 @@ module Nylas
|
|
|
28
28
|
|
|
29
29
|
attachments.each_with_index do |attachment, index|
|
|
30
30
|
file = attachment[:content] || attachment["content"]
|
|
31
|
+
file_path = attachment[:file_path] || attachment["file_path"]
|
|
31
32
|
if file.respond_to?(:closed?) && file.closed?
|
|
32
|
-
unless
|
|
33
|
+
unless file_path
|
|
33
34
|
raise ArgumentError, "The file at index #{index} is closed and no file_path was provided."
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
file = File.open(
|
|
37
|
+
file = File.open(file_path, "rb")
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
# Setting original filename and content type if available. See rest-client#lib/restclient/payload.rb
|
|
@@ -62,6 +63,7 @@ module Nylas
|
|
|
62
63
|
opened_files = []
|
|
63
64
|
|
|
64
65
|
attachments.each_with_index do |attachment, _index|
|
|
66
|
+
attachment.delete(:file_path)
|
|
65
67
|
current_attachment = attachment[:content]
|
|
66
68
|
next unless current_attachment
|
|
67
69
|
|
|
@@ -86,7 +88,9 @@ module Nylas
|
|
|
86
88
|
|
|
87
89
|
# Use form data only if the attachment size is greater than 3mb
|
|
88
90
|
attachments = payload[:attachments]
|
|
89
|
-
|
|
91
|
+
# Support both string and symbol keys for attachment size to handle
|
|
92
|
+
# user-provided hashes that may use either key type
|
|
93
|
+
attachment_size = attachments&.sum { |attachment| attachment[:size] || attachment["size"] || 0 } || 0
|
|
90
94
|
|
|
91
95
|
# Handle the attachment encoding depending on the size
|
|
92
96
|
if attachment_size >= FORM_DATA_ATTACHMENT_SIZE
|
data/lib/nylas/version.rb
CHANGED
data/lib/nylas.rb
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
-
require "
|
|
5
|
-
|
|
6
|
-
# BUGFIX
|
|
7
|
-
# See https://github.com/sparklemotion/http-cookie/issues/27
|
|
8
|
-
# and https://github.com/sparklemotion/http-cookie/issues/6
|
|
9
|
-
#
|
|
10
|
-
# CookieJar uses unsafe class caching for dynamically loading cookie jars.
|
|
11
|
-
# If two rest-client instances are instantiated at the same time (in threads), non-deterministic
|
|
12
|
-
# behaviour can occur whereby the Hash cookie jar isn't properly loaded and cached.
|
|
13
|
-
# Forcing an instantiation of the jar onload will force the CookieJar to load before the system has
|
|
14
|
-
# a chance to spawn any threads.
|
|
15
|
-
# Note that this should technically be fixed in rest-client itself, however that library appears to
|
|
16
|
-
# be stagnant so we're forced to fix it here.
|
|
17
|
-
# This object should get GC'd as it's not referenced by anything.
|
|
18
|
-
HTTP::CookieJar.new
|
|
4
|
+
require "httparty"
|
|
19
5
|
|
|
20
6
|
require "ostruct"
|
|
21
7
|
require "forwardable"
|
|
@@ -26,6 +12,7 @@ require_relative "nylas/client"
|
|
|
26
12
|
require_relative "nylas/config"
|
|
27
13
|
|
|
28
14
|
require_relative "nylas/handler/http_client"
|
|
15
|
+
require_relative "nylas/handler/service_account_signer"
|
|
29
16
|
|
|
30
17
|
require_relative "nylas/resources/applications"
|
|
31
18
|
require_relative "nylas/resources/attachments"
|
|
@@ -38,10 +25,16 @@ require_relative "nylas/resources/drafts"
|
|
|
38
25
|
require_relative "nylas/resources/events"
|
|
39
26
|
require_relative "nylas/resources/folders"
|
|
40
27
|
require_relative "nylas/resources/grants"
|
|
28
|
+
require_relative "nylas/resources/lists"
|
|
41
29
|
require_relative "nylas/resources/messages"
|
|
30
|
+
require_relative "nylas/resources/notetakers"
|
|
42
31
|
require_relative "nylas/resources/smart_compose"
|
|
43
32
|
require_relative "nylas/resources/threads"
|
|
44
33
|
require_relative "nylas/resources/redirect_uris"
|
|
34
|
+
require_relative "nylas/resources/policies"
|
|
35
|
+
require_relative "nylas/resources/rules"
|
|
36
|
+
require_relative "nylas/resources/workspaces"
|
|
37
|
+
require_relative "nylas/resources/domains"
|
|
45
38
|
require_relative "nylas/resources/webhooks"
|
|
46
39
|
require_relative "nylas/resources/scheduler"
|
|
47
40
|
|