nylas 5.7.0 → 5.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d8d9639941076724b3e9ae95b85a2e4a48c8f663a35b03f5f26473c5c87b208
4
- data.tar.gz: 4b2733e86538a6dd7ac3069dc5738997ea8db1b7be13b1a8de9bef5c868ec1d5
3
+ metadata.gz: c1e352b09e650aa0cbc5dff7363b8a0997aab35c94e73a5f4a77b5503de70448
4
+ data.tar.gz: a7830ea4cc6a9028669ca6c0e502cba4f2dfc70402a2c00f85cd1f6d315d0594
5
5
  SHA512:
6
- metadata.gz: 56b9216d9e5f37a0c449d999891a76a06e1ed8dd8925efe5186d8d59d16105da76ea3b8a5599d88a9e8e83bd2862bc71cc7491957ac8c8da8718a825af2a2a2a
7
- data.tar.gz: 5fa04ae09e9692f0c954926ae8e7d541388597a12a154dd8bf82b78c40e91b7b9b73508c5d39b6a2c604ed5d53f5eec86379687dc9b79da81b4a8571d0500460
6
+ metadata.gz: 7aeed921859461105491d8394f845b79d6419ecc10a17ae0989f2239382cce8e4ad1fb3936bd7a4cebd730e40bac60b28dafe8e145e63a10d424a9e9b46915f0
7
+ data.tar.gz: 47fdeaa77f5e1037934fc421b7b869edc031f956aad054d2888d29aee0a75ecb537c063e4c89e3c30e4f14f2be2da0860b5ec546e39034590f137773b73ef3cc
data/lib/nylas/account.rb CHANGED
@@ -9,12 +9,15 @@ module Nylas
9
9
  self.showable = true
10
10
  self.updatable = true
11
11
  self.destroyable = true
12
+ self.filterable = true
13
+ self.auth_method = HttpClient::AuthMethod::BASIC
12
14
 
13
15
  attribute :id, :string, read_only: true
14
16
  attribute :account_id, :string, read_only: true
15
17
  attribute :billing_state, :string, read_only: true
16
18
  attribute :sync_state, :string, read_only: true
17
19
  attribute :provider, :string, read_only: true
20
+ attribute :authentication_type, :string, read_only: true
18
21
 
19
22
  attribute :email, :string, read_only: true
20
23
  attribute :trial, :boolean, read_only: true
data/lib/nylas/api.rb CHANGED
@@ -35,15 +35,19 @@ module Nylas
35
35
  )
36
36
  end
37
37
 
38
- def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil)
38
+ def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil,
39
+ provider: nil, redirect_on_error: nil)
39
40
  params = {
40
41
  client_id: app_id,
41
42
  redirect_uri: redirect_uri,
42
43
  response_type: response_type,
43
44
  login_hint: login_hint
44
45
  }
46
+
45
47
  params[:state] = state if state
46
48
  params[:scopes] = scopes.join(",") if scopes
49
+ params[:provider] = provider if provider
50
+ params[:redirect_on_error] = redirect_on_error if redirect_on_error
47
51
 
48
52
  "#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
49
53
  end
@@ -132,7 +136,12 @@ module Nylas
132
136
 
133
137
  # @return[Collection<JobStatus>] A queryable collection of {JobStatus} objects
134
138
  def job_statuses
135
- @job_statuses ||= Collection.new(model: JobStatus, api: self)
139
+ @job_statuses ||= JobStatusCollection.new(model: JobStatus, api: self)
140
+ end
141
+
142
+ # @return[OutboxCollection] A collection of Outbox operations
143
+ def outbox
144
+ @outbox ||= Outbox.new(api: self)
136
145
  end
137
146
 
138
147
  # @return[SchedulerCollection<Scheduler>] A queryable collection of {Scheduler} objects
@@ -143,7 +152,7 @@ module Nylas
143
152
  @scheduler ||= SchedulerCollection.new(model: Scheduler, api: scheduler_api)
144
153
  end
145
154
 
146
- # @return[Neural] A {Neural} object that provides
155
+ # @return[Neural] A collection of Neural operations
147
156
  def neural
148
157
  @neural ||= Neural.new(api: self)
149
158
  end
@@ -163,7 +172,11 @@ module Nylas
163
172
  # Returns the application details
164
173
  # @return [ApplicationDetail] The application details
165
174
  def application_details
