nylas 5.17.0 → 6.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nylas/client.rb +121 -0
  3. data/lib/nylas/config.rb +19 -0
  4. data/lib/nylas/errors.rb +63 -89
  5. data/lib/nylas/handler/api_operations.rb +162 -0
  6. data/lib/nylas/handler/http_client.rb +252 -0
  7. data/lib/nylas/resources/applications.rb +27 -0
  8. data/lib/nylas/resources/attachments.rb +65 -0
  9. data/lib/nylas/resources/auth.rb +209 -0
  10. data/lib/nylas/resources/calendars.rb +101 -0
  11. data/lib/nylas/resources/connectors.rb +80 -0
  12. data/lib/nylas/resources/contacts.rb +89 -0
  13. data/lib/nylas/resources/credentials.rb +75 -0
  14. data/lib/nylas/resources/drafts.rb +121 -0
  15. data/lib/nylas/resources/events.rb +98 -0
  16. data/lib/nylas/resources/folders.rb +73 -0
  17. data/lib/nylas/resources/grants.rb +59 -0
  18. data/lib/nylas/resources/messages.rb +135 -0
  19. data/lib/nylas/resources/redirect_uris.rb +68 -0
  20. data/lib/nylas/resources/resource.rb +18 -0
  21. data/lib/nylas/resources/smart_compose.rb +36 -0
  22. data/lib/nylas/resources/threads.rb +62 -0
  23. data/lib/nylas/resources/webhooks.rb +121 -0
  24. data/lib/nylas/utils/file_utils.rb +61 -0
  25. data/lib/nylas/version.rb +1 -1
  26. data/lib/nylas.rb +31 -148
  27. metadata +88 -247
  28. data/lib/nylas/account.rb +0 -56
  29. data/lib/nylas/api.rb +0 -246
  30. data/lib/nylas/application_details.rb +0 -13
  31. data/lib/nylas/calendar.rb +0 -46
  32. data/lib/nylas/calendar_collection.rb +0 -144
  33. data/lib/nylas/categorize.rb +0 -14
  34. data/lib/nylas/collection.rb +0 -175
  35. data/lib/nylas/component.rb +0 -35
  36. data/lib/nylas/component_collection.rb +0 -10
  37. data/lib/nylas/constraints.rb +0 -56
  38. data/lib/nylas/contact.rb +0 -53
  39. data/lib/nylas/contact_group.rb +0 -23
  40. data/lib/nylas/current_account.rb +0 -23
  41. data/lib/nylas/delta.rb +0 -56
  42. data/lib/nylas/deltas.rb +0 -19
  43. data/lib/nylas/deltas_collection.rb +0 -40
  44. data/lib/nylas/draft.rb +0 -100
  45. data/lib/nylas/email_address.rb +0 -12
  46. data/lib/nylas/event.rb +0 -144
  47. data/lib/nylas/event_collection.rb +0 -15
  48. data/lib/nylas/event_conferencing.rb +0 -12
  49. data/lib/nylas/event_conferencing_autocreate.rb +0 -10
  50. data/lib/nylas/event_conferencing_details.rb +0 -14
  51. data/lib/nylas/event_notification.rb +0 -17
  52. data/lib/nylas/file.rb +0 -75
  53. data/lib/nylas/filter_attributes.rb +0 -25
  54. data/lib/nylas/folder.rb +0 -26
  55. data/lib/nylas/free_busy.rb +0 -13
  56. data/lib/nylas/free_busy_collection.rb +0 -48
  57. data/lib/nylas/http_client.rb +0 -279
  58. data/lib/nylas/im_address.rb +0 -11
  59. data/lib/nylas/job_status.rb +0 -27
  60. data/lib/nylas/job_status_collection.rb +0 -21
  61. data/lib/nylas/label.rb +0 -27
  62. data/lib/nylas/logging.rb +0 -41
  63. data/lib/nylas/message.rb +0 -98
  64. data/lib/nylas/message_headers.rb +0 -27
  65. data/lib/nylas/message_tracking.rb +0 -13
  66. data/lib/nylas/model/attributable.rb +0 -89
  67. data/lib/nylas/model/attribute_definition.rb +0 -24
  68. data/lib/nylas/model/attributes.rb +0 -97
  69. data/lib/nylas/model/list_attribute_definition.rb +0 -39
  70. data/lib/nylas/model/transferable.rb +0 -53
  71. data/lib/nylas/model.rb +0 -217
  72. data/lib/nylas/native_authentication.rb +0 -39
  73. data/lib/nylas/neural.rb +0 -87
  74. data/lib/nylas/neural_categorizer.rb +0 -29
  75. data/lib/nylas/neural_clean_conversation.rb +0 -33
  76. data/lib/nylas/neural_contact_link.rb +0 -11
  77. data/lib/nylas/neural_contact_name.rb +0 -11
  78. data/lib/nylas/neural_message_options.rb +0 -35
  79. data/lib/nylas/neural_ocr.rb +0 -16
  80. data/lib/nylas/neural_sentiment_analysis.rb +0 -17
  81. data/lib/nylas/neural_signature_contact.rb +0 -81
  82. data/lib/nylas/neural_signature_extraction.rb +0 -18
  83. data/lib/nylas/new_message.rb +0 -39
  84. data/lib/nylas/nylas_date.rb +0 -25
  85. data/lib/nylas/open_hours.rb +0 -15
  86. data/lib/nylas/outbox.rb +0 -116
  87. data/lib/nylas/outbox_job_status.rb +0 -19
  88. data/lib/nylas/outbox_message.rb +0 -17
  89. data/lib/nylas/participant.rb +0 -13
  90. data/lib/nylas/phone_number.rb +0 -11
  91. data/lib/nylas/physical_address.rb +0 -17
  92. data/lib/nylas/raw_message.rb +0 -25
  93. data/lib/nylas/recurrence.rb +0 -11
  94. data/lib/nylas/registry.rb +0 -42
  95. data/lib/nylas/room_resource.rb +0 -19
  96. data/lib/nylas/rsvp.rb +0 -24
  97. data/lib/nylas/scheduler.rb +0 -51
  98. data/lib/nylas/scheduler_booking_confirmation.rb +0 -24
  99. data/lib/nylas/scheduler_booking_request.rb +0 -17
  100. data/lib/nylas/scheduler_collection.rb +0 -104
  101. data/lib/nylas/scheduler_config.rb +0 -20
  102. data/lib/nylas/scheduler_time_slot.rb +0 -14
  103. data/lib/nylas/search_collection.rb +0 -10
  104. data/lib/nylas/send_grid_verified_status.rb +0 -12
  105. data/lib/nylas/services/tunnel.rb +0 -128
  106. data/lib/nylas/thread.rb +0 -66
  107. data/lib/nylas/time_slot.rb +0 -16
  108. data/lib/nylas/time_slot_capacity.rb +0 -13
  109. data/lib/nylas/timespan.rb +0 -20
  110. data/lib/nylas/token_info.rb +0 -20
  111. data/lib/nylas/types.rb +0 -168
  112. data/lib/nylas/web_page.rb +0 -11
  113. data/lib/nylas/webhook.rb +0 -111
  114. data/lib/nylas/when.rb +0 -75
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Methods to check and raise error if extra attributes are present
5
- class FilterAttributes
6
- def initialize(attributes:, allowed_attributes:)
7
- @attributes = attributes
8
- @allowed_attributes = allowed_attributes
9
- end
10
-
11
- def check
12
- return if extra_attributes.empty?
13
-
14
- raise ArgumentError, "Only #{allowed_attributes} are allowed to be sent"
15
- end
16
-
17
- private
18
-
19
- attr_reader :attributes, :allowed_attributes
20
-
21
- def extra_attributes
22
- attributes - allowed_attributes
23
- end
24
- end
25
- end
data/lib/nylas/folder.rb DELETED
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Structure to represent the Folder Schema
5
- # @see https://docs.nylas.com/reference#folders
6
- class Folder
7
- include Model
8
- self.resources_path = "/folders"
9
- self.creatable = true
10
- self.listable = true
11
- self.showable = true
12
- self.filterable = false
13
- self.updatable = true
14
- self.destroyable = true
15
- self.id_listable = true
16
- self.countable = true
17
-
18
- attribute :id, :string, read_only: true
19
- attribute :account_id, :string, read_only: true
20
- attribute :object, :string, read_only: true
21
-
22
- attribute :name, :string
23
- attribute :display_name, :string
24
- attribute :job_status_id, :string, read_only: true
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Query free/busy information for a calendar during a certain time period
5
- # @see https://docs.nylas.com/reference#calendars-free-busy
6
- class FreeBusy
7
- include Model::Attributable
8
-
9
- attribute :email, :string
10
- attribute :object, :string
11
- has_n_of_attribute :time_slots, :time_slot
12
- end
13
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Helper to get and build `FreeBusy` objects
5
- class FreeBusyCollection
6
- extend Forwardable
7
- def_delegators :each, :map, :select, :reject, :to_a, :take
8
- def_delegators :to_a, :first, :last, :[]
9
-
10
- def initialize(emails:, start_time:, end_time:, api:)
11
- @api = api
12
- @emails = emails
13
- @start_time = start_time
14
- @end_time = end_time
15
- end
16
-
17
- def each
18
- return enum_for(:each) unless block_given?
19
-
20
- execute.each do |result|
21
- yield(FreeBusy.new(**result))
22
- end
23
- end
24
-
25
- private
26
-
27
- attr_reader :api, :emails, :start_time, :end_time
28
-
29
- PATH = "/calendars/free-busy"
30
- private_constant :PATH
31
-
32
- def execute
33
- api.execute(
34
- method: :post,
35
- path: PATH,
36
- payload: payload
37
- )
38
- end
39
-
40
- def payload
41
- JSON.dump(
42
- emails: emails,
43
- start_time: start_time,
44
- end_time: end_time
45
- )
46
- end
47
- end
48
- end
@@ -1,279 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- require "yajl"
5
- require "base64"
6
-
7
- # Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
8
- class HttpClient
9
- module AuthMethod
10
- BEARER = 1
11
- BASIC = 2
12
- end
13
-
14
- HTTP_SUCCESS_CODES = [200, 201, 202, 302].freeze
15
-
16
- HTTP_CODE_TO_EXCEPTIONS = {
17
- 400 => InvalidRequest,
18
- 401 => UnauthorizedRequest,
19
- 402 => MessageRejected,
20
- 403 => AccessDenied,
21
- 404 => ResourceNotFound,
22
- 405 => MethodNotAllowed,
23
- 410 => ResourceRemoved,
24
- 418 => TeapotError,
25
- 422 => MailProviderError,
26
- 429 => SendingQuotaExceeded,
27
- 500 => InternalError,
28
- 501 => EndpointNotYetImplemented,
29
- 502 => BadGateway,
30
- 503 => ServiceUnavailable,
31
- 504 => RequestTimedOut
32
- }.freeze
33
-
34
- ENDPOINT_TIMEOUTS = {
35
- "/oauth/authorize" => 345,
36
- "/messages/search" => 350,
37
- "/threads/search" => 350,
38
- "/delta" => 3650,
39
- "/delta/longpoll" => 3650,
40
- "/delta/streaming" => 3650
41
- }.freeze
42
-
43
- SUPPORTED_API_VERSION = "2.5"
44
-
45
- include Logging
46
- attr_accessor :api_server
47
- attr_writer :default_headers
48
- attr_reader :access_token
49
- attr_reader :app_id
50
- attr_reader :app_secret
51
-
52
- # @param app_id [String] Your application id from the Nylas Dashboard
53
- # @param app_secret [String] Your application secret from the Nylas Dashboard
54
- # @param access_token [String] (Optional) Your users access token.
55
- # @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if
56
- # you're using a self-hosted Nylas instance.
57
- # @return [Nylas::HttpClient]
58
- def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api.nylas.com")
59
- unless api_server.include?("://")
60
- raise "When overriding the Nylas API server address, you must include https://"
61
- end
62
-
63
- @api_server = api_server
64
- @access_token = access_token
65
- @app_secret = app_secret
66
- @app_id = app_id
67
- end
68
-
69
- # @return [Nylas::HttpClient[]
70
- def as(access_token)
71
- HttpClient.new(app_id: app_id, access_token: access_token,
72
- app_secret: app_secret, api_server: api_server)
73
- end
74
-
75
- # Sends a request to the Nylas API and rai
76
- # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch
77
- # @param path [String] (Optional, defaults to nil) - Relative path from the API Base. Preferred way to
78
- # execute arbitrary or-not-yet-SDK-ified API commands.
79
- # @param headers [Hash] (Optional, defaults to {}) - Additional HTTP headers to include in the payload.
80
- # @param query [Hash] (Optional, defaults to {}) - Hash of names and values to include in the query
81
- # section of the URI fragment
82
- # @param payload [String,Hash] (Optional, defaults to nil) - Body to send with the request.
83
- # @param auth_method [AuthMethod] (Optional, defaults to BEARER) - The authentication method.
84
- # @return [Array Hash Stringn]
85
- # rubocop:disable Metrics/MethodLength
86
- def execute(method:, path: nil, headers: {}, query: {}, payload: nil, auth_method: nil)
87
- timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
88
- request = build_request(
89
- method: method,
90
- path: path,
91
- headers: headers,
92
- query: query,
93
- payload: payload,
94
- timeout: timeout,
95
- auth_method: auth_method || AuthMethod::BEARER
96
- )
97
- rest_client_execute(**request) do |response, _request, result|
98
- content_type = nil
99
-
100
- if response.headers && response.headers[:content_type]
101
- content_type = response.headers[:content_type].downcase
102
- end
103
-
104
- begin
105
- response = parse_response(response) if content_type == "application/json"
106
- rescue Nylas::JsonParseError
107
- handle_failed_response(result: result, response: response)
108
- raise
109
- end
110
-
111
- handle_failed_response(result: result, response: response)
112
- response
113
- end
114
- end
115
- # rubocop:enable Metrics/MethodLength
116
- inform_on :execute, level: :debug,
117
- also_log: { result: true, values: %i[method url path headers query payload] }
118
-
119
- def build_request(
120
- method:,
121
- path: nil,
122
- headers: {},
123
- query: {},
124
- payload: nil,
125
- timeout: nil,
126
- auth_method: nil
127
- )
128
- url ||= url_for_path(path)
129
- url = add_query_params_to_url(url, query)
130
- resulting_headers = default_headers.merge(headers).merge(auth_header(auth_method))
131
- { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
132
- end
133
-
134
- # Syntactical sugar for making GET requests via the API.
135
- # @see #execute
136
- def get(path: nil, headers: {}, query: {}, auth_method: nil)
137
- execute(method: :get, path: path, query: query, headers: headers, auth_method: auth_method)
138
- end
139
-
140
- # Syntactical sugar for making POST requests via the API.
141
- # @see #execute
142
- def post(path: nil, payload: nil, headers: {}, query: {}, auth_method: nil)
143
- execute(
144
- method: :post,
145
- path: path,
146
- headers: headers,
147
- query: query,
148
- payload: payload,
149
- auth_method: auth_method
150
- )
151
- end
152
-
153
- # Syntactical sugar for making PUT requests via the API.
154
- # @see #execute
155
- def put(path: nil, payload:, headers: {}, query: {}, auth_method: nil)
156
- execute(
157
- method: :put,
158
- path: path,
159
- headers: headers,
160
- query: query,
161
- payload: payload,
162
- auth_method: auth_method
163
- )
164
- end
165
-
166
- # Syntactical sugar for making DELETE requests via the API.
167
- # @see #execute
168
- def delete(path: nil, payload: nil, headers: {}, query: {}, auth_method: nil)
169
- execute(
170
- method: :delete,
171
- path: path,
172
- headers: headers,
173
- query: query,
174
- payload: payload,
175
- auth_method: auth_method
176
- )
177
- end
178
-
179
- def default_headers
180
- @default_headers ||= {
181
- "X-Nylas-API-Wrapper" => "ruby",
182
- "X-Nylas-Client-Id" => @app_id,
183
- "Nylas-API-Version" => SUPPORTED_API_VERSION,
184
- "User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
185
- "Content-type" => "application/json"
186
- }
187
- end
188
-
189
- def parse_response(response)
190
- return response if response.is_a?(Enumerable)
191
-
192
- Yajl::Parser.new(symbolize_names: true).parse(response)
193
- rescue Yajl::ParseError
194
- raise Nylas::JsonParseError
195
- end
196
- inform_on :parse_response, level: :debug, also_log: { result: true }
197
-
198
- def url_for_path(path)
199
- protocol, domain = api_server.split("//")
200
- "#{protocol}//#{access_token}:@#{domain}#{path}"
201
- end
202
-
203
- private
204
-
205
- def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block)
206
- ::RestClient::Request.execute(method: method, url: url, payload: payload,
207
- headers: headers, timeout: timeout, &block)
208
- end
209
-
210
- inform_on :rest_client_execute, level: :debug,
211
- also_log: { result: true, values: %i[method url headers payload] }
212
-
213
- def handle_failed_response(result:, response:)
214
- http_code = result.code.to_i
215
-
216
- handle_anticipated_failure_mode(http_code: http_code, response: response)
217
- raise UnexpectedResponse, result.msg if result.is_a?(Net::HTTPClientError)
218
- end
219
-
220
- def handle_anticipated_failure_mode(http_code:, response:)
221
- return if HTTP_SUCCESS_CODES.include?(http_code)
222
-
223
- exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
224
- case response
225
- when Hash
226
- raise error_hash_to_exception(exception, response)
227
- when RestClient::Response
228
- raise exception.parse_error_response(response)
229
- else
230
- raise exception.new(http_code, response)
231
- end
232
- end
233
-
234
- def error_hash_to_exception(exception, response)
235
- exception.new(
236
- response[:type],
237
- response[:message],
238
- response.fetch(:server_error, nil)
239
- )
240
- end
241
-
242
- def add_query_params_to_url(url, query)
243
- unless query.empty?
244
- uri = URI.parse(url)
245
- query = custom_params(query)
246
- params = URI.decode_www_form(uri.query || "") + query.to_a
247
- uri.query = URI.encode_www_form(params)
248
- url = uri.to_s
249
- end
250
-
251
- url
252
- end
253
-
254
- def custom_params(query)
255
- # Convert hash to "<key>:<value>" form for metadata_pair query
256
- if query.key?(:metadata_pair)
257
- pairs = query[:metadata_pair].map do |key, value|
258
- "#{key}:#{value}"
259
- end
260
- query[:metadata_pair] = pairs
261
- end
262
-
263
- query
264
- end
265
-
266
- def auth_header(auth_method)
267
- authorization_string = case auth_method
268
- when AuthMethod::BEARER
269
- "Bearer #{access_token}"
270
- when AuthMethod::BASIC
271
- "Basic #{Base64.encode64("#{access_token}:")}"
272
- else
273
- "Bearer #{access_token}"
274
- end
275
-
276
- { "Authorization" => authorization_string }
277
- end
278
- end
279
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Structure to represent the IM Address Schema
5
- # @see https://docs.nylas.com/reference#contactsid
6
- class IMAddress
7
- include Model::Attributable
8
- attribute :type, :string
9
- attribute :im_address, :string
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Ruby representation of a Nylas Job Status object
5
- # @see https://developer.nylas.com/docs/api/#tag--Job-Status
6
- class JobStatus
7
- include Model
8
- self.resources_path = "/job-statuses"
9
- self.listable = true
10
-
11
- attribute :id, :string, read_only: true
12
- attribute :account_id, :string, read_only: true
13
- attribute :job_status_id, :string, read_only: true
14
- attribute :action, :string, read_only: true
15
- attribute :object, :string, read_only: true
16
- attribute :status, :string, read_only: true
17
- attribute :created_at, :unix_timestamp, read_only: true
18
- attribute :reason, :string, read_only: true
19
- attribute :metadata, :hash, read_only: true
20
-
21
- # Returns the status of a job as a boolean
22
- # @return [Boolean] If the job was successful
23
- def successful?
24
- status == "successful"
25
- end
26
- end
27
- end
@@ -1,21 +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 JobStatusCollection < Collection
7
- def find_model(id)
8
- response = api.execute(
9
- **to_be_executed.merge(
10
- path: "#{resources_path}/#{id}",
11
- query: view_query
12
- )
13
- )
14
-
15
- object_type = response[:object]
16
- return OutboxJobStatus.from_hash(response, api: api) if object_type == "message"
17
-
18
- model.from_hash(response, api: api)
19
- end
20
- end
21
- end
data/lib/nylas/label.rb DELETED
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Structure to represent the Label Schema
5
- # @see https://docs.nylas.com/reference#labels
6
- class Label
7
- include Model
8
- self.resources_path = "/labels"
9
- self.creatable = true
10
- self.listable = true
11
- self.showable = true
12
- self.filterable = false
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
- attribute :object, :string
21
-
22
- attribute :name, :string
23
- attribute :display_name, :string
24
- attribute :provider_id, :string
25
- attribute :job_status_id, :string, read_only: true
26
- end
27
- end
data/lib/nylas/logging.rb DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "informed"
5
- rescue LoadError
6
- end
7
-
8
- module Nylas
9
- # Exposes a shared logger for debugging purposes
10
- module Logging
11
- def self.included(object)
12
- if const_defined? :Informed
13
- object.include Informed
14
- Informed.logger = logger
15
- else
16
- object.extend NoOpInformOn
17
- end
18
- end
19
-
20
- def self.logger
21
- return @logger if @logger
22
-
23
- @logger = Logger.new(STDOUT)
24
- @logger.level = level
25
- @logger
26
- end
27
-
28
- def self.level
29
- Logger.const_get(ENV["NYLAS_LOG_LEVEL"] || :WARN)
30
- end
31
-
32
- def self.logger=(logger)
33
- @logger = logger
34
- end
35
-
36
- # No op for inform_on if user does not have the informed gem installed.
37
- module NoOpInformOn
38
- def inform_on(method, level: :debug, also_log: {}); end
39
- end
40
- end
41
- end
data/lib/nylas/message.rb DELETED
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Ruby representatin of a Nylas Message object
5
- # @see https://docs.nylas.com/reference#messages
6
- class Message
7
- include Model
8
- self.raw_mime_type = "message/rfc822"
9
- self.resources_path = "/messages"
10
- self.listable = true
11
- self.showable = true
12
- self.filterable = true
13
- self.updatable = true
14
- self.searchable = true
15
- self.id_listable = true
16
- self.countable = true
17
- UPDATABLE_ATTRIBUTES = %i[label_ids folder_id starred unread metadata].freeze
18
-
19
- attribute :id, :string
20
- attribute :object, :string
21
- attribute :account_id, :string
22
- attribute :thread_id, :string
23
-
24
- attribute :headers, :message_headers
25
-
26
- has_n_of_attribute :to, :email_address
27
- has_n_of_attribute :from, :email_address
28
- has_n_of_attribute :cc, :email_address
29
- has_n_of_attribute :bcc, :email_address
30
- has_n_of_attribute :reply_to, :email_address
31
-
32
- attribute :date, :unix_timestamp
33
- # This is only used when receiving a message received notification via a webhook
34
- attribute :received_date, :unix_timestamp
35
- attribute :subject, :string
36
- attribute :snippet, :string
37
- attribute :body, :string
38
- attribute :starred, :boolean
39
- attribute :unread, :boolean
40
-
41
- has_n_of_attribute :events, :event
42
- has_n_of_attribute :files, :file
43
- attribute :folder, :folder
44
- attribute :folder_id, :string
45
- attribute :metadata, :hash
46
- attribute :reply_to_message_id, :string, read_only: true
47
- attribute :job_status_id, :string, read_only: true
48
-
49
- has_n_of_attribute :labels, :label, read_only: true
50
- has_n_of_attribute :label_ids, :string
51
-
52
- transfer :api, to: %i[events files folder labels]
53
-
54
- def starred?
55
- starred
56
- end
57
-
58
- def unread?
59
- unread
60
- end
61
-
62
- def update(payload)
63
- FilterAttributes.new(
64
- attributes: payload.keys,
65
- allowed_attributes: UPDATABLE_ATTRIBUTES
66
- ).check
67
-
68
- super(**payload)
69
- end
70
-
71
- def update_folder(folder_id)
72
- update(folder_id: folder_id)
73
- end
74
-
75
- def expanded
76
- return self unless headers.nil?
77
-
78
- assign(**api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
79
- # Transfer reference to the API to attributes that need it
80
- transfer_attributes
81
- self
82
- end
83
-
84
- def save
85
- handle_folder
86
-
87
- super
88
- end
89
-
90
- def handle_folder
91
- return if folder.nil?
92
-
93
- self.folder_id = folder.id if folder_id.nil? && !self.to_h.dig(:folder, :id).nil?
94
-
95
- self.folder = nil
96
- end
97
- end
98
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Translates message headers into a Ruby object
5
- # @see https://docs.nylas.com/reference#section-message-views
6
- class MessageHeaders
7
- include Model::Attributable
8
- attribute :in_reply_to, :string
9
- attribute :message_id, :string
10
- has_n_of_attribute :references, :string
11
- end
12
-
13
- # Serializes, Deserializes between {MessageHeaders} objects and a Hash
14
- class MessageHeadersType < Types::ModelType
15
- def initialize
16
- super(model: MessageHeaders)
17
- end
18
- RUBY_KEY_TO_JSON_KEY_MAP = {
19
- in_reply_to: :"In-Reply-To",
20
- message_id: :"Message-Id",
21
- references: :References
22
- }.freeze
23
- def json_key_from_attribute_name(attribute_name)
24
- RUBY_KEY_TO_JSON_KEY_MAP.fetch(attribute_name)
25
- end
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nylas
4
- # Message tracking features
5
- # @see https://docs.nylas.com/reference#message-tracking-overview
6
- class MessageTracking
7
- include Model::Attributable
8
- attribute :links, :boolean
9
- attribute :opens, :boolean
10
- attribute :thread_replies, :boolean
11
- attribute :payload, :string
12
- end
13
- end