nylas 5.7.0 → 5.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nylas/model.rb CHANGED
@@ -20,8 +20,8 @@ module Nylas
20
20
  model.extend(ClassMethods)
21
21
  model.extend(Forwardable)
22
22
  model.def_delegators :model_class, :creatable?, :filterable?, :listable?, :searchable?, :showable?,
23
- :updatable?, :destroyable?
24
- model.allows_operations
23
+ :updatable?, :destroyable?, :id_listable?, :countable?
24
+ model.init_operations
25
25
  end
26
26
 
27
27
  def save
@@ -39,8 +39,8 @@ module Nylas
39
39
  !id.nil?
40
40
  end
41
41
 
42
- def execute(method:, payload: nil, path:, query: {})
43
- api.execute(method: method, payload: payload, path: path, query: query)
42
+ def execute(method:, payload: nil, path:, query: {}, auth_method: self.auth_method)
43
+ api.execute(method: method, payload: payload, path: path, query: query, auth_method: auth_method)
44
44
  end
45
45
 
46
46
  def create
@@ -107,6 +107,10 @@ module Nylas
107
107
  self.class.resources_path(api: api)
108
108
  end
109
109
 
110
+ def auth_method
111
+ self.class.auth_method(api: api)
112
+ end
113
+
110
114
  def destroy
111
115
  raise ModelNotDestroyableError, self unless destroyable?
112
116
 
@@ -137,19 +141,19 @@ module Nylas
137
141
  # Allows you to narrow in exactly what kind of model you're working with
138
142
  module ClassMethods
139
143
  attr_accessor :raw_mime_type, :creatable, :showable, :filterable, :searchable, :listable, :updatable,
140
- :destroyable
141
- attr_writer :resources_path
142
-
143
- def allows_operations(creatable: false, showable: false, listable: false, filterable: false,
144
- searchable: false, updatable: false, destroyable: false)
145
-
146
- self.creatable ||= creatable
147
- self.showable ||= showable
148
- self.listable ||= listable
149
- self.filterable ||= filterable
150
- self.searchable ||= searchable
151
- self.updatable ||= updatable
152
- self.destroyable ||= destroyable
144
+ :destroyable, :id_listable, :countable
145
+ attr_writer :resources_path, :auth_method
146
+
147
+ def init_operations
148
+ self.creatable = false
149
+ self.showable = false
150
+ self.listable = false
151
+ self.filterable = false
152
+ self.searchable = false
153
+ self.updatable = false
154
+ self.destroyable = false
155
+ self.id_listable = false
156
+ self.countable = false
153
157
  end
154
158
 
155
159
  def creatable?
@@ -180,10 +184,22 @@ module Nylas
180
184
  destroyable
181
185
  end
182
186
 
187
+ def id_listable?
188
+ id_listable
189
+ end
190
+
191
+ def countable?
192
+ countable
193
+ end
194
+
183
195
  def resources_path(*)
184
196
  @resources_path
185
197
  end
186
198
 
199
+ def auth_method(*)
200
+ @auth_method || HttpClient::AuthMethod::BEARER
201
+ end
202
+
187
203
  def exposable_as_raw?
188
204
  !raw_mime_type.nil?
189
205
  end
@@ -6,7 +6,7 @@ module Nylas
6
6
  class NeuralCategorizer < Message
7
7
  include Model
8
8
  self.resources_path = "/neural/categorize"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
 
11
11
  attribute :categorizer, :categorize
12
12
  # Overrides Message's label attribute as currently categorize returns
@@ -6,7 +6,7 @@ module Nylas
6
6
  class NeuralCleanConversation < Message
7
7
  include Model