166
- response = client.as(client.app_secret).execute(method: :get, path: "/a/#{app_id}")
175
+ response = client.as(client.app_secret).execute(
176
+ method: :get,
177
+ path: "/a/#{app_id}",
178
+ auth_method: HttpClient::AuthMethod::BASIC
179
+ )
167
180
  ApplicationDetail.new(**response)
168
181
  end
169
182
 
@@ -174,7 +187,8 @@ module Nylas
174
187
  response = client.as(client.app_secret).execute(
175
188
  method: :put,
176
189
  path: "/a/#{app_id}",
177
- payload: JSON.dump(application_details.to_h)
190
+ payload: JSON.dump(application_details.to_h),
191
+ auth_method: HttpClient::AuthMethod::BASIC
178
192
  )
179
193
  ApplicationDetail.new(**response)
180
194
  end
@@ -184,7 +198,7 @@ module Nylas
184
198
  # hash has keys of :updated_at (unix timestamp) and :ip_addresses (array of strings)
185
199
  def ip_addresses
186
200
  path = "/a/#{app_id}/ip_addresses"
187
- client.as(client.app_secret).get(path: path)
201
+ client.as(client.app_secret).get(path: path, auth_method: HttpClient::AuthMethod::BASIC)
188
202
  end
189
203
 
190
204
  # @param message [Hash, String, #send!]
@@ -6,8 +6,14 @@ module Nylas
6
6
  class Calendar
7
7
  include Model
8
8
  self.resources_path = "/calendars"
9
- allows_operations(creatable: true, listable: true, filterable: true, showable: true, updatable: true,
10
- destroyable: true)
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
11
17
 
12
18
  attribute :id, :string
13
19
  attribute :account_id, :string
@@ -4,48 +4,86 @@ module Nylas
4
4
  # Additional methods for some of Calendar's other functionality
5
5
  # @see https://developer.nylas.com/docs/connectivity/calendar
6
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
7
20
  def availability(duration_minutes:,
8
- interval:,
21
+ interval_minutes:,
9
22
  start_time:,
10
23
  end_time:,
11
- emails:,
24
+ emails: [],
12
25
  buffer: nil,
13
26
  round_robin: nil,
27
+ event_collection_id: nil,
14
28
  free_busy: [],
15
- open_hours: [])
29
+ open_hours: [],
30
+ calendars: [])
31
+ validate_calendars_or_emails(calendars, emails)
16
32
  validate_open_hours(emails, free_busy, open_hours) unless open_hours.empty?
17
33
 
18
- execute_availability("/calendars/availability",
19
- duration_minutes: duration_minutes,
20
- interval: interval,
21
- start_time: start_time,
22
- end_time: end_time,
23
- emails: emails,
24
- buffer: buffer,
25
- round_robin: round_robin,
26
- free_busy: free_busy,
27
- open_hours: open_hours)
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)
28
49
  end
29
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
30
62
  def consecutive_availability(duration_minutes:,
31
- interval:,
63
+ interval_minutes:,
32
64
  start_time:,
33
65
  end_time:,
34
- emails:,
66
+ emails: [],
35
67
  buffer: nil,
36
68
  free_busy: [],
37
- open_hours: [])
69
+ open_hours: [],
70
+ calendars: [])
71
+ validate_calendars_or_emails(emails, calendars)
38
72
  validate_open_hours(emails, free_busy, open_hours) unless open_hours.empty?
39
73
 
40
- execute_availability("/calendars/availability/consecutive",
41
- duration_minutes: duration_minutes,
42
- interval: interval,
43
- start_time: start_time,
44
- end_time: end_time,
45
- emails: emails,
46
- buffer: buffer,
47
- free_busy: free_busy,
48
- open_hours: open_hours)
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)
49
87
  end
50
88
 
51
89
  private
@@ -58,6 +96,12 @@ module Nylas
58
96
  )
59
97
  end
60
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
+
61
105
  def validate_open_hours(emails, free_busy, open_hours)
62
106
  raise TypeError, "open_hours' must be an array." unless open_hours.is_a?(Array)
63
107
 
@@ -17,7 +17,7 @@ module Nylas
17
17
 
18
18
  # Instantiates a new model
19
19
  def new(**attributes)
20
- model.new(attributes.merge(api: api))
20
+ model.new(**attributes.merge(api: api))
21
21
  end
22
22
 
23
23
  def create(**attributes)
@@ -51,7 +51,14 @@ module Nylas
51
51
 
52
52
  # @return [Integer]
53
53
  def count
