nylas 4.6.6 → 5.2.0

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: baebc1d39fd0bc001c952f302dd417ac00399e139f90b6954080479c659d45ca
4
- data.tar.gz: 554cf1807cb4432d1e7b75722c7da6846db751369085583adc08e09b0e1eaa9b
3
+ metadata.gz: c6b0265bb93198dcc5494a819c68a5261703a143a4fe320a4662cc6c65aa2e94
4
+ data.tar.gz: ee107c7cacfb2b7e2b099fd675c20c02700def063e1ccdd6b46923448da9e25b
5
5
  SHA512:
6
- metadata.gz: 7e388d554f86e260cba3950dcd2e4ec559009af1e285c0cbc90c9b8111bed522016292dbf6e907b2a0da89dfedf98bd99d7bc67bab552c3368681b4c0224dc76
7
- data.tar.gz: 947425b241a41b35904eba088d71c2ad6bbb2e0221eb36ba01ff215274e42e852db66c587e047076ab3a81e06d86fac0a98e327b799881097ba7a502ea9b939c
6
+ metadata.gz: 4e7aca3de25b0e2847011c4b190960405a214e8905429ba2743f9d3bd068d41e60cb36ad7365d298f685eb47979c30df0397996212d784c26e20e54f32b874aa
7
+ data.tar.gz: 8fc30003aa6609694e5f2a7aedf2c949e2f191c45a0edea6045669d918c3ff88cdfc837046ec409815f67c255b7a1184586532878988166cd39865c8517f00fe
data/lib/nylas.rb CHANGED
@@ -51,10 +51,13 @@ require_relative "nylas/timespan"
51
51
  require_relative "nylas/web_page"
52
52
  require_relative "nylas/nylas_date"
53
53
  require_relative "nylas/when"
54
+ require_relative "nylas/free_busy"
55
+ require_relative "nylas/time_slot"
54
56
 
55
57
  # Custom collection types
56
58
  require_relative "nylas/search_collection"
57
59
  require_relative "nylas/deltas_collection"
60
+ require_relative "nylas/free_busy_collection"
58
61
 
59
62
  # Models supported by the API
60
63
  require_relative "nylas/account"
@@ -66,6 +69,7 @@ require_relative "nylas/deltas"
66
69
  require_relative "nylas/delta"
67
70
  require_relative "nylas/draft"
68
71
  require_relative "nylas/message"
72
+ require_relative "nylas/room_resource"
69
73
  require_relative "nylas/new_message"
70
74
  require_relative "nylas/raw_message"
71
75
  require_relative "nylas/thread"
@@ -91,6 +95,7 @@ module Nylas
91
95
  Types.registry[:folder] = Types::ModelType.new(model: Folder)
92
96
  Types.registry[:im_address] = Types::ModelType.new(model: IMAddress)
93
97
  Types.registry[:label] = Types::ModelType.new(model: Label)
98
+ Types.registry[:room_resource] = Types::ModelType.new(model: RoomResource)
94
99
  Types.registry[:message] = Types::ModelType.new(model: Message)
95
100
  Types.registry[:message_headers] = MessageHeadersType.new
96
101
  Types.registry[:message_tracking] = Types::ModelType.new(model: MessageTracking)
@@ -104,4 +109,5 @@ module Nylas
104
109
  Types.registry[:nylas_date] = NylasDateType.new
105
110
  Types.registry[:contact_group] = Types::ModelType.new(model: ContactGroup)
106
111
  Types.registry[:when] = Types::ModelType.new(model: When)
112
+ Types.registry[:time_slot] = Types::ModelType.new(model: TimeSlot)
107
113
  end
data/lib/nylas/api.rb CHANGED
@@ -6,7 +6,7 @@ module Nylas
6
6
  attr_accessor :client
7
7
 
8
8
  extend Forwardable
9
- def_delegators :client, :execute, :get, :post, :put, :delete, :app_id
9
+ def_delegators :client, :execute, :get, :post, :put, :delete, :app_id, :api_server
10
10
 
11
11
  include Logging
12
12
 
@@ -16,13 +16,11 @@ module Nylas
16
16
  # @param access_token [String] (Optional) Your users access token.
17
17
  # @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if
18
18
  # you're using a self-hosted Nylas instance.
19
- # @param service_domain [String] (Optional) Host you are authenticating OAuth against.
20
19
  # @return [Nylas::API]
