nylas 5.17.0 → 6.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nylas/client.rb +62 -0
  3. data/lib/nylas/config.rb +19 -0
  4. data/lib/nylas/errors.rb +41 -89
  5. data/lib/nylas/handler/admin_api_operations.rb +95 -0
  6. data/lib/nylas/handler/api_operations.rb +138 -0
  7. data/lib/nylas/handler/grants_api_operations.rb +99 -0
  8. data/lib/nylas/handler/http_client.rb +179 -0
  9. data/lib/nylas/resources/applications.rb +27 -0
  10. data/lib/nylas/resources/auth.rb +197 -0
  11. data/lib/nylas/resources/calendars.rb +31 -0
  12. data/lib/nylas/resources/events.rb +20 -0
  13. data/lib/nylas/resources/grants.rb +20 -0
  14. data/lib/nylas/resources/redirect_uris.rb +20 -0
  15. data/lib/nylas/resources/resource.rb +18 -0
  16. data/lib/nylas/resources/webhooks.rb +37 -0
  17. data/lib/nylas/version.rb +1 -1
  18. data/lib/nylas.rb +20 -148
  19. metadata +70 -257
  20. data/lib/nylas/account.rb +0 -56
  21. data/lib/nylas/api.rb +0 -246
  22. data/lib/nylas/application_details.rb +0 -13
  23. data/lib/nylas/calendar.rb +0 -46
  24. data/lib/nylas/calendar_collection.rb +0 -144
  25. data/lib/nylas/categorize.rb +0 -14
  26. data/lib/nylas/collection.rb +0 -175
  27. data/lib/nylas/component.rb +0 -35
  28. data/lib/nylas/component_collection.rb +0 -10
  29. data/lib/nylas/constraints.rb +0 -56
  30. data/lib/nylas/contact.rb +0 -53
  31. data/lib/nylas/contact_group.rb +0 -23
  32. data/lib/nylas/current_account.rb +0 -23
  33. data/lib/nylas/delta.rb +0 -56
  34. data/lib/nylas/deltas.rb +0 -19
  35. data/lib/nylas/deltas_collection.rb +0 -40
  36. data/lib/nylas/draft.rb +0 -100
  37. data/lib/nylas/email_address.rb +0 -12
  38. data/lib/nylas/event.rb +0 -144
  39. data/lib/nylas/event_collection.rb +0 -15
  40. data/lib/nylas/event_conferencing.rb +0 -12
  41. data/lib/nylas/event_conferencing_autocreate.rb +0 -10
  42. data/lib/nylas/event_conferencing_details.rb +0 -14
  43. data/lib/nylas/event_notification.rb +0 -17
  44. data/lib/nylas/file.rb +0 -75
  45. data/lib/nylas/filter_attributes.rb +0 -25
  46. data/lib/nylas/folder.rb +0 -26
  47. data/lib/nylas/free_busy.rb +0 -13
  48. data/lib/nylas/free_busy_collection.rb +0 -48
  49. data/lib/nylas/http_client.rb +0 -279
  50. data/lib/nylas/im_address.rb +0 -11
  51. data/lib/nylas/job_status.rb +0 -27
  52. data/lib/nylas/job_status_collection.rb +0 -21
  53. data/lib/nylas/label.rb +0 -27
  54. data/lib/nylas/logging.rb +0 -41
  55. data/lib/nylas/message.rb +0 -98
  56. data/lib/nylas/message_headers.rb +0 -27
  57. data/lib/nylas/message_tracking.rb +0 -13
  58. data/lib/nylas/model/attributable.rb +0 -89
  59. data/lib/nylas/model/attribute_definition.rb +0 -24
  60. data/lib/nylas/model/attributes.rb +0 -97
  61. data/lib/nylas/model/list_attribute_definition.rb +0 -39
  62. data/lib/nylas/model/transferable.rb +0 -53
  63. data/lib/nylas/model.rb +0 -217
  64. data/lib/nylas/native_authentication.rb +0 -39
  65. data/lib/nylas/neural.rb +0 -87
  66. data/lib/nylas/neural_categorizer.rb +0 -29
  67. data/lib/nylas/neural_clean_conversation.rb +0 -33
  68. data/lib/nylas/neural_contact_link.rb +0 -11
  69. data/lib/nylas/neural_contact_name.rb +0 -11
  70. data/lib/nylas/neural_message_options.rb +0 -35
  71. data/lib/nylas/neural_ocr.rb +0 -16
  72. data/lib/nylas/neural_sentiment_analysis.rb +0 -17
  73. data/lib/nylas/neural_signature_contact.rb +0 -81
  74. data/lib/nylas/neural_signature_extraction.rb +0 -18
  75. data/lib/nylas/new_message.rb +0 -39
  76. data/lib/nylas/nylas_date.rb +0 -25
  77. data/lib/nylas/open_hours.rb +0 -15
  78. data/lib/nylas/outbox.rb +0 -116
  79. data/lib/nylas/outbox_job_status.rb +0 -19
  80. data/lib/nylas/outbox_message.rb +0 -17
  81. data/lib/nylas/participant.rb +0 -13
  82. data/lib/nylas/phone_number.rb +0 -11
  83. data/lib/nylas/physical_address.rb +0 -17
  84. data/lib/nylas/raw_message.rb +0 -25
  85. data/lib/nylas/recurrence.rb +0 -11
  86. data/lib/nylas/registry.rb +0 -42
  87. data/lib/nylas/room_resource.rb +0 -19
  88. data/lib/nylas/rsvp.rb +0 -24
  89. data/lib/nylas/scheduler.rb +0 -51
  90. data/lib/nylas/scheduler_booking_confirmation.rb +0 -24
  91. data/lib/nylas/scheduler_booking_request.rb +0 -17
  92. data/lib/nylas/scheduler_collection.rb +0 -104
  93. data/lib/nylas/scheduler_config.rb +0 -20
  94. data/lib/nylas/scheduler_time_slot.rb +0 -14
  95. data/lib/nylas/search_collection.rb +0 -10
  96. data/lib/nylas/send_grid_verified_status.rb +0 -12
  97. data/lib/nylas/services/tunnel.rb +0 -128
  98. data/lib/nylas/thread.rb +0 -66
  99. data/lib/nylas/time_slot.rb +0 -16
  100. data/lib/nylas/time_slot_capacity.rb +0 -13
  101. data/lib/nylas/timespan.rb +0 -20
  102. data/lib/nylas/token_info.rb +0 -20
  103. data/lib/nylas/types.rb +0 -168
  104. data/lib/nylas/web_page.rb +0 -11
  105. data/lib/nylas/webhook.rb +0 -111
  106. data/lib/nylas/when.rb +0 -75