54
- self.class.new(model: model, api: api, constraints: constraints.merge(view: "count")).execute[: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
55
62
  end
56
63
 
57
64
  # @return [Collection<Model>]
@@ -61,7 +68,14 @@ module Nylas
61
68
 
62
69
  # @return [Array<String>]
63
70
  def ids
64
- self.class.new(model: model, api: api, constraints: constraints.merge(view: "ids")).execute
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
65
79
  end
66
80
 
67
81
  # Iterates over a single page of results based upon current pagination settings
@@ -139,7 +153,7 @@ module Nylas
139
153
  # @return [Hash] Specification for request to be passed to {API#execute}
140
154
  def to_be_executed
141
155
  { method: :get, path: resources_path, query: constraints.to_query,
142
- headers: constraints.to_headers }
156
+ headers: constraints.to_headers, auth_method: model.auth_method }
143
157
  end
144
158
 
145
159
  # Retrieves the data from the API for the particular constraints
@@ -4,8 +4,13 @@ module Nylas
4
4
  # Structure to represent a the Component Schema.
5
5
  class Component
6
6
  include Model
7
- allows_operations(creatable: true, listable: true, filterable: true, showable: true, updatable: true,
8
- destroyable: true)
7
+ self.creatable = true
8
+ self.listable = true
9
+ self.showable = true
10
+ self.filterable = true
11
+ self.updatable = true
12
+ self.destroyable = true
13
+ self.auth_method = HttpClient::AuthMethod::BASIC
9
14
 
10
15
  attribute :id, :string, read_only: true
11
16
  attribute :account_id, :string
data/lib/nylas/deltas.rb CHANGED
@@ -8,7 +8,7 @@ module Nylas
8
8
  class Deltas
9
9
  include Model
10
10
  self.resources_path = "/delta"
11
- allows_operations(filterable: true)
11
+ self.filterable = true
12
12
  has_n_of_attribute :deltas, :delta
13
13
  attribute :cursor_start, :string
14
14
  attribute :cursor_end, :string
data/lib/nylas/draft.rb CHANGED
@@ -6,7 +6,13 @@ module Nylas
6
6
  class Draft
7
7
  include Model
8
8
  self.resources_path = "/drafts"
9
- allows_operations(creatable: true, showable: true, listable: true, updatable: true, destroyable: true)
9
+ self.creatable = true
10
+ self.listable = true
11
+ self.showable = true
12
+ self.updatable = true
13
+ self.destroyable = true
14
+ self.id_listable = true
15
+ self.countable = true
10
16
 
11
17
  attribute :id, :string
12
18
  attribute :object, :string
data/lib/nylas/event.rb CHANGED
@@ -6,8 +6,14 @@ module Nylas
6
6
  class Event
7
7
  include Model
8
8
  self.resources_path = "/events"
9
- allows_operations(creatable: true, listable: true, filterable: true, showable: true, updatable: true,
10
- destroyable: true)
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
11
17
 
12
18
  attribute :id, :string, read_only: true
13
19
  attribute :object, :string, read_only: true
@@ -16,7 +22,9 @@ module Nylas
16
22
  attribute :master_event_id, :string
17
23
  attribute :message_id, :string
18
24
  attribute :ical_uid, :string
25
+ attribute :event_collection_id, :string
19
26
 
27
+ attribute :capacity, :integer
20
28
  attribute :busy, :boolean
21
29
  attribute :description, :string
22
30
  attribute :location, :string
@@ -30,7 +38,10 @@ module Nylas
30
38
  attribute :metadata, :hash
31
39
  attribute :conferencing, :event_conferencing
32
40
  has_n_of_attribute :notifications, :event_notification
41
+ has_n_of_attribute :round_robin_order, :string
33
42
  attribute :original_start_time, :unix_timestamp
43
+ attribute :reminder_minutes, :string
44
+ attribute :reminder_method, :string
34
45
  attribute :job_status_id, :string, read_only: true
35
46
 
36
47
  attr_accessor :notify_participants
@@ -44,12 +55,8 @@ module Nylas
44
55
  end
45
56
 
46
57
  def save
47
- if conferencing
48
- body = to_h
49
- if body.dig(:conferencing, :details) && body.dig(:conferencing, :autocreate)
50
- raise ArgumentError, "Cannot set both 'details' and 'autocreate' in conferencing object."
51
- end
52
- end
58
+ validate
59
+ format_reminder_minutes
53
60
 
54
61
  super
55
62
  end
@@ -81,6 +88,18 @@ module Nylas
81
88
 