21
20
  def initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil,
22
- api_server: "https://api.nylas.com", service_domain: "api.nylas.com")
21
+ api_server: "https://api.nylas.com")
23
22
  self.client = client || HttpClient.new(app_id: app_id, app_secret: app_secret,
24
- access_token: access_token, api_server: api_server,
25
- service_domain: service_domain)
23
+ access_token: access_token, api_server: api_server)
26
24
  end
27
25
 
28
26
  # @return [String] A Nylas access token for that particular user.
@@ -37,6 +35,19 @@ module Nylas
37
35
  )
38
36
  end
39
37
 
38
+ def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil)
39
+ params = {
40
+ client_id: app_id,
41
+ redirect_uri: redirect_uri,
42
+ response_type: response_type,
43
+ login_hint: login_hint
44
+ }
45
+ params[:state] = state if state
46
+ params[:scopes] = scopes.join(",") if scopes
47
+
48
+ "#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
49
+ end
50
+
40
51
  def exchange_code_for_token(code)
41
52
  data = {
42
53
  "client_id" => app_id,
@@ -110,6 +121,11 @@ module Nylas
110
121
  @messages ||= Collection.new(model: Message, api: self)
111
122
  end
112
123
 
124
+ # @return[Collection<RoomResource>] A queryable collection of {RoomResource} objects
125
+ def room_resources
126
+ @room_resources ||= Collection.new(model: RoomResource, api: self)
127
+ end
128
+
113
129
  # Revokes access to the Nylas API for the given access token
114
130
  # @return [Boolean]
115
131
  def revoke(access_token)
@@ -150,6 +166,15 @@ module Nylas
150
166
  @webhooks ||= Collection.new(model: Webhook, api: as(client.app_secret))
151
167
  end
152
168
 
169
+ def free_busy(emails:, start_time:, end_time:)
170
+ FreeBusyCollection.new(
171
+ api: self,
172
+ emails: emails,
173
+ start_time: start_time.to_i,
174
+ end_time: end_time.to_i
175
+ )
176
+ end
177
+
153
178
  private
154
179
 
155
180
  def prevent_calling_if_missing_access_token(method_name)
@@ -21,7 +21,7 @@ module Nylas
21
21
  end
22
22
 
23
23
  def create(**attributes)
24
- instance = model.new(attributes.merge(api: api))
24
+ instance = model.new(**attributes.merge(api: api))
25
25
  instance.save
26
26
  instance
27
27
  end
@@ -69,7 +69,7 @@ module Nylas
69
69
  return enum_for(:each) unless block_given?
70
70
 
71
71
  execute.each do |result|
72
- yield(model.new(result.merge(api: api)))
72
+ yield(model.new(**result.merge(api: api)))
73
73
  end
74
74
  end
75
75
 
@@ -119,7 +119,7 @@ module Nylas
119
119
  end
120
120
 
121
121
  def find_raw(id)
122
- api.execute(to_be_executed.merge(path: "#{resources_path}/#{id}")).to_s
122
+ api.execute(**to_be_executed.merge(path: "#{resources_path}/#{id}")).to_s
123
123
  end
124
124
 
125
125
  def resources_path
@@ -127,9 +127,13 @@ module Nylas
127
127
  end
128
128
 
129
129
  def find_model(id)
130
- instance = model.from_hash({ id: id }, api: api)
131
- instance.reload
132
- instance
130
+ response = api.execute(
131
+ **to_be_executed.merge(
132
+ path: "#{resources_path}/#{id}",
133
+ query: view_query
134
+ )
135
+ )
136
+ model.from_hash(response, api: api)
133
137
  end
134
138
 
135
139
  # @return [Hash] Specification for request to be passed to {API#execute}
@@ -141,7 +145,17 @@ module Nylas
141
145
  # Retrieves the data from the API for the particular constraints
142
146
  # @return [Hash,Array]
143
147
  def execute
144
- api.execute(to_be_executed)
148
+ api.execute(**to_be_executed)
149
+ end
150
+
151
+ private
152
+
153
+ def view_query
154
+ if constraints.view
155
+ { view: constraints.view }
156
+ else
157
+ {}
158
+ end
145
159
  end
146
160
  end
147
161
  end
data/lib/nylas/contact.rb CHANGED
@@ -13,9 +13,9 @@ module Nylas
13
13
  self.updatable = true
14
14
  self.destroyable = true
15
15
 
16
- attribute :id, :string, exclude_when: %i[creating updating]
16
+ attribute :id, :string, read_only: true
17
17
  attribute :object, :string, default: "contact"
18
- attribute :account_id, :string, exclude_when: %i[creating updating]
18
+ attribute :account_id, :string, read_only: true
19
19
 
20
20
  attribute :given_name, :string
21
21
  attribute :middle_name, :string
data/lib/nylas/delta.rb CHANGED
@@ -6,6 +6,7 @@ module Nylas
6
6
  # @see https://docs.nylas.com/reference#deltas
7
7
  class Delta
8
8
  include Model::Attributable
9
+
9
10
  attribute :id, :string
10
11
  attribute :type, :string
11
12
  attribute :object, :string
@@ -24,6 +25,8 @@ module Nylas
24
25
  @model ||= Types.registry[object.to_sym].cast(object_attributes_with_ids)
25
26
  end
26
27
 
28
+ private
29
+
27
30
  def object_attributes_with_ids
28
31
  (object_attributes || {}).merge(id: id, account_id: account_id)
29
32
  end
@@ -42,8 +45,10 @@ module Nylas
42
45
  else
43
46
  data
44
47
  end
48
+
49
+ data = data.merge(data[:attributes]) if data[:attributes]
45
50
  data[:object_attributes] = data.delete(:attributes)
46
- super(data)
51
+ super(**data)
47
52
  end
48
53
  end
49
54
  end
data/lib/nylas/deltas.rb CHANGED
@@ -14,6 +14,6 @@ module Nylas
14
14
  attribute :cursor_end, :string
15
15
 
16
16
  extend Forwardable
17
- def_delegators :deltas, :count, :length, :each, :map, :first, :to_a, :empty?
17
+ def_delegators :deltas, :count, :length, :each, :map, :first, :last, :to_a, :empty?
18
18
  end
19
19
  end
@@ -34,7 +34,7 @@ module Nylas
34
34
  # Retrieves the data from the API for the particular constraints
35
35
  # @return [Detlas]
36
36
  def execute
37
- self.deltas ||= Deltas.new(api.execute(to_be_executed))
37
+ self.deltas ||= Deltas.new(**api.execute(**to_be_executed))
38
38
  end
39
39
  end
40
40
  end
data/lib/nylas/draft.rb CHANGED
@@ -29,7 +29,8 @@ module Nylas
29
29
  attribute :unread, :boolean
30
30
 
31
31
  has_n_of_attribute :events, :event
32
- has_n_of_attribute :files, :file
32
+ has_n_of_attribute :files, :file, read_only: true
33
+ has_n_of_attribute :file_ids, :string
33
34
  attribute :folder, :folder
34
35
  has_n_of_attribute :labels, :label
35
36
 
@@ -37,6 +38,20 @@ module Nylas
37
38
 
38
39
  transfer :api, to: %i[events files folder labels]
39
40
 
41
+ def update(**data)
42
+ self.files = data[:files] if data[:files]
43
+ extract_file_ids!
44
+ data[:file_ids] = file_ids
45
+
46
+ super
47
+ end
48
+
49
+ def create
50
+ extract_file_ids!
51
+
52
+ super
53
+ end
54
+
40
55
  def send!
41
56
  return execute(method: :post, path: "/send", payload: to_json) if tracking
42
57
 
@@ -53,7 +68,21 @@ module Nylas
53
68
  end
54
69
 
55
70
  def destroy
56
- execute(method: :delete, path: resource_path, payload: attributes.serialize(keys: [:version]))
71
+ execute(method: :delete, path: resource_path, payload: attributes.serialize_for_api(keys: [:version]))
72
+ end
73
+
74
+ private
75
+
76
+ def save_call
77
+ extract_file_ids!
78
+
79
+ super
80
+ end
81
+
82
+ def extract_file_ids!
83
+ files = self.files || []
84
+
85
+ self.file_ids = files.map(&:id)
57
86
  end
58
87
  end
59
88
  end
data/lib/nylas/event.rb CHANGED
@@ -9,9 +9,9 @@ module Nylas
9
9
  allows_operations(creatable: true, listable: true, filterable: true, showable: true, updatable: true,
10
10
  destroyable: true)
11
11
 
12
- attribute :id, :string
13
- attribute :object, :string
14
- attribute :account_id, :string
12
+ attribute :id, :string, read_only: true
13
+ attribute :object, :string, read_only: true
14
+ attribute :account_id, :string, read_only: true
15
15
  attribute :calendar_id, :string
16
16
  attribute :master_event_id, :string
17
17
  attribute :message_id, :string
@@ -27,6 +27,7 @@ module Nylas
27
27
  attribute :status, :string
28
28
  attribute :title, :string
29
29
  attribute :when, :when
30
+ attribute :metadata, :hash
30
31
  attribute :original_start_time, :unix_timestamp
31
32
 
32
33
  attr_accessor :notify_participants
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,48 @@
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
@@ -5,6 +5,8 @@ module Nylas
5
5
 
6
6
  # Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
7
7
  class HttpClient # rubocop:disable Metrics/ClassLength
8
+ HTTP_SUCCESS_CODES = [200, 302].freeze
9
+
8
10
  HTTP_CODE_TO_EXCEPTIONS = {
9
11
  400 => InvalidRequest,
10
12
  401 => UnauthorizedRequest,
@@ -31,9 +33,10 @@ module Nylas
31
33
  "/delta/longpoll" => 3650,
32
34
  "/delta/streaming" => 3650
33
35
  }.freeze
36
+ SUPPORTED_API_VERSION = "2.2"
34
37
 
35
38
  include Logging
36
- attr_accessor :api_server, :service_domain
39
+ attr_accessor :api_server
37
40
  attr_writer :default_headers
38
41
  attr_reader :access_token
39
42
  attr_reader :app_id
@@ -44,10 +47,8 @@ module Nylas
44
47
  # @param access_token [String] (Optional) Your users access token.
45
48
  # @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if
46
49
  # you're using a self-hosted Nylas instance.
47
- # @param service_domain [String] (Optional) Host you are authenticating OAuth against.
48
50
  # @return [Nylas::HttpClient]
49
- def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api.nylas.com",
50
- service_domain: "api.nylas.com")
51
+ def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api.nylas.com")
51
52
  unless api_server.include?("://")