data/lib/nylas/account.rb DELETED
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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
data/lib/nylas/api.rb DELETED
@@ -1,246 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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 [Nylas::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
- # @param message [Hash, String, #send!]
204
- # @return [Message] The resulting message
205
- def send!(message)
206
- return message.send! if message.respond_to?(:send!)
207
- return NewMessage.new(**message.merge(api: self)).send! if message.respond_to?(:key?)
208
- return RawMessage.new(message, api: self).send! if message.is_a? String
209
- end
210
-
211
- # Allows you to get an API that acts as a different user but otherwise has the same settings
212
- # @param access_token [String] Oauth Access token or app secret used to authenticate with the API
213
- # @return [API]
214
- def as(access_token)
215
- API.new(client: client.as(access_token))
216
- end
217
-
218
- # @return [Collection<Thread>] A queryable collection of Threads
219
- def threads
220
- @threads ||= Collection.new(model: Thread, api: self)
221
- end
222
-
223
- # @return [Collection<Webhook>] A queryable collection of {Webhook}s
224
- def webhooks
225
- @webhooks ||= Collection.new(model: Webhook, api: as(client.app_secret))
226
- end
227
-
228
- # TODO: Move this into calendar collection
229
- def free_busy(emails:, start_time:, end_time:)
230
- FreeBusyCollection.new(
231
- api: self,
232
- emails: emails,
233
- start_time: start_time.to_i,
234
- end_time: end_time.to_i
235
- )
236
- end
237
-
238
- private
239
-
240
- def prevent_calling_if_missing_access_token(method_name)
241
- return if client.access_token && !client.access_token.empty?
242
-
243
- raise NoAuthToken, method_name
244
- end
245
- end
246
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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
@@ -1,144 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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<Nylas::FreeBusy>] A list of free-busy data for users not in your organization
17
- # @param open_hours [Array<Nylas::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<Nylas::FreeBusy>] A list of free-busy data for users not in your organization
59
- # @param open_hours [Array<Nylas::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
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
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
@@ -1,175 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # An enumerable for working with index and search endpoints
5
- class Collection
6
- attr_accessor :model, :api, :constraints
7
-
8
- extend Forwardable
9
- def_delegators :each, :map, :select, :reject, :to_a, :take
10
- def_delegators :to_a, :first, :last, :[]
11
-
12
- def initialize(model:, api:, constraints: nil)
13
- self.constraints = Constraints.from_constraints(constraints)
14
- self.model = model
15
- self.api = api
16
- end
17
-
18
- # Instantiates a new model
19
- def new(**attributes)
20
- model.new(**attributes.merge(api: api))
21
- end
22
-
23
- def create(**attributes)
24
- instance = model.new(**attributes.merge(api: api))
25
- instance.save
26
- instance
27
- end
28
-
29
- # Merges in additional filters when querying the collection
30
- # @return [Collection<Model>]
31
- def where(filters)
32
- raise ModelNotFilterableError, model unless model.filterable?
33
-
34
- self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
35
- end
36
-
37
- def search(query)
38
- raise ModelNotSearchableError, model unless model.searchable?
39
-
40
- SearchCollection.new(model: model, api: api, constraints: constraints.merge(where: { q: query }))
41
- end
42
-
43
- # The collection now returns a string representation of the model in a particular mime type instead of
44
- # Model objects
45
- # @return [Collection<String>]
46
- def raw
47
- raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw?
48
-
49
- self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type))
50
- end
51
-
52
- # @return [Integer]
53
- def count
54
- collection = self.class.new(model: model, api: api, constraints: constraints)
55
-
56
- if model.countable
57
- collection.constraints = collection.constraints.merge(view: "count")
58
- collection.execute[:count]
59
- else
60
- collection.find_each.map.count
61
- end
62
- end
63
-
64
- # @return [Collection<Model>]
65
- def expanded
66
- self.class.new(model: model, api: api, constraints: constraints.merge(view: "expanded"))
67
- end
68
-
69
- # @return [Array<String>]
70
- def ids
71
- collection = self.class.new(model: model, api: api, constraints: constraints)
72
-
73
- if model.id_listable
74
- collection.constraints = collection.constraints.merge(view: "ids")
75
- collection.execute
76
- else
77
- collection.find_each.map(&:id)
78
- end
79
- end
80
-
81
- # Iterates over a single page of results based upon current pagination settings
82
- def each
83
- return enum_for(:each) unless block_given?
84
-
85
- execute.each do |result|
86
- yield(model.new(**result.merge(api: api)))
87
- end
88
- end
89
-
90
- def limit(quantity)
91
- self.class.new(model: model, api: api, constraints: constraints.merge(limit: quantity))
92
- end
93
-
94
- def offset(start)
95
- self.class.new(model: model, api: api, constraints: constraints.merge(offset: start))
96
- end
97
-
98
- # Iterates over every result that meets the filters, retrieving a page at a time
99
- def find_each
100
- return enum_for(:find_each) unless block_given?
101
-
102
- query = self
103
- accumulated = 0
104
-
105
- while query
106
- results = query.each do |instance|
107
- yield(instance)
108
- end
109
-
110
- accumulated += results.length
111
- query = query.next_page(accumulated: accumulated, current_page: results)
112
- end
113
- end
114
-
115
- def next_page(accumulated:, current_page:)
116
- return nil unless more_pages?(accumulated, current_page)
117
-
118
- self.class.new(model: model, api: api, constraints: constraints.next_page)
119
- end
120
-
121
- def more_pages?(accumulated, current_page)
122
- return false if current_page.empty?
123
- return false if constraints.limit && accumulated >= constraints.limit
124
- return false if constraints.per_page && current_page.length < constraints.per_page
125
-
126
- true
127
- end
128
-
129
- # Retrieves a record. Nylas doesn't support where filters on GET so this will not take into
130
- # consideration other query constraints, such as where clauses.
131
- def find(id)
132
- constraints.accept == "application/json" ? find_model(id) : find_raw(id)
133
- end
134
-
135
- def find_raw(id)
136
- api.execute(**to_be_executed.merge(path: "#{resources_path}/#{id}")).to_s
137
- end
138
-
139
- def resources_path
140
- model.resources_path(api: api)
141
- end
142
-
143
- def find_model(id)
144
- response = api.execute(
145
- **to_be_executed.merge(
146
- path: "#{resources_path}/#{id}",
147
- query: view_query
148
- )
149
- )
150
- model.from_hash(response, api: api)
151
- end
152
-
153
- # @return [Hash] Specification for request to be passed to {API#execute}
154
- def to_be_executed
155
- { method: :get, path: resources_path, query: constraints.to_query,
156
- headers: constraints.to_headers, auth_method: model.auth_method }
157
- end
158
-
159
- # Retrieves the data from the API for the particular constraints
160
- # @return [Hash,Array]
161
- def execute
162
- api.execute(**to_be_executed)
163
- end
164
-
165
- private
166
-
167
- def view_query
168
- if constraints.view
169
- { view: constraints.view }
170
- else
171
- {}
172
- end
173
- end
174
- end
175
- end