82
89
  private
83
90
 
91
+ def validate
92
+ if conferencing
93
+ body = to_h
94
+ if body.dig(:conferencing, :details) && body.dig(:conferencing, :autocreate)
95
+ raise ArgumentError, "Cannot set both 'details' and 'autocreate' in conferencing object."
96
+ end
97
+ end
98
+ return unless capacity && capacity != -1 && participants && participants.length > capacity
99
+
100
+ raise ArgumentError, "The number of participants in the event exceeds the set capacity."
101
+ end
102
+
84
103
  def build_ics_event_payload(ical_uid, method, prodid)
85
104
  payload = {}
86
105
  if id
@@ -101,6 +120,13 @@ module Nylas
101
120
  payload
102
121
  end
103
122
 
123
+ # Formats the reminder minute field to match the API format: "[%d]"
124
+ def format_reminder_minutes
125
+ return if reminder_minutes.nil? || reminder_minutes.empty? || reminder_minutes.match(/\[\d+\]/)
126
+
127
+ self.reminder_minutes = "[#{reminder_minutes}]"
128
+ end
129
+
104
130
  def query_params
105
131
  if notify_participants.nil?
106
132
  {}
data/lib/nylas/file.rb CHANGED
@@ -6,7 +6,13 @@ module Nylas
6
6
  class File
7
7
  include Model
8
8
  self.resources_path = "/files"
9
- allows_operations(listable: true, showable: true, filterable: true, creatable: true, destroyable: true)
9
+ self.creatable = true
10
+ self.listable = true
11
+ self.showable = true
12
+ self.filterable = true
13
+ self.destroyable = true
14
+ self.id_listable = true
15
+ self.countable = true
10
16
 
11
17
  attribute :id, :string
12
18
  attribute :account_id, :string
data/lib/nylas/folder.rb CHANGED
@@ -12,6 +12,8 @@ module Nylas
12
12
  self.filterable = false
13
13
  self.updatable = true
14
14
  self.destroyable = true
15
+ self.id_listable = true
16
+ self.countable = true
15
17
 
16
18
  attribute :id, :string, read_only: true
17
19
  attribute :account_id, :string, read_only: true
@@ -2,10 +2,16 @@
2
2
 
3
3
  module Nylas
4
4
  require "yajl"
5
+ require "base64"
5
6
 
6
7
  # Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
7
- class HttpClient # rubocop:disable Metrics/ClassLength
8
- HTTP_SUCCESS_CODES = [200, 201, 302].freeze
8
+ class HttpClient
9
+ module AuthMethod
10
+ BEARER = 1
11
+ BASIC = 2
12
+ end
13
+
14
+ HTTP_SUCCESS_CODES = [200, 201, 202, 302].freeze
9
15
 
10
16
  HTTP_CODE_TO_EXCEPTIONS = {
11
17
  400 => InvalidRequest,
@@ -33,7 +39,8 @@ module Nylas
33
39
  "/delta/longpoll" => 3650,
34
40
  "/delta/streaming" => 3650
35
41
  }.freeze
36
- SUPPORTED_API_VERSION = "2.2"
42
+
43
+ SUPPORTED_API_VERSION = "2.5"
37
44
 
38
45
  include Logging
39
46
  attr_accessor :api_server
@@ -73,9 +80,10 @@ module Nylas
73
80
  # @param query [Hash] (Optional, defaults to {}) - Hash of names and values to include in the query
74
81
  # section of the URI fragment
75
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.
76
84
  # @return [Array Hash Stringn]
77
85
  # rubocop:disable Metrics/MethodLength
78
- def execute(method:, path: nil, headers: {}, query: {}, payload: nil)
86
+ def execute(method:, path: nil, headers: {}, query: {}, payload: nil, auth_method: nil)
79
87
  timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
80
88
  request = build_request(
81
89
  method: method,
@@ -83,7 +91,8 @@ module Nylas
83
91
  headers: headers,
84
92
  query: query,
85
93
  payload: payload,
86
- timeout: timeout
94
+ timeout: timeout,
95
+ auth_method: auth_method || AuthMethod::BEARER
87
96
  )
88
97
  rest_client_execute(**request) do |response, _request, result|
89
98
  content_type = nil
@@ -107,35 +116,64 @@ module Nylas
107
116
  inform_on :execute, level: :debug,
108
117
  also_log: { result: true, values: %i[method url path headers query payload] }
109
118
 