52
53
  raise "When overriding the Nylas API server address, you must include https://"
53
54
  end
@@ -56,13 +57,12 @@ module Nylas
56
57
  @access_token = access_token
57
58
  @app_secret = app_secret
58
59
  @app_id = app_id
59
- @service_domain = service_domain
60
60
  end
61
61
 
62
62
  # @return [Nylas::HttpClient[]
63
63
  def as(access_token)
64
64
  HttpClient.new(app_id: app_id, access_token: access_token,
65
- app_secret: app_secret, api_server: api_server, service_domain: service_domain)
65
+ app_secret: app_secret, api_server: api_server)
66
66
  end
67
67
 
68
68
  # Sends a request to the Nylas API and rai
@@ -103,8 +103,8 @@ module Nylas
103
103
  also_log: { result: true, values: %i[method url path headers query payload] }
104
104
 
105
105
  def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil)
106
- headers[:params] = query
107
106
  url ||= url_for_path(path)
107
+ url = add_query_params_to_url(url, query)
108
108
  resulting_headers = default_headers.merge(headers)
109
109
  { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
110
110
  end
@@ -137,6 +137,7 @@ module Nylas
137
137
  @default_headers ||= {
138
138
  "X-Nylas-API-Wrapper" => "ruby",
139
139
  "X-Nylas-Client-Id" => @app_id,
140
+ "Nylas-API-Version" => SUPPORTED_API_VERSION,
140
141
  "User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
141
142
  "Content-types" => "application/json"
142
143
  }
@@ -175,11 +176,40 @@ module Nylas
175
176
  end
176
177
 
177
178
  def handle_anticipated_failure_mode(http_code:, response:)
178
- return if http_code == 200
179
- return unless response.is_a?(Hash)
179
+ return if HTTP_SUCCESS_CODES.include?(http_code)
180
180
 
181
181
  exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
182
- raise exception.new(response[:type], response[:message], response.fetch(:server_error, nil))
182
+ parsed_response = parse_response(response)
183
+
184
+ raise exception.new(
185
+ parsed_response[:type],
186
+ parsed_response[:message],
187
+ parsed_response.fetch(:server_error, nil)
188
+ )
189
+ end
190
+
191
+ def add_query_params_to_url(url, query)
192
+ unless query.empty?
193
+ uri = URI.parse(url)
194
+ query = custom_params(query)
195
+ params = URI.decode_www_form(uri.query || "") + query.to_a
196
+ uri.query = URI.encode_www_form(params)
197
+ url = uri.to_s
198
+ end
199
+
200
+ url
201
+ end
202
+
203
+ def custom_params(query)
204
+ # Convert hash to "<key>:<value>" form for metadata_pair query
205
+ if query.key?(:metadata_pair)
206
+ pairs = query[:metadata_pair].map do |key, value|
207
+ "#{key}:#{value}"
208
+ end
209
+ query[:metadata_pair] = pairs
210
+ end
211
+
212
+ query
183
213
  end
184
214
  end
185
215
  end
data/lib/nylas/message.rb CHANGED
@@ -37,7 +37,7 @@ module Nylas
37
37
  attribute :folder, :folder
38
38
  attribute :folder_id, :string
39
39
 
40
- has_n_of_attribute :labels, :label, exclude_when: [:saving]
40
+ has_n_of_attribute :labels, :label, read_only: true
41
41
  has_n_of_attribute :label_ids, :string
42
42
 
43
43
  transfer :api, to: %i[events files folder labels]
@@ -56,7 +56,7 @@ module Nylas
56
56
  allowed_attributes: UPDATABLE_ATTRIBUTES
57
57
  ).check