8
8
  self.resources_path = "/neural/conversation"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
  IMAGE_REGEX = /[(']cid:(.*?)[)']/.freeze
11
11
 
12
12
  attribute :conversation, :string
@@ -6,7 +6,7 @@ module Nylas
6
6
  class NeuralOcr < File
7
7
  include Model
8
8
  self.resources_path = "/neural/ocr"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
 
11
11
  has_n_of_attribute :ocr, :string
12
12
  attribute :processed_pages, :integer
@@ -6,7 +6,7 @@ module Nylas
6
6
  class NeuralSentimentAnalysis
7
7
  include Model
8
8
  self.resources_path = "/neural/sentiment"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
 
11
11
  attribute :account_id, :string
12
12
  attribute :sentiment, :string
@@ -26,8 +26,14 @@ module Nylas
26
26
 
27
27
  attribute :tracking, :message_tracking
28
28
 
29
+ # Sends the new message
30
+ # @return [Message] The sent message
31
+ # @raise [RuntimeError] if the API response data was not a hash
29
32
  def send!
30
- Message.new(**api.execute(method: :post, path: "/send", payload: to_json).merge(api: api))
33
+ message_data = api.execute(method: :post, path: "/send", payload: to_json)
34
+ raise "Unexpected response from the server, data received not a Message" unless message_data.is_a?(Hash)
35
+
36
+ Message.from_hash(message_data, api: api)
31
37
  end
32
38
  end
33
39
  end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Methods for Outbox functionality
5
+ # @see https://developer.nylas.com/docs/api/#tag--Outbox
6
+ class Outbox
7
+ attr_accessor :api
8
+
9
+ def initialize(api:)
10
+ self.api = api
11
+ end
12
+
13
+ def outbox_path
14
+ @outbox_path ||= "/v2/outbox"
15
+ end
16
+
17
+ # rubocop:disable Layout/LineLength
18
+ # Send a message via Outbox
19
+ # @param draft [Draft, OutboxMessage] The message to send
20
+ # @param send_at [Numeric] The date and time to send the message. If not set, Outbox will send this message immediately.
21
+ # @param retry_limit_datetime [Numeric] The date and time to stop retry attempts for a message. If not set, it defaults to 24 hours after send_at.
22
+ # @return [OutboxJobStatus] The outbox job status status and message data
23
+ # rubocop:enable Layout/LineLength
24
+ def send(draft, send_at: nil, retry_limit_datetime: nil)
25
+ message = draft.to_h(enforce_read_only: true)
26
+ message.merge!(validate_set_date_time(send_at, retry_limit_datetime))
27
+ outbox_response = api.execute(
28
+ method: :post,
29
+ path: outbox_path,
30
+ payload: JSON.dump(message)
31
+ )
32
+
33
+ OutboxJobStatus.new(**outbox_response)
34
+ end
35
+
36
+ # rubocop:disable Layout/LineLength
37
+ # Update a scheduled Outbox message
38
+ # @param job_status_id [String] The ID of the outbox job status
39
+ # @param message [Draft, OutboxMessage] The message object with updated values
40
+ # @param send_at [Numeric] The date and time to send the message. If not set, Outbox will send this message immediately.
41
+ # @param retry_limit_datetime [Numeric] The date and time to stop retry attempts for a message. If not set, it defaults to 24 hours after send_at.
42
+ # @return [OutboxJobStatus] The updated outbox job status status and message data
43
+ # rubocop:enable Layout/LineLength
44
+ def update(job_status_id, message: nil, send_at: nil, retry_limit_datetime: nil)
45
+ payload = {}
46
+ payload.merge!(message.to_h(enforce_read_only: true)) if message
47
+ payload.merge!(validate_set_date_time(send_at, retry_limit_datetime))
48
+ outbox_response = api.execute(
49
+ method: :patch,
50
+ path: "#{outbox_path}/#{job_status_id}",
51
+ payload: JSON.dump(payload)
52
+ )
53
+
54
+ OutboxJobStatus.new(**outbox_response)
55
+ end
56
+
57
+ # Delete a scheduled Outbox message
58
+ # @param job_status_id [String] The ID of the outbox job status to delete
59
+ # @return [void]
60
+ def delete(job_status_id)
61
+ api.execute(
62
+ method: :delete,
63
+ path: "#{outbox_path}/#{job_status_id}"
64
+ )
65
+ end
66
+
67
+ # SendGrid - Check Authentication and Verification Status
68
+ # @return [SendGridVerifiedStatus] The SendGrid Authentication and Verification Status
69
+ def send_grid_verification_status
70
+ response = api.execute(
71
+ method: :get,
72
+ path: "#{outbox_path}/onboard/verified_status"
73
+ )
74
+
75
+ raise "Verification status not present in response" if response.key?("results")
76
+
77
+ SendGridVerifiedStatus.new(**response[:results])
78
+ end
79
+
80
+ # SendGrid - Delete SendGrid Subuser and UAS Grant
81
+ # @param email [String] Email address for SendGrid subuser to delete
82
+ # @return [void]
83
+ def delete_send_grid_sub_user(email)
84
+ api.execute(
85
+ method: :delete,
86
+ path: "#{outbox_path}/onboard/subuser",
87
+ payload: JSON.dump({ email: email })
88
+ )
89
+ end
90
+
91
+ private
92
+
93
+ def validate_set_date_time(send_at, retry_limit_datetime)
94
+ hash = {}
95
+ hash[:send_at] = validate_send_at(send_at) if send_at
96
+ if retry_limit_datetime
97
+ hash[:retry_limit_datetime] = validate_retry_limit_datetime(send_at, retry_limit_datetime)
98
+ end
99
+
100
+ hash
101
+ end
102
+
103
+ def validate_send_at(send_at)
104
+ return send_at unless send_at != 0 && (send_at < Time.now.to_i)
105
+
106
+ raise ArgumentError, "Cannot set message to be sent at a time before the current time."
107
+ end
108
+
109
+ def validate_retry_limit_datetime(send_at, retry_limit_datetime)
110
+ valid_send_at = send_at && send_at != 0 ? send_at : Time.now.to_i
111
+ return retry_limit_datetime unless retry_limit_datetime != 0 && (retry_limit_datetime < valid_send_at)
112
+
113
+ raise ArgumentError, "Cannot set message to stop retrying before time to send at."
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Ruby representation of a Nylas Outbox Job Status object
5
+ # @see https://developer.nylas.com/docs/api/#post/v2/outbox
6
+ class OutboxJobStatus < JobStatus
7
+ include Model
8
+
9
+ attribute :send_at, :unix_timestamp
10
+ attribute :original_send_at, :unix_timestamp
11
+ attribute :message_id, :string
12
+ attribute :thread_id, :string
13
+ attribute :original_data, :outbox_message
14
+
15
+ transfer :api, to: %i[original_data]
16
+
17
+ inherit_attributes
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Ruby representation of a Nylas Outbox Message object
5
+ # @see https://developer.nylas.com/docs/api/#post/v2/outbox
6
+ class OutboxMessage < Draft
7
+ include Model
8
+
9
+ attribute :send_at, :unix_timestamp
10
+ attribute :retry_limit_datetime, :unix_timestamp
11
+ attribute :original_send_at, :unix_timestamp, read_only: true
12
+
13
+ transfer :api, to: %i[events files folder labels]
14
+
15
+ inherit_attributes
16
+ end
17
+ end
@@ -6,6 +6,7 @@ module Nylas
6
6
  include Model::Attributable
7
7
  attribute :name, :string
8
8
  attribute :email, :string
9
+ attribute :phone_number, :string
9
10
  attribute :comment, :string
10
11
  attribute :status, :string, read_only: true
11
12
  end
@@ -6,7 +6,7 @@ module Nylas
6
6
  class RoomResource
7
7
  include Model
8
8
  self.resources_path = "/resources"
9
- allows_operations(listable: true)
9
+ self.listable = true
10
10
 
11
11
  attribute :object, :string, read_only: true
12
12
  attribute :email, :string, read_only: true
data/lib/nylas/rsvp.rb CHANGED
@@ -5,7 +5,7 @@ module Nylas
5
5
  # @see https://docs.nylas.com/reference#rsvping-to-invitations
6
6
  class Rsvp
7
7
  include Model
8
- allows_operations(creatable: true)
8
+ self.creatable = true
9
9
 
10
10
  attribute :account_id, :string
11
11
  attribute :event_id, :string
@@ -6,8 +6,12 @@ module Nylas
6
6
  class Scheduler
7
7
  include Model
8
8
  self.resources_path = "/manage/pages"
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
11
15
 
12
16
  attribute :id, :integer, read_only: true
13
17
  attribute :app_client_id, :string
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Ruby representation of a Nylas Send Grid verified status object
5
+ # @see https://docs.nylas.com/reference#drafts
6
+ class SendGridVerifiedStatus
7
+ include Model::Attributable
8
+
9
+ attribute :domain_verified, :boolean
10
+ attribute :sender_verified, :boolean
11
+ end
12
+ end
data/lib/nylas/thread.rb CHANGED
@@ -5,7 +5,12 @@ module Nylas
5
5
  # @see https://docs.nylas.com/reference#threads
6
6
  class Thread
7
7
  include Model
8
- allows_operations(searchable: true, filterable: true, listable: true, updatable: true)
8
+ self.searchable = true
9
+ self.listable = true
10
+ self.filterable = true
11
+ self.updatable = true
12
+ self.id_listable = true
13
+ self.countable = true
9
14
 
10
15
  self.resources_path = "/threads"
11
16
 
@@ -10,5 +10,7 @@ module Nylas
10
10
  attribute :status, :string
11
11
  attribute :start_time, :unix_timestamp
12
12
  attribute :end_time, :unix_timestamp
13
+ attribute :capacity, :time_slot_capacity
14
+ has_n_of_attribute :emails, :string
13
15
  end
14
16
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Capacity values for a timeslot
5
+ # @see https://docs.nylas.com/reference#calendars-free-busy
6
+ class TimeSlotCapacity
7
+ include Model::Attributable
8
+
9
+ attribute :event_id, :string
10
+ attribute :current_capacity, :integer
11
+ attribute :max_capacity, :integer
12
+ end
13
+ end
data/lib/nylas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "5.7.0"
4
+ VERSION = "5.12.1"
5
5
  end
data/lib/nylas/webhook.rb CHANGED
@@ -1,21 +1,98 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module WebhookState
4
+ # Module representing the possible 'state' values in a Webhook
5
+ # @see https://developer.nylas.com/docs/api#post/a/client_id/webhooks
6
+
7
+ ACTIVE = "active"
8
+ INACTIVE = "inactive"
9
+ end
10
+
11
+ module WebhookTrigger
12
+ # Module representing the possible 'trigger' values in a Webhook
13
+ # @see https://developer.nylas.com/docs/api#post/a/client_id/webhooks
14
+
15
+ ACCOUNT_CONNECTED = "account.connected"
16
+ ACCOUNT_RUNNING = "account.running"
17
+ ACCOUNT_STOPPED = "account.stopped"
18
+ ACCOUNT_INVALID = "account.invalid"
19
+ ACCOUNT_SYNC_ERROR = "account.sync_error"
20
+ MESSAGE_CREATED = "message.created"
21
+ MESSAGE_OPENED = "message.opened"
22
+ MESSAGE_LINK_CLICKED = "message.link_created"
23
+ MESSAGE_UPDATED = "message.updated"
24
+ MESSAGE_BOUNCED = "message.bounced"
25
+ THREAD_REPLIED = "thread.replied"
26
+ CONTACT_CREATED = "contact.created"
27
+ CONTACT_UPDATED = "contact.updated"
28
+ CONTACT_DELETED = "contact.deleted"
29
+ CALENDAR_CREATED = "calendar.created"
30
+ CALENDAR_UPDATED = "calendar.updated"
31
+ CALENDAR_DELETED = "calendar.deleted"
32
+ EVENT_CREATED = "event.created"
33
+ EVENT_UPDATED = "event.updated"
34
+ EVENT_DELETED = "event.deleted"
35
+ JOB_SUCCESSFUL = "job.successful"
36
+ JOB_FAILED = "job.failed"
37
+ end
38
+
3
39
  module Nylas
4
40
  # Represents a webhook attached to your application.
5
41
  # @see https://docs.nylas.com/reference#webhooks
6
42
  class Webhook
7
43
  include Model
8
- allows_operations(listable: true, showable: true)
9
- attribute :id, :string
10
- attribute :application_id, :string
44
+ self.creatable = true
45
+ self.listable = true
46
+ self.showable = true
47
+ self.updatable = true
48
+ self.destroyable = true
49
+ self.auth_method = HttpClient::AuthMethod::BASIC
50
+ attribute :id, :string, read_only: true
51
+ attribute :application_id, :string, read_only: true
11
52
 
12
53
  attribute :callback_url, :string
13
54
  attribute :state, :string
14
- attribute :version, :string
55
+ attribute :version, :string, read_only: true
15
56
  has_n_of_attribute :triggers, :string
16
57
 
58
+ STATE = [:inactive].freeze
59
+
60
+ def save
61
+ result = if persisted?
62
+ update_call(update_payload)
63
+ else
64
+ create
65
+ end
66
+
67
+ attributes.merge(result)
68
+ end
69
+
70
+ def save_all_attributes
71
+ save
72
+ end
73
+
74
+ def update(**data)
75
+ raise ArgumentError, "Only 'state' is allowed to be updated" if data.length > 1 || !data.key?(:state)
76
+
77
+ attributes.merge(**data)
78
+ payload = JSON.dump(data)
79
+ update_call(payload)
80
+
81
+ true
82
+ end
83
+
84
+ def update_all_attributes(**data)
85
+ update(**data)
86
+ end
87
+
17
88
  def self.resources_path(api:)
18
89
  "/a/#{api.app_id}/webhooks"
19
90
  end
91
+
92
+ private
93
+
94
+ def update_payload
95
+ JSON.dump({ state: state })
96
+ end
20
97
  end
21
98
  end
data/lib/nylas.rb CHANGED
@@ -29,6 +29,8 @@ require_relative "nylas/registry"
29
29
  require_relative "nylas/types"
30
30
  require_relative "nylas/constraints"
31
31
 
32
+ require_relative "nylas/http_client"
33
+ require_relative "nylas/api"
32
34
  require_relative "nylas/collection"
33
35
  require_relative "nylas/model"
34
36
 
@@ -52,6 +54,7 @@ require_relative "nylas/nylas_date"
52
54
  require_relative "nylas/when"
53
55
  require_relative "nylas/free_busy"
54
56
  require_relative "nylas/time_slot"
57
+ require_relative "nylas/time_slot_capacity"
55
58
  require_relative "nylas/open_hours"
56
59
  require_relative "nylas/event_conferencing"
57
60
  require_relative "nylas/event_conferencing_details"
@@ -67,6 +70,8 @@ require_relative "nylas/free_busy_collection"
67
70
  require_relative "nylas/calendar_collection"
68
71
  require_relative "nylas/component_collection"
69
72
  require_relative "nylas/scheduler_collection"
73
+ require_relative "nylas/job_status_collection"
74
+ require_relative "nylas/outbox"
70
75
 
71
76
  # Models supported by the API
72
77
  require_relative "nylas/account"
@@ -87,6 +92,9 @@ require_relative "nylas/scheduler"
87
92
  require_relative "nylas/job_status"
88
93
  require_relative "nylas/token_info"
89
94
  require_relative "nylas/application_details"
95
+ require_relative "nylas/outbox_message"
96
+ require_relative "nylas/outbox_job_status"
97
+ require_relative "nylas/send_grid_verified_status"
90
98
 
91
99
  # Neural specific types
92
100
  require_relative "nylas/neural"
@@ -107,9 +115,6 @@ require_relative "nylas/scheduler_booking_confirmation"
107
115
 
108
116
  require_relative "nylas/native_authentication"
109
117
 
110
- require_relative "nylas/http_client"
111
- require_relative "nylas/api"
112
-
113
118
  require_relative "nylas/filter_attributes"
114
119
  # an SDK for interacting with the Nylas API
115
120
  # @see https://docs.nylas.com/reference
@@ -140,6 +145,7 @@ module Nylas
140
145
  Types.registry[:contact_group] = Types::ModelType.new(model: ContactGroup)
141
146
  Types.registry[:when] = Types::ModelType.new(model: When)
142
147
  Types.registry[:time_slot] = Types::ModelType.new(model: TimeSlot)
148
+ Types.registry[:time_slot_capacity] = Types::ModelType.new(model: TimeSlotCapacity)
143
149
  Types.registry[:event_conferencing] = Types::ModelType.new(model: EventConferencing)
144
150
  Types.registry[:event_conferencing_details] = Types::ModelType.new(model: EventConferencingDetails)
145
151
  Types.registry[:event_conferencing_autocreate] = Types::ModelType.new(model: EventConferencingAutocreate)
@@ -152,4 +158,5 @@ module Nylas
152
158
  Types.registry[:scheduler_config] = Types::ModelType.new(model: SchedulerConfig)
153
159
  Types.registry[:scheduler_time_slot] = Types::ModelType.new(model: SchedulerTimeSlot)
154
160
  Types.registry[:job_status] = Types::ModelType.new(model: JobStatus)
161
+ Types.registry[:outbox_message] = Types::ModelType.new(model: OutboxMessage)
155
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nylas
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0
4
+ version: 5.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -300,6 +300,7 @@ files:
300
300
  - lib/nylas/http_client.rb
301
301
  - lib/nylas/im_address.rb
302
302
  - lib/nylas/job_status.rb
303
+ - lib/nylas/job_status_collection.rb
303
304
  - lib/nylas/label.rb
304
305
  - lib/nylas/logging.rb
305
306
  - lib/nylas/message.rb
@@ -325,6 +326,9 @@ files:
325
326
  - lib/nylas/new_message.rb
326
327
  - lib/nylas/nylas_date.rb
327
328
  - lib/nylas/open_hours.rb
329
+ - lib/nylas/outbox.rb
330
+ - lib/nylas/outbox_job_status.rb
331
+ - lib/nylas/outbox_message.rb
328
332
  - lib/nylas/participant.rb
329
333
  - lib/nylas/phone_number.rb
330
334
  - lib/nylas/physical_address.rb
@@ -340,8 +344,10 @@ files:
340
344
  - lib/nylas/scheduler_config.rb
341
345
  - lib/nylas/scheduler_time_slot.rb
342
346
  - lib/nylas/search_collection.rb
347
+ - lib/nylas/send_grid_verified_status.rb
343
348
  - lib/nylas/thread.rb
344
349
  - lib/nylas/time_slot.rb
350
+ - lib/nylas/time_slot_capacity.rb
345
351
  - lib/nylas/timespan.rb
346
352
  - lib/nylas/token_info.rb
347
353
  - lib/nylas/types.rb
@@ -374,7 +380,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
374
380
  - !ruby/object:Gem::Version
375
381
  version: '0'
376
382
  requirements: []
377
- rubygems_version: 3.2.17
383
+ rubygems_version: 3.3.7
378
384
  signing_key:
379
385
  specification_version: 4
380
386
  summary: Gem for interacting with the Nylas API