110
- def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil)
119
+ def build_request(
120
+ method:,
121
+ path: nil,
122
+ headers: {},
123
+ query: {},
124
+ payload: nil,
125
+ timeout: nil,
126
+ auth_method: nil
127
+ )
111
128
  url ||= url_for_path(path)
112
129
  url = add_query_params_to_url(url, query)
113
- resulting_headers = default_headers.merge(headers)
130
+ resulting_headers = default_headers.merge(headers).merge(auth_header(auth_method))
114
131
  { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
115
132
  end
116
133
 
117
134
  # Syntactical sugar for making GET requests via the API.
118
135
  # @see #execute
119
- def get(path: nil, headers: {}, query: {})
120
- execute(method: :get, path: path, query: query, headers: headers)
136
+ def get(path: nil, headers: {}, query: {}, auth_method: nil)
137
+ execute(method: :get, path: path, query: query, headers: headers, auth_method: auth_method)
121
138
  end
122
139
 
123
140
  # Syntactical sugar for making POST requests via the API.
124
141
  # @see #execute
125
- def post(path: nil, payload: nil, headers: {}, query: {})
126
- execute(method: :post, path: path, headers: headers, query: query, payload: payload)
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
+ )
127
151
  end
128
152
 
129
153
  # Syntactical sugar for making PUT requests via the API.
130
154
  # @see #execute
131
- def put(path: nil, payload:, headers: {}, query: {})
132
- execute(method: :put, path: path, headers: headers, query: query, payload: payload)
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
+ )
133
164
  end
134
165
 
135
166
  # Syntactical sugar for making DELETE requests via the API.
136
167
  # @see #execute
137
- def delete(path: nil, payload: nil, headers: {}, query: {})
138
- execute(method: :delete, path: path, headers: headers, query: query, payload: payload)
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
+ )
139
177
  end
140
178
 
141
179
  def default_headers
@@ -216,5 +254,18 @@ module Nylas
216
254
 
217
255
  query
218
256
  end
257
+
258
+ def auth_header(auth_method)
259
+ authorization_string = case auth_method
260
+ when AuthMethod::BEARER
261
+ "Bearer #{access_token}"
262
+ when AuthMethod::BASIC
263
+ "Basic #{Base64.encode64("#{access_token}:")}"
264
+ else
265
+ "Bearer #{access_token}"
266
+ end
267
+
268
+ { "Authorization" => authorization_string }
269
+ end
219
270
  end
220
271
  end
@@ -6,7 +6,7 @@ module Nylas
6
6
  class JobStatus
7
7
  include Model
8
8
  self.resources_path = "/job-statuses"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
 
11
11
  attribute :id, :string, read_only: true
12
12
  attribute :account_id, :string, read_only: true
@@ -15,7 +15,8 @@ module Nylas
15
15
  attribute :object, :string, read_only: true
16
16
  attribute :status, :string, read_only: true
17
17
  attribute :created_at, :unix_timestamp, read_only: true
18
- attribute :original_data, :message, read_only: true
18
+ attribute :reason, :string, read_only: true
19
+ attribute :metadata, :hash, read_only: true
19
20
 
20
21
  # Returns the status of a job as a boolean
21
22
  # @return [Boolean] If the job was successful
@@ -0,0 +1,21 @@
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 CHANGED
@@ -12,6 +12,8 @@ module Nylas
12
12
  self.filterable = false
13
13
  self.updatable = true
14
14
  self.destroyable = true
15
+ self.id_listable = true
16
+ self.countable = true
15
17
 
16
18
  attribute :id, :string
17
19
  attribute :account_id, :string
data/lib/nylas/message.rb CHANGED
@@ -7,7 +7,13 @@ module Nylas
7
7
  include Model
8
8
  self.raw_mime_type = "message/rfc822"
9
9
  self.resources_path = "/messages"
10
- allows_operations(showable: true, listable: true, filterable: true, searchable: true, updatable: true)
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
11
17
  UPDATABLE_ATTRIBUTES = %i[label_ids folder_id starred unread metadata].freeze
12
18
 
13
19
  attribute :id, :string
@@ -37,6 +43,7 @@ module Nylas
37
43
  attribute :folder, :folder
38
44
  attribute :folder_id, :string
39
45
  attribute :metadata, :hash
46
+ attribute :reply_to_message_id, :string, read_only: true
40
47
  attribute :job_status_id, :string, read_only: true
41
48
 
42
49
  has_n_of_attribute :labels, :label, read_only: true