58
58
 
59
- super(payload)
59
+ super(**payload)
60
60
  end
61
61
 
62
62
  def update_folder(folder_id)
@@ -66,7 +66,9 @@ module Nylas
66
66
  def expanded
67
67
  return self unless headers.nil?
68
68
 
69
- assign(api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
69
+ assign(**api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
70
+ # Transfer reference to the API to attributes that need it
71
+ transfer_attributes
70
72
  self
71
73
  end
72
74
 
@@ -75,7 +77,7 @@ module Nylas
75
77
 
76
78
  execute(
77
79
  method: :put,
78
- payload: attributes.serialize(keys: allowed_keys_for_save),
80
+ payload: attributes.serialize_for_api,
79
81
  path: resource_path
80
82
  )
81
83
  end
data/lib/nylas/model.rb CHANGED
@@ -48,7 +48,7 @@ module Nylas
48
48
 
49
49
  execute(
50
50
  method: :post,
51
- payload: attributes.serialize,
51
+ payload: attributes.serialize_for_api,
52
52
  path: resources_path,
53
53
  query: query_params
54
54
  )
@@ -58,19 +58,44 @@ module Nylas
58
58
  raise ModelNotUpdatableError, model_class unless updatable?
59
59
 
60
60
  attributes.merge(**data)
61
- execute(
62
- method: :put,
63
- payload: attributes.serialize(keys: data.keys),
64
- path: resource_path,
65
- query: query_params
66
- )
61
+ payload = attributes.serialize_for_api(keys: data.keys)
62
+ update_call(payload)
63
+
64
+ true
65
+ rescue Registry::MissingKeyError => e
66
+ raise ModelMissingFieldError.new(e.key, self)
67
+ end
68
+
69
+ def save_all_attributes
70
+ result = if persisted?
71
+ raise ModelNotUpdatableError, self unless updatable?
72
+
73
+ execute(
74
+ method: :put,
75
+ payload: attributes.serialize_all_for_api,
76
+ path: resource_path
77
+ )
78
+ else
79
+ create
80
+ end
81
+
82
+ attributes.merge(result)
83
+ end
84
+
85
+ def update_all_attributes(**data)
86
+ raise ModelNotUpdatableError, model_class unless updatable?
87
+
88
+ attributes.merge(**data)
89
+ payload = attributes.serialize_all_for_api(keys: data.keys)
90
+ update_call(payload)
91
+
67
92
  true
68
93
  rescue Registry::MissingKeyError => e
69
94
  raise ModelMissingFieldError.new(e.key, self)
70
95
  end
71
96
 
72
97
  def reload
73
- assign(execute(method: :get, path: resource_path))
98
+ assign(**execute(method: :get, path: resource_path))
74
99
  true
75
100
  end
76
101
 
@@ -95,20 +120,24 @@ module Nylas
95
120
 
96
121
  private
97
122
 
98
- def allowed_keys_for_save
99
- attributes.attribute_definitions.to_h.reject do |_k, v|
100
- v.exclude_when.include?(:saving)
101
- end.keys
102
- end
103
-
104
123
  def save_call
105
124
  execute(
106
125
  method: :put,
107
- payload: attributes.serialize(keys: allowed_keys_for_save),
126
+ payload: attributes.serialize_for_api,
108
127
  path: resource_path
109
128
  )
110
129
  end
111
130
 
131
+ def update_call(payload)
132
+ result = execute(
133
+ method: :put,
134
+ payload: payload,
135
+ path: resource_path,
136
+ query: query_params
137
+ )
138
+ attributes.merge(result) if result
139
+ end
140
+
112
141
  def query_params
113
142
  {}
114
143
  end
@@ -34,17 +34,22 @@ module Nylas
34
34
  # Methods to call when tweaking Attributable classes
35
35
  module ClassMethods
36
36
  # rubocop:disable Naming/PredicateName
37
- def has_n_of_attribute(name, type_name, exclude_when: [], default: [])
38
- attribute_definitions[name] = ListAttributeDefinition.new(type_name: type_name,
39
- exclude_when: exclude_when,
40
- default: default)
37
+ def has_n_of_attribute(name, type_name, read_only: false, default: [])
38
+ attribute_definitions[name] = ListAttributeDefinition.new(
39
+ type_name: type_name,
40
+ read_only: read_only,
41
+ default: default
42
+ )
41
43
  define_accessors(name)
42
44
  end
43
45
  # rubocop:enable Naming/PredicateName
44
46
 
45
- def attribute(name, type_name, exclude_when: [], default: nil)
46
- attribute_definitions[name] = AttributeDefinition.new(type_name: type_name,
47
- exclude_when: exclude_when, default: default)
47
+ def attribute(name, type_name, read_only: false, default: nil)
48
+ attribute_definitions[name] = AttributeDefinition.new(
49
+ type_name: type_name,
50
+ read_only: read_only,
51
+ default: default
52
+ )
48
53
  define_accessors(name)
49
54
  end
50
55
 
@@ -6,11 +6,11 @@ module Nylas
6
6
  class AttributeDefinition
7
7
  extend Forwardable
8
8
  def_delegators :type, :cast, :serialize
9
- attr_accessor :type_name, :exclude_when, :default
9
+ attr_accessor :type_name, :read_only, :default
10
10
 
11
- def initialize(type_name:, exclude_when:, default:)
11
+ def initialize(type_name:, read_only:, default:)
12
12
  self.type_name = type_name
13
- self.exclude_when = exclude_when
13
+ self.read_only = read_only
14
14
  self.default = default
15
15
  end
16
16
 
@@ -39,6 +39,22 @@ module Nylas
39
39
  JSON.dump(to_h(keys: keys))
40
40
  end
41
41
 
42
+ def serialize_for_api(keys: attribute_definitions.keys)
43
+ api_keys = keys.delete_if { |key| attribute_definitions[key].read_only == true }
44
+
45
+ serialize(keys: api_keys)
46
+ end
47
+
48
+ def serialize_all_for_api(keys: attribute_definitions.keys)
49
+ api_keys = keys.delete_if { |key| attribute_definitions[key].read_only == true }
50
+
51
+ JSON.dump(
52
+ api_keys.each_with_object({}) do |key, casted_data|
53
+ casted_data[key] = attribute_definitions[key].serialize(self[key])
54
+ end
55
+ )
56
+ end
57
+
42
58
  private
43
59
 
44
60
  def cast(key, value)
@@ -4,11 +4,11 @@ module Nylas
4
4
  module Model
5
5
  # Allows models to have an attribute which is a lists of another type of thing
6
6
  class ListAttributeDefinition
7
- attr_accessor :type_name, :exclude_when, :default
7
+ attr_accessor :type_name, :read_only, :default
8
8
 
9
- def initialize(type_name:, exclude_when:, default:)
9
+ def initialize(type_name:, read_only:, default:)
10
10
  self.type_name = type_name
11
- self.exclude_when = exclude_when
11
+ self.read_only = read_only
12
12
  self.default = default
13
13
  end
14
14
 
@@ -11,8 +11,15 @@ module Nylas
11
11
  end
12
12
 
13
13
  def send!
14
- Message.new(api.execute(method: :post, path: "/send", payload: mime_compatible_string,
15
- headers: { "Content-type" => "message/rfc822" }).merge(api: api))
14
+ Message.new(**api.execute(
15
+ method: :post,
16
+ path: "/send",
17
+ payload: mime_compatible_string,
18
+ headers: HEADERS
19
+ ).merge(api: api))
16
20
  end
21
+
22
+ HEADERS = { "Content-type" => "message/rfc822" }.freeze
23
+ private_constant :HEADERS
17
24
  end
18
25
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nylas
4
+ # Ruby representation of a Nylas Room Resource object
5
+ # @see https://developer.nylas.com/docs/api/#tag--Room-Resources
6
+ class RoomResource
7
+ include Model
8
+ self.resources_path = "/resources"
9
+ allows_operations(listable: true)
10
+
11
+ attribute :object, :string, read_only: true
12
+ attribute :email, :string, read_only: true
13
+ attribute :name, :string, read_only: true
14
+ attribute :capacity, :string, read_only: true
15
+ attribute :building, :string, read_only: true
16
+ attribute :floor_name, :string, read_only: true
17
+ attribute :floor_number, :string, read_only: true
18
+ end
19
+ end
data/lib/nylas/rsvp.rb CHANGED
@@ -13,8 +13,12 @@ module Nylas
13
13
  attr_accessor :notify_participants
14
14
 
15
15
  def save
16
- api.execute(method: :post, path: "/send-rsvp", payload: attributes.serialize,
17
- query: { notify_participants: notify_participants })
16
+ api.execute(
17
+ method: :post,
18
+ path: "/send-rsvp",
19
+ payload: attributes.serialize_for_api,
20
+ query: { notify_participants: notify_participants }
21
+ )
18
22
  end
19
23
  end
20
24
  end
data/lib/nylas/thread.rb CHANGED
@@ -42,7 +42,7 @@ module Nylas
42
42
  raise ArgumentError, "Cannot update #{unupdatable_attributes} only " \
43
43
  "#{UPDATABLE_ATTRIBUTES} are updatable"
44
44
  end
45
- super(data)
45
+ super(**data)
46
46
  end
47
47
 
48
48
  def update_folder(folder_id)
@@ -0,0 +1,14 @@
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 TimeSlot
7
+ include Model::Attributable
8
+
9
+ attribute :object, :string
10
+ attribute :status, :string
11
+ attribute :start_time, :unix_timestamp
12
+ attribute :end_time, :unix_timestamp
13
+ end
14
+ 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 = "4.6.6"
4
+ VERSION = "5.2.0"
5
5
  end
data/lib/nylas/when.rb CHANGED
@@ -8,7 +8,7 @@ module Nylas
8
8
 
9
9
  include Model::Attributable
10
10
 
11
- attribute :object, :string
11
+ attribute :object, :string, read_only: true
12
12
 
13
13
  # when object == 'date'
14
14
  attribute :date, :date
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: 4.6.6
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.0
27
- - !ruby/object:Gem::Dependency
28
- name: jeweler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: yard
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -300,6 +286,8 @@ files:
300
286
  - lib/nylas/file.rb
301
287
  - lib/nylas/filter_attributes.rb
302
288
  - lib/nylas/folder.rb
289
+ - lib/nylas/free_busy.rb
290
+ - lib/nylas/free_busy_collection.rb
303
291
  - lib/nylas/http_client.rb
304
292
  - lib/nylas/im_address.rb
305
293
  - lib/nylas/label.rb
@@ -322,9 +310,11 @@ files:
322
310
  - lib/nylas/raw_message.rb
323
311
  - lib/nylas/recurrence.rb
324
312
  - lib/nylas/registry.rb
313
+ - lib/nylas/room_resource.rb
325
314
  - lib/nylas/rsvp.rb
326
315
  - lib/nylas/search_collection.rb
327
316
  - lib/nylas/thread.rb
317
+ - lib/nylas/time_slot.rb
328
318
  - lib/nylas/timespan.rb
329
319
  - lib/nylas/types.rb
330
320
  - lib/nylas/version.rb
@@ -356,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
356
346
  - !ruby/object:Gem::Version
357
347
  version: '0'
358
348
  requirements: []
359
- rubygems_version: 3.1.2
349
+ rubygems_version: 3.2.17
360
350
  signing_key:
361
351
  specification_version: 4
362
352
  summary: Gem for interacting with the Nylas API