nylas-legacy 5.17.0 → 5.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nylas-legacy/account.rb +56 -0
- data/lib/nylas-legacy/api.rb +265 -0
- data/lib/nylas-legacy/application_details.rb +13 -0
- data/lib/nylas-legacy/calendar.rb +46 -0
- data/lib/nylas-legacy/calendar_collection.rb +144 -0
- data/lib/nylas-legacy/categorize.rb +14 -0
- data/lib/nylas-legacy/collection.rb +175 -0
- data/lib/nylas-legacy/component.rb +35 -0
- data/lib/nylas-legacy/component_collection.rb +10 -0
- data/lib/nylas-legacy/constraints.rb +56 -0
- data/lib/nylas-legacy/contact.rb +53 -0
- data/lib/nylas-legacy/contact_group.rb +23 -0
- data/lib/nylas-legacy/current_account.rb +23 -0
- data/lib/nylas-legacy/delta.rb +56 -0
- data/lib/nylas-legacy/deltas.rb +19 -0
- data/lib/nylas-legacy/deltas_collection.rb +40 -0
- data/lib/nylas-legacy/draft.rb +101 -0
- data/lib/nylas-legacy/email_address.rb +12 -0
- data/lib/nylas-legacy/errors.rb +111 -0
- data/lib/nylas-legacy/event.rb +144 -0
- data/lib/nylas-legacy/event_collection.rb +15 -0
- data/lib/nylas-legacy/event_conferencing.rb +12 -0
- data/lib/nylas-legacy/event_conferencing_autocreate.rb +10 -0
- data/lib/nylas-legacy/event_conferencing_details.rb +14 -0
- data/lib/nylas-legacy/event_notification.rb +17 -0
- data/lib/nylas-legacy/file.rb +75 -0
- data/lib/nylas-legacy/filter_attributes.rb +25 -0
- data/lib/nylas-legacy/folder.rb +26 -0
- data/lib/nylas-legacy/free_busy.rb +13 -0
- data/lib/nylas-legacy/free_busy_collection.rb +48 -0
- data/lib/nylas-legacy/http_client.rb +280 -0
- data/lib/nylas-legacy/im_address.rb +11 -0
- data/lib/nylas-legacy/job_status.rb +27 -0
- data/lib/nylas-legacy/job_status_collection.rb +21 -0
- data/lib/nylas-legacy/label.rb +27 -0
- data/lib/nylas-legacy/logging.rb +41 -0
- data/lib/nylas-legacy/message.rb +98 -0
- data/lib/nylas-legacy/message_headers.rb +27 -0
- data/lib/nylas-legacy/message_tracking.rb +13 -0
- data/lib/nylas-legacy/model/attributable.rb +89 -0
- data/lib/nylas-legacy/model/attribute_definition.rb +24 -0
- data/lib/nylas-legacy/model/attributes.rb +97 -0
- data/lib/nylas-legacy/model/list_attribute_definition.rb +39 -0
- data/lib/nylas-legacy/model/transferable.rb +53 -0
- data/lib/nylas-legacy/model.rb +217 -0
- data/lib/nylas-legacy/native_authentication.rb +39 -0
- data/lib/nylas-legacy/neural.rb +87 -0
- data/lib/nylas-legacy/neural_categorizer.rb +29 -0
- data/lib/nylas-legacy/neural_clean_conversation.rb +33 -0
- data/lib/nylas-legacy/neural_contact_link.rb +11 -0
- data/lib/nylas-legacy/neural_contact_name.rb +11 -0
- data/lib/nylas-legacy/neural_message_options.rb +35 -0
- data/lib/nylas-legacy/neural_ocr.rb +16 -0
- data/lib/nylas-legacy/neural_sentiment_analysis.rb +17 -0
- data/lib/nylas-legacy/neural_signature_contact.rb +81 -0
- data/lib/nylas-legacy/neural_signature_extraction.rb +18 -0
- data/lib/nylas-legacy/new_message.rb +41 -0
- data/lib/nylas-legacy/nylas_date.rb +25 -0
- data/lib/nylas-legacy/open_hours.rb +15 -0
- data/lib/nylas-legacy/outbox.rb +116 -0
- data/lib/nylas-legacy/outbox_job_status.rb +19 -0
- data/lib/nylas-legacy/outbox_message.rb +17 -0
- data/lib/nylas-legacy/participant.rb +13 -0
- data/lib/nylas-legacy/phone_number.rb +11 -0
- data/lib/nylas-legacy/physical_address.rb +17 -0
- data/lib/nylas-legacy/raw_message.rb +25 -0
- data/lib/nylas-legacy/recurrence.rb +11 -0
- data/lib/nylas-legacy/registry.rb +42 -0
- data/lib/nylas-legacy/room_resource.rb +19 -0
- data/lib/nylas-legacy/rsvp.rb +24 -0
- data/lib/nylas-legacy/scheduler.rb +51 -0
- data/lib/nylas-legacy/scheduler_booking_confirmation.rb +24 -0
- data/lib/nylas-legacy/scheduler_booking_request.rb +17 -0
- data/lib/nylas-legacy/scheduler_collection.rb +104 -0
- data/lib/nylas-legacy/scheduler_config.rb +20 -0
- data/lib/nylas-legacy/scheduler_time_slot.rb +14 -0
- data/lib/nylas-legacy/search_collection.rb +14 -0
- data/lib/nylas-legacy/send_grid_verified_status.rb +12 -0
- data/lib/nylas-legacy/services/tunnel.rb +128 -0
- data/lib/nylas-legacy/thread.rb +66 -0
- data/lib/nylas-legacy/time_slot.rb +16 -0
- data/lib/nylas-legacy/time_slot_capacity.rb +13 -0
- data/lib/nylas-legacy/timespan.rb +20 -0
- data/lib/nylas-legacy/token_info.rb +20 -0
- data/lib/nylas-legacy/types.rb +169 -0
- data/lib/nylas-legacy/version.rb +5 -0
- data/lib/nylas-legacy/web_page.rb +11 -0
- data/lib/nylas-legacy/webhook.rb +111 -0
- data/lib/nylas-legacy/when.rb +75 -0
- data/lib/nylas-legacy.rb +164 -0
- metadata +175 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 607e84f20f666b534f194963686cc7be6b7eb1806a383053041c7c0aa1297335
|
4
|
+
data.tar.gz: 22cce4f9c9a2cb9aec4b5f2eff2f59c95465fe5d0e790eb50e4d5eda933faf0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '019a2409e905818fe5deefce5a7f68d1613d4ee0f8840bc1a72ca18fb0d084f16307f464a586104047ecfe009bb1b99fccf670f2beb519eaff55f81092639c2b'
|
7
|
+
data.tar.gz: 4f131fa1fc168e9eb729ce20aac3de5ab3502b5eb78fff5728655032de0db7c9fc47a7f32e4abe365a6656143ba024380efaa2cd1231a52b9b392519843282ef
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Representation of the accounts for Account management purposes.
|
5
|
+
# @see https://docs.nylas.com/reference#account-management
|
6
|
+
class Account
|
7
|
+
include Model
|
8
|
+
self.listable = true
|
9
|
+
self.showable = true
|
10
|
+
self.updatable = true
|
11
|
+
self.destroyable = true
|
12
|
+
self.filterable = true
|
13
|
+
self.auth_method = HttpClient::AuthMethod::BASIC
|
14
|
+
|
15
|
+
attribute :id, :string, read_only: true
|
16
|
+
attribute :account_id, :string, read_only: true
|
17
|
+
attribute :billing_state, :string, read_only: true
|
18
|
+
attribute :sync_state, :string, read_only: true
|
19
|
+
attribute :provider, :string, read_only: true
|
20
|
+
attribute :authentication_type, :string, read_only: true
|
21
|
+
|
22
|
+
attribute :email, :string, read_only: true
|
23
|
+
attribute :trial, :boolean, read_only: true
|
24
|
+
attribute :metadata, :hash
|
25
|
+
|
26
|
+
def upgrade
|
27
|
+
response = execute(method: :post, path: "#{resource_path}/upgrade")
|
28
|
+
response[:success]
|
29
|
+
end
|
30
|
+
|
31
|
+
def downgrade
|
32
|
+
response = execute(method: :post, path: "#{resource_path}/downgrade")
|
33
|
+
response[:success]
|
34
|
+
end
|
35
|
+
|
36
|
+
def revoke_all(keep_access_token: nil)
|
37
|
+
payload = JSON.dump(keep_access_token: keep_access_token) if keep_access_token
|
38
|
+
|
39
|
+
response = execute(method: :post, path: "#{resource_path}/revoke-all", payload: payload)
|
40
|
+
response[:success]
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return information about an account's access token
|
44
|
+
# @param access_token [String] The access token to inquire about
|
45
|
+
# @return [TokenInfo] The access token information
|
46
|
+
def token_info(access_token)
|
47
|
+
payload = JSON.dump(access_token: access_token)
|
48
|
+
response = execute(method: :post, path: "#{resource_path}/token-info", payload: payload)
|
49
|
+
TokenInfo.new(**response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.resources_path(api:)
|
53
|
+
"/a/#{api.app_id}/accounts"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Methods to retrieve data from the Nylas API as Ruby objects
|
5
|
+
class API
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :client, :execute, :get, :post, :put, :delete, :app_id, :api_server
|
10
|
+
|
11
|
+
include Logging
|
12
|
+
|
13
|
+
# @param client [HttpClient] Http Client to use for retrieving data
|
14
|
+
# @param app_id [String] Your application id from the Nylas Dashboard
|
15
|
+
# @param app_secret [String] Your application secret from the Nylas Dashboard
|
16
|
+
# @param access_token [String] (Optional) Your users access token.
|
17
|
+
# @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if
|
18
|
+
# you're using a self-hosted Nylas instance.
|
19
|
+
# @return [NylasLegacy::API]
|
20
|
+
def initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil,
|
21
|
+
api_server: "https://api.nylas.com")
|
22
|
+
self.client = client || HttpClient.new(app_id: app_id, app_secret: app_secret,
|
23
|
+
access_token: access_token, api_server: api_server)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [String] A Nylas access token for that particular user.
|
27
|
+
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil, scopes: nil,
|
28
|
+
return_full_response: false)
|
29
|
+
NativeAuthentication.new(api: self).authenticate(
|
30
|
+
name: name,
|
31
|
+
email_address: email_address,
|
32
|
+
provider: provider,
|
33
|
+
settings: settings,
|
34
|
+
reauth_account_id: reauth_account_id,
|
35
|
+
scopes: scopes,
|
36
|
+
return_full_response: return_full_response
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil,
|
41
|
+
provider: nil, redirect_on_error: nil, disable_provider_selection: nil)
|
42
|
+
params = { client_id: app_id, redirect_uri: redirect_uri, response_type: response_type,
|
43
|
+
login_hint: login_hint }
|
44
|
+
|
45
|
+
params[:state] = state if state
|
46
|
+
params[:scopes] = scopes.join(",") if scopes
|
47
|
+
params[:provider] = provider if provider
|
48
|
+
params[:redirect_on_error] = redirect_on_error if redirect_on_error
|
49
|
+
params[:disable_provider_selection] = disable_provider_selection if disable_provider_selection
|
50
|
+
|
51
|
+
"#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Exchanges an authorization code for an access token
|
55
|
+
# @param code [String] The authorization code to exchange
|
56
|
+
# @param return_full_response [Boolean] If true, returns the full response body instead of just the token
|
57
|
+
# @return [String | Hash] Returns just the access token as a string, or the full response as a hash
|
58
|
+
def exchange_code_for_token(code, return_full_response: false)
|
59
|
+
data = {
|
60
|
+
"client_id" => app_id,
|
61
|
+
"client_secret" => client.app_secret,
|
62
|
+
"grant_type" => "authorization_code",
|
63
|
+
"code" => code
|
64
|
+
}
|
65
|
+
|
66
|
+
response = execute(method: :post, path: "/oauth/token", payload: data)
|
67
|
+
return_full_response ? response : response[:access_token]
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Collection<Contact>] A queryable collection of Contacts
|
71
|
+
def contacts
|
72
|
+
@contacts ||= Collection.new(model: Contact, api: self)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Collection<ContactGroup>] A queryable collection of Contact Groups
|
76
|
+
def contact_groups
|
77
|
+
@contact_groups ||= Collection.new(model: ContactGroup, api: self)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [CurrentAccount] The account details for whomevers access token is set
|
81
|
+
def current_account
|
82
|
+
prevent_calling_if_missing_access_token(:current_account)
|
83
|
+
CurrentAccount.from_hash(execute(method: :get, path: "/account"), api: self)
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Collection<Account>] A queryable collection of {Account}s
|
87
|
+
def accounts
|
88
|
+
@accounts ||= Collection.new(model: Account, api: as(client.app_secret))
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [CalendarCollection<Calendar>] A queryable collection of {Calendar}s
|
92
|
+
def calendars
|
93
|
+
@calendars ||= CalendarCollection.new(model: Calendar, api: self)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [DeltasCollection<Delta>] A queryable collection of Deltas, which are themselves a collection.
|
97
|
+
def deltas
|
98
|
+
@deltas ||= DeltasCollection.new(api: self)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return[Collection<Draft>] A queryable collection of {Draft} objects
|
102
|
+
def drafts
|
103
|
+
@drafts ||= Collection.new(model: Draft, api: self)
|
104
|
+
end
|
105
|
+
|
106
|
+
# @return [EventCollection<Event>] A queryable collection of {Event}s
|
107
|
+
def events
|
108
|
+
@events ||= EventCollection.new(model: Event, api: self)
|
109
|
+
end
|
110
|
+
|
111
|
+
# @return [Collection<Folder>] A queryable collection of {Folder}s
|
112
|
+
def folders
|
113
|
+
@folders ||= Collection.new(model: Folder, api: self)
|
114
|
+
end
|
115
|
+
|
116
|
+
# @return [Collection<File>] A queryable collection of {File}s
|
117
|
+
def files
|
118
|
+
@files ||= Collection.new(model: File, api: self)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @return [Collection<Label>] A queryable collection of {Label} objects
|
122
|
+
def labels
|
123
|
+
@labels ||= Collection.new(model: Label, api: self)
|
124
|
+
end
|
125
|
+
|
126
|
+
# @return[Collection<Message>] A queryable collection of {Message} objects
|
127
|
+
def messages
|
128
|
+
@messages ||= Collection.new(model: Message, api: self)
|
129
|
+
end
|
130
|
+
|
131
|
+
# @return[Collection<RoomResource>] A queryable collection of {RoomResource} objects
|
132
|
+
def room_resources
|
133
|
+
@room_resources ||= Collection.new(model: RoomResource, api: self)
|
134
|
+
end
|
135
|
+
|
136
|
+
# @return[Collection<JobStatus>] A queryable collection of {JobStatus} objects
|
137
|
+
def job_statuses
|
138
|
+
@job_statuses ||= JobStatusCollection.new(model: JobStatus, api: self)
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return[OutboxCollection] A collection of Outbox operations
|
142
|
+
def outbox
|
143
|
+
@outbox ||= Outbox.new(api: self)
|
144
|
+
end
|
145
|
+
|
146
|
+
# @return[SchedulerCollection<Scheduler>] A queryable collection of {Scheduler} objects
|
147
|
+
def scheduler
|
148
|
+
# Make a deep copy of the API as the scheduler API uses a different base URL
|
149
|
+
scheduler_api = Marshal.load(Marshal.dump(self))
|
150
|
+
scheduler_api.client.api_server = "https://api.schedule.nylas.com"
|
151
|
+
@scheduler ||= SchedulerCollection.new(model: Scheduler, api: scheduler_api)
|
152
|
+
end
|
153
|
+
|
154
|
+
# @return[Neural] A collection of Neural operations
|
155
|
+
def neural
|
156
|
+
@neural ||= Neural.new(api: self)
|
157
|
+
end
|
158
|
+
|
159
|
+
# @return [Collection<Component>] A queryable collection of {Component}s
|
160
|
+
def components
|
161
|
+
@components ||= ComponentCollection.new(model: Component, api: as(client.app_secret))
|
162
|
+
end
|
163
|
+
|
164
|
+
# Revokes access to the Nylas API for the given access token
|
165
|
+
# @return [Boolean]
|
166
|
+
def revoke(access_token)
|
167
|
+
response = client.as(access_token).post(path: "/oauth/revoke")
|
168
|
+
response.code == 200 && response.empty?
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns the application details
|
172
|
+
# @return [ApplicationDetail] The application details
|
173
|
+
def application_details
|
174
|
+
response = client.as(client.app_secret).execute(
|
175
|
+
method: :get,
|
176
|
+
path: "/a/#{app_id}",
|
177
|
+
auth_method: HttpClient::AuthMethod::BASIC
|
178
|
+
)
|
179
|
+
ApplicationDetail.new(**response)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Updates the application details
|
183
|
+
# @param application_details [ApplicationDetail] The updated application details
|
184
|
+
# @return [ApplicationDetails] The updated application details, returned from the server
|
185
|
+
def update_application_details(application_details)
|
186
|
+
response = client.as(client.app_secret).execute(
|
187
|
+
method: :put,
|
188
|
+
path: "/a/#{app_id}",
|
189
|
+
payload: JSON.dump(application_details.to_h),
|
190
|
+
auth_method: HttpClient::AuthMethod::BASIC
|
191
|
+
)
|
192
|
+
ApplicationDetail.new(**response)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Returns list of IP addresses
|
196
|
+
# @return [Hash]
|
197
|
+
# hash has keys of :updated_at (unix timestamp) and :ip_addresses (array of strings)
|
198
|
+
def ip_addresses
|
199
|
+
path = "/a/#{app_id}/ip_addresses"
|
200
|
+
client.as(client.app_secret).get(path: path, auth_method: HttpClient::AuthMethod::BASIC)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns list of IP addresses
|
204
|
+
# @param email_address [String] The email address to detect the provider for
|
205
|
+
# @return [Hash] The provider information
|
206
|
+
# hash has keys of :updated_at (unix timestamp) and :ip_addresses (array of strings)
|
207
|
+
def detect_provider(email_address)
|
208
|
+
payload = {
|
209
|
+
"client_id" => app_id,
|
210
|
+
"client_secret" => client.app_secret,
|
211
|
+
"email_address" => email_address
|
212
|
+
}
|
213
|
+
|
214
|
+
client.as(client.app_secret).execute(
|
215
|
+
method: :post,
|
216
|
+
path: "/connect/detect-provider",
|
217
|
+
payload: JSON.dump(payload)
|
218
|
+
)
|
219
|
+
end
|
220
|
+
|
221
|
+
# @param message [Hash, String, #send!]
|
222
|
+
# @return [Message] The resulting message
|
223
|
+
def send!(message)
|
224
|
+
return message.send! if message.respond_to?(:send!)
|
225
|
+
return NewMessage.new(**message.merge(api: self)).send! if message.respond_to?(:key?)
|
226
|
+
|
227
|
+
RawMessage.new(message, api: self).send! if message.is_a? String
|
228
|
+
end
|
229
|
+
|
230
|
+
# Allows you to get an API that acts as a different user but otherwise has the same settings
|
231
|
+
# @param access_token [String] Oauth Access token or app secret used to authenticate with the API
|
232
|
+
# @return [API]
|
233
|
+
def as(access_token)
|
234
|
+
API.new(client: client.as(access_token))
|
235
|
+
end
|
236
|
+
|
237
|
+
# @return [Collection<Thread>] A queryable collection of Threads
|
238
|
+
def threads
|
239
|
+
@threads ||= Collection.new(model: Thread, api: self)
|
240
|
+
end
|
241
|
+
|
242
|
+
# @return [Collection<Webhook>] A queryable collection of {Webhook}s
|
243
|
+
def webhooks
|
244
|
+
@webhooks ||= Collection.new(model: Webhook, api: as(client.app_secret))
|
245
|
+
end
|
246
|
+
|
247
|
+
# TODO: Move this into calendar collection
|
248
|
+
def free_busy(emails:, start_time:, end_time:)
|
249
|
+
FreeBusyCollection.new(
|
250
|
+
api: self,
|
251
|
+
emails: emails,
|
252
|
+
start_time: start_time.to_i,
|
253
|
+
end_time: end_time.to_i
|
254
|
+
)
|
255
|
+
end
|
256
|
+
|
257
|
+
private
|
258
|
+
|
259
|
+
def prevent_calling_if_missing_access_token(method_name)
|
260
|
+
return if client.access_token && !client.access_token.empty?
|
261
|
+
|
262
|
+
raise NoAuthToken, method_name
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Structure to represent a Nylas Application Detail object.
|
5
|
+
# @see https://developer.nylas.com/docs/api/#get/a/client_id
|
6
|
+
class ApplicationDetail
|
7
|
+
include Model::Attributable
|
8
|
+
|
9
|
+
attribute :application_name, :string
|
10
|
+
attribute :icon_url, :string
|
11
|
+
has_n_of_attribute :redirect_uris, :string
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Ruby bindings for the Nylas Calendar API
|
5
|
+
# @see https://docs.nylas.com/reference#calendars
|
6
|
+
class Calendar
|
7
|
+
include Model
|
8
|
+
self.resources_path = "/calendars"
|
9
|
+
self.creatable = true
|
10
|
+
self.listable = true
|
11
|
+
self.showable = true
|
12
|
+
self.filterable = true
|
13
|
+
self.updatable = true
|
14
|
+
self.destroyable = true
|
15
|
+
self.id_listable = true
|
16
|
+
self.countable = true
|
17
|
+
|
18
|
+
attribute :id, :string
|
19
|
+
attribute :account_id, :string
|
20
|
+
|
21
|
+
attribute :object, :string
|
22
|
+
|
23
|
+
attribute :name, :string
|
24
|
+
attribute :description, :string
|
25
|
+
attribute :is_primary, :boolean
|
26
|
+
attribute :location, :string
|
27
|
+
attribute :timezone, :string
|
28
|
+
|
29
|
+
attribute :read_only, :boolean
|
30
|
+
attribute :metadata, :hash
|
31
|
+
attribute :job_status_id, :string, read_only: true
|
32
|
+
attribute :hex_color, :string, read_only: true
|
33
|
+
|
34
|
+
def read_only?
|
35
|
+
read_only == true
|
36
|
+
end
|
37
|
+
|
38
|
+
def primary?
|
39
|
+
is_primary
|
40
|
+
end
|
41
|
+
|
42
|
+
def events
|
43
|
+
api.events.where(calendar_id: id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Additional methods for some of Calendar's other functionality
|
5
|
+
# @see https://developer.nylas.com/docs/connectivity/calendar
|
6
|
+
class CalendarCollection < Collection
|
7
|
+
# Check multiple calendars to find available time slots for a single meeting
|
8
|
+
# @param duration_minutes [Integer] The total number of minutes the event should last
|
9
|
+
# @param interval_minutes [Integer] How many minutes it should check for availability
|
10
|
+
# @param start_time [Integer] The timestamp for the beginning of the event
|
11
|
+
# @param end_time [Integer] The timestamp for the end of the event
|
12
|
+
# @param emails [Array<String>] Emails on the same domain to check
|
13
|
+
# @param buffer [Integer] The amount of buffer time in minutes that you want around existing meetings
|
14
|
+
# @param round_robin [String] Finds available meeting times in a round-robin style
|
15
|
+
# @param event_collection_id [String] Unique identifier for a collection of events that are created
|
16
|
+
# @param free_busy [Array<NylasLegacy::FreeBusy>] A list of free-busy data for users not in your organization
|
17
|
+
# @param open_hours [Array<NylasLegacy::OpenHours>] Additional times email accounts are available
|
18
|
+
# @param calendars [Array] Check account and calendar IDs for free/busy status
|
19
|
+
# @return [Hash] The availability information; a list of time slots where all participants are available
|
20
|
+
def availability(duration_minutes:,
|
21
|
+
interval_minutes:,
|
22
|
+
start_time:,
|
23
|
+
end_time:,
|
24
|
+
emails: [],
|
25
|
+
buffer: nil,
|
26
|
+
round_robin: nil,
|
27
|
+
event_collection_id: nil,
|
28
|
+
free_busy: [],
|
29
|
+
open_hours: [],
|
30
|
+
calendars: [])
|
31
|
+
validate_calendars_or_emails(calendars, emails)
|
32
|
+
validate_open_hours(emails, free_busy, open_hours) unless open_hours.empty?
|
33
|
+
|
34
|
+
payload = {
|
35
|
+
duration_minutes: duration_minutes,
|
36
|
+
interval_minutes: interval_minutes,
|
37
|
+
start_time: start_time,
|
38
|
+
end_time: end_time,
|
39
|
+
emails: emails,
|
40
|
+
free_busy: free_busy.map(&:to_h),
|
41
|
+
open_hours: open_hours.map(&:to_h),
|
42
|
+
calendars: calendars
|
43
|
+
}
|
44
|
+
payload[:buffer] = buffer if buffer
|
45
|
+
payload[:round_robin] = round_robin if round_robin
|
46
|
+
payload[:event_collection_id] = event_collection_id if event_collection_id
|
47
|
+
|
48
|
+
execute_availability("/calendars/availability", **payload)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Check multiple calendars to find availability for multiple meetings with several participants
|
52
|
+
# @param duration_minutes [Integer] The total number of minutes the event should last
|
53
|
+
# @param interval_minutes [Integer] How many minutes it should check for availability
|
54
|
+
# @param start_time [Integer] The timestamp for the beginning of the event
|
55
|
+
# @param end_time [Integer] The timestamp for the end of the event
|
56
|
+
# @param emails [Array<Array<String>>] Emails on the same domain to check
|
57
|
+
# @param buffer [Integer] The amount of buffer time in minutes that you want around existing meetings
|
58
|
+
# @param free_busy [Array<NylasLegacy::FreeBusy>] A list of free-busy data for users not in your organization
|
59
|
+
# @param open_hours [Array<NylasLegacy::OpenHours>] Additional times email accounts are available
|
60
|
+
# @param calendars [Array] Check account and calendar IDs for free/busy status
|
61
|
+
# @return [Hash] The availability information; a list of all possible groupings that share time slots
|
62
|
+
def consecutive_availability(duration_minutes:,
|
63
|
+
interval_minutes:,
|
64
|
+
start_time:,
|
65
|
+
end_time:,
|
66
|
+
emails: [],
|
67
|
+
buffer: nil,
|
68
|
+
free_busy: [],
|
69
|
+
open_hours: [],
|
70
|
+
calendars: [])
|
71
|
+
validate_calendars_or_emails(emails, calendars)
|
72
|
+
validate_open_hours(emails, free_busy, open_hours) unless open_hours.empty?
|
73
|
+
|
74
|
+
payload = {
|
75
|
+
duration_minutes: duration_minutes,
|
76
|
+
interval_minutes: interval_minutes,
|
77
|
+
start_time: start_time,
|
78
|
+
end_time: end_time,
|
79
|
+
emails: emails,
|
80
|
+
free_busy: free_busy.map(&:to_h),
|
81
|
+
open_hours: open_hours.map(&:to_h),
|
82
|
+
calendars: calendars
|
83
|
+
}
|
84
|
+
payload[:buffer] = buffer if buffer
|
85
|
+
|
86
|
+
execute_availability("/calendars/availability/consecutive", **payload)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def execute_availability(path, **payload)
|
92
|
+
api.execute(
|
93
|
+
method: :post,
|
94
|
+
path: path,
|
95
|
+
payload: JSON.dump(payload)
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
def validate_calendars_or_emails(calendars, emails)
|
100
|
+
return unless calendars.empty? && emails.empty?
|
101
|
+
|
102
|
+
raise ArgumentError, "You must provide at least one of 'emails' or 'calendars'"
|
103
|
+
end
|
104
|
+
|
105
|
+
def validate_open_hours(emails, free_busy, open_hours)
|
106
|
+
raise TypeError, "open_hours' must be an array." unless open_hours.is_a?(Array)
|
107
|
+
|
108
|
+
open_hours_emails = map_open_hours_emails(open_hours)
|
109
|
+
free_busy_emails = map_free_busy_emails(free_busy)
|
110
|
+
emails = merge_arrays(emails) if emails[0].is_a?(Array)
|
111
|
+
|
112
|
+
open_hours_emails.each do |email|
|
113
|
+
next if emails.include?(email) || free_busy_emails.include?(email)
|
114
|
+
|
115
|
+
raise ArgumentError, "Open Hours cannot contain an email not present in the main email list or
|
116
|
+
the free busy email list."
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def map_open_hours_emails(open_hours)
|
121
|
+
open_hours_emails = []
|
122
|
+
open_hours.map do |oh|
|
123
|
+
open_hours_emails += oh.emails
|
124
|
+
end
|
125
|
+
open_hours_emails
|
126
|
+
end
|
127
|
+
|
128
|
+
def map_free_busy_emails(free_busy)
|
129
|
+
free_busy_emails = []
|
130
|
+
free_busy.map do |fb|
|
131
|
+
free_busy_emails.append(fb.email)
|
132
|
+
end
|
133
|
+
free_busy_emails
|
134
|
+
end
|
135
|
+
|
136
|
+
def merge_arrays(array)
|
137
|
+
list = []
|
138
|
+
array.each do |x|
|
139
|
+
list += x
|
140
|
+
end
|
141
|
+
list
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NylasLegacy
|
4
|
+
# Structure to represent the Neural Categorize object.
|
5
|
+
# @see https://developer.nylas.com/docs/intelligence/categorizer/#categorize-message-response
|
6
|
+
class Categorize
|
7
|
+
include Model::Attributable
|
8
|
+
|
9
|
+
attribute :category, :string
|
10
|
+
attribute :categorized_at, :unix_timestamp
|
11
|
+
attribute :model_version, :string
|
12
|
+
has_n_of_attribute :subcategories, :string
|
13
|
+
end
|
14
|
+
end
|