nylas 4.6.0 → 4.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e28cb5adc245b84ca2b193137308a2d0d95b45ec76938b8ce8bc50ad43e39e
4
- data.tar.gz: 7b518a3084cacc0416ccfe7124d5580f092e63d9589c62d693a4c889618155ec
3
+ metadata.gz: cc59654b2a73962455afa89f51aa5bd9b5dcfe7867c6a10add1da68725982db6
4
+ data.tar.gz: 6df2f0c708e16d688666429edb793f736f9df1ae65fc310f3c1ffdf8fa197672
5
5
  SHA512:
6
- metadata.gz: 77debca7d2c13b8da3f64266843d834a1e49b2cbb982a5176e6fd084eb472c5b7a6ba9e865266092c1e4240eedcc7f9db3eb959f114b7f33c1bef0d4f888cf09
7
- data.tar.gz: be398a3b5ca813fc91f9bd44abba42d1a6c36f20397646529b97829e1b752f1b4b45f56c223ce1a72fedeed1b0c566b92b3148db517332344d93bd08bd9bf43c
6
+ metadata.gz: c2bb1f816dbd759685097c76d7d03ee9a24870fd341a4cd2909cc33be5078f6a1bee9b72871d126a48f09e6e0edd047e2f1dd2b3b9b0205003f7cf8d2af6ac25
7
+ data.tar.gz: dd34aa4b46d5de885dc3c0acca19fe4f0adfedec97b2790e2bff402c3240aa5c26c78f4b413c8cf817e5914eb8cd6788770a652ff21af4484c80b832ba44909f
data/lib/nylas.rb CHANGED
@@ -3,6 +3,21 @@
3
3
  require "json"
4
4
  require "rest-client"
5
5
 
6
+ # BUGFIX
7
+ # See https://github.com/sparklemotion/http-cookie/issues/27
8
+ # and https://github.com/sparklemotion/http-cookie/issues/6
9
+ #
10
+ # CookieJar uses unsafe class caching for dynamically loading cookie jars
11
+ # If 2 rest-client instances are instantiated at the same time, (in threads)
12
+ # non-deterministic behaviour can occur whereby the Hash cookie jar isn't
13
+ # properly loaded and cached.
14
+ # Forcing an instantiation of the jar onload will force the CookieJar to load
15
+ # before the system has a chance to spawn any threads.
16
+ # Note this should technically be fixed in rest-client itself however that
17
+ # library appears to be stagnant so we're forced to fix it here
18
+ # This object should get GC'd as it's not referenced by anything
19
+ HTTP::CookieJar.new
20
+
6
21
  require "ostruct"
7
22
  require "forwardable"
8
23
 
data/lib/nylas/api.rb CHANGED
@@ -36,6 +36,18 @@ module Nylas
36
36
  )
37
37
  end
38
38
 
39
+ def exchange_code_for_token(code)
40
+ data = {
41
+ "client_id" => app_id,
42
+ "client_secret" => client.app_secret,
43
+ "grant_type" => "authorization_code",
44
+ "code" => code
45
+ }
46
+
47
+ response_json = execute(method: :post, path: "/oauth/token", payload: data)
48
+ response_json[:access_token]
49
+ end
50
+
39
51
  # @return [Collection<Contact>] A queryable collection of Contacts
40
52
  def contacts
41
53
  @contacts ||= Collection.new(model: Contact, api: self)
@@ -15,6 +15,9 @@ module Nylas
15
15
 
16
16
  attribute :name, :string
17
17
  attribute :description, :string
18
+ attribute :is_primary, :boolean
19
+ attribute :location, :string
20
+ attribute :timezone, :string
18
21
 
19
22
  attribute :read_only, :boolean
20
23
 
@@ -22,6 +25,10 @@ module Nylas
22
25
  read_only == true
23
26
  end
24
27
 
28
+ def primary?
29
+ is_primary
30
+ end
31
+
25
32
  def events
26
33
  api.events.where(calendar_id: id)
27
34
  end
data/lib/nylas/contact.rb CHANGED
@@ -29,7 +29,6 @@ module Nylas
29
29
  attribute :manager_name, :string
30
30
  attribute :office_location, :string
31
31
  attribute :notes, :string
32
- attribute :web_page, :web_page
33
32
  attribute :source, :string
34
33
 
35
34
  has_n_of_attribute :groups, :contact_group
data/lib/nylas/draft.rb CHANGED
@@ -33,9 +33,13 @@ module Nylas
33
33
  attribute :folder, :folder
34
34
  has_n_of_attribute :labels, :label
35
35
 
36
+ attribute :tracking, :message_tracking
37
+
36
38
  transfer :api, to: %i[events files folder labels]
37
39
 
38
40
  def send!
41
+ return execute(method: :post, path: "/send", payload: to_json) if tracking
42
+
39
43
  save
40
44
  execute(method: :post, path: "/send", payload: JSON.dump(draft_id: id, version: version))
41
45
  end
data/lib/nylas/errors.rb CHANGED
@@ -14,6 +14,8 @@ module Nylas
14
14
  class ModelNotUpdatableError < ModelActionError; end
15
15
  class ModelNotDestroyableError < ModelActionError; end
16
16
 
17
+ class JsonParseError < Error; end
18
+
17
19
  # Raised when attempting to set a field that is not on a model with mass assignment
18
20
  class ModelMissingFieldError < ModelActionError
19
21
  def initialize(field, model)
@@ -48,6 +50,10 @@ module Nylas
48
50
  ResourceNotFound = Class.new(APIError)
49
51
  MethodNotAllowed = Class.new(APIError)
50
52
  InvalidRequest = Class.new(APIError)
53
+ UnauthorizedRequest = Class.new(APIError)
54
+ ResourceRemoved = Class.new(APIError)
55
+ TeapotError = Class.new(APIError)
56
+ RequestTimedOut = Class.new(APIError)
51
57
  MessageRejected = Class.new(APIError)
52
58
  SendingQuotaExceeded = Class.new(APIError)
53
59
  ServiceUnavailable = Class.new(APIError)
data/lib/nylas/event.rb CHANGED
@@ -15,6 +15,7 @@ module Nylas
15
15
  attribute :calendar_id, :string
16
16
  attribute :master_event_id, :string
17
17
  attribute :message_id, :string
18
+ attribute :ical_uid, :string
18
19
 
19
20
  attribute :busy, :boolean
20
21
  attribute :description, :string
data/lib/nylas/file.rb CHANGED
@@ -18,6 +18,7 @@ module Nylas
18
18
  attribute :content_type, :string
19
19
  attribute :filename, :string
20
20
  attribute :size, :integer
21
+ attribute :content_disposition, :string
21
22
 
22
23
  attr_accessor :file
23
24
  # Downloads and caches a local copy of the file.
@@ -56,7 +57,9 @@ module Nylas
56
57
  def retrieve_file
57
58
  response = api.get(path: "#{resource_path}/download")
58
59
  filename = response.headers.fetch(:content_disposition, "").gsub("attachment; filename=", "")
59
- temp_file = Tempfile.new(filename, encoding: "ascii-8bit")
60
+ # The returned filename can be longer than 256 chars which isn't supported by rb_sysopen.
61
+ # 128 chars here is more than enough given that TempFile ensure the filename will be unique.
62
+ temp_file = Tempfile.new(filename[0..127], encoding: "ascii-8bit")
60
63
  temp_file.write(response.body)
61
64
  temp_file.seek(0)
62
65
  temp_file
@@ -1,20 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
+ require "yajl"
5
+
4
6
  # Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
5
7
  class HttpClient # rubocop:disable Metrics/ClassLength
6
8
  HTTP_CODE_TO_EXCEPTIONS = {
7
9
  400 => InvalidRequest,
10
+ 401 => UnauthorizedRequest,
8
11
  402 => MessageRejected,
9
12
  403 => AccessDenied,
10
13
  404 => ResourceNotFound,
11
14
  405 => MethodNotAllowed,
15
+ 410 => ResourceRemoved,
16
+ 418 => TeapotError,
12
17
  422 => MailProviderError,
13
18
  429 => SendingQuotaExceeded,
14
19
  500 => InternalError,
15
20
  501 => EndpointNotYetImplemented,
16
21
  502 => BadGateway,
17
- 503 => ServiceUnavailable
22
+ 503 => ServiceUnavailable,
23
+ 504 => RequestTimedOut
18
24
  }.freeze
19
25
 
20
26
  ENDPOINT_TIMEOUTS = {
@@ -80,7 +86,14 @@ module Nylas
80
86
  timeout: timeout
81
87
  )
82
88
  rest_client_execute(**request) do |response, _request, result|
83
- response = parse_response(response)
89
+ content_type = nil
90
+
91
+ if response.headers && response.headers[:content_type]
92
+ content_type = response.headers[:content_type].downcase
93
+ end
94
+
95
+ response = parse_response(response) if content_type == "application/json"
96
+
84
97
  handle_failed_response(result: result, response: response)
85
98
  response
86
99
  end
@@ -130,9 +143,12 @@ module Nylas
130
143
  end
131
144
 
132
145
  def parse_response(response)
133
- response.is_a?(Enumerable) ? response : JSON.parse(response, symbolize_names: true)
134
- rescue JSON::ParserError
135
- response
146
+ return response if response.is_a?(Enumerable)
147
+
148
+ json = StringIO.new(response)
149
+ Yajl::Parser.new(symbolize_names: true).parse(json)
150
+ rescue Yajl::ParseError
151
+ raise Nylas::JsonParseError
136
152
  end
137
153
  inform_on :parse_response, level: :debug, also_log: { result: true }
138
154
 
data/lib/nylas/message.rb CHANGED
@@ -59,11 +59,33 @@ module Nylas
59
59
  super(payload)
60
60
  end
61
61
 
62
+ def update_folder(folder_id)
63
+ update(folder_id: folder_id)
64
+ end
65
+
62
66
  def expanded
63
67
  return self unless headers.nil?
64
68
 
65
69
  assign(api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
66
70
  self
67
71
  end
72
+
73
+ def save_call
74
+ handle_folder
75
+
76
+ execute(
77
+ method: :put,
78
+ payload: attributes.serialize(keys: allowed_keys_for_save),
79
+ path: resource_path
80
+ )
81
+ end
82
+
83
+ def handle_folder
84
+ return if folder.nil?
85
+
86
+ self.folder_id = folder.id if folder_id.nil? && !self.to_h.dig(:folder, :id).nil?
87
+
88
+ self.folder = nil
89
+ end
68
90
  end
69
91
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Nylas
4
4
  module Model
5
- # Allows defining of tyypecastable attributes on a model
5
+ # Allows defining of typecastable attributes on a model
6
6
  module Attributable
7
7
  def self.included(model)
8
8
  model.extend(ClassMethods)
@@ -27,8 +27,6 @@ module Nylas
27
27
  data.each do |attribute_name, value|
28
28
  if respond_to?(:"#{attribute_name}=")
29
29
  send(:"#{attribute_name}=", value)
30
- else
31
- Logging.logger.warn("#{attribute_name} is not defined as an attribute on #{self.class.name}")
32
30
  end
33
31
  end
34
32
  end
@@ -17,6 +17,8 @@ module Nylas
17
17
 
18
18
  def []=(key, value)
19
19
  data[key] = cast(key, value)
20
+ rescue Nylas::Registry::MissingKeyError
21
+ # Don't crash when a new attribute is added
20
22
  end
21
23
 
22
24
  # Merges data into the registry while casting input types correctly
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- # Data structure for seending a message via the Nylas API
4
+ # Data structure for sending a message via the Nylas API
5
5
  class NewMessage
6
6
  include Model
7
7
  self.creatable = false
@@ -15,6 +15,7 @@ module Nylas
15
15
  has_n_of_attribute :from, :email_address
16
16
  has_n_of_attribute :cc, :email_address
17
17
  has_n_of_attribute :bcc, :email_address
18
+ has_n_of_attribute :reply_to, :email_address
18
19
 
19
20
  attribute :subject, :string
20
21
  attribute :body, :string
@@ -12,5 +12,6 @@ module Nylas
12
12
  attribute :state, :string
13
13
  attribute :city, :string
14
14
  attribute :country, :string
15
+ attribute :secondary_address, :string
15
16
  end
16
17
  end
data/lib/nylas/thread.rb CHANGED
@@ -45,6 +45,10 @@ module Nylas
45
45
  super(data)
46
46
  end
47
47
 
48
+ def update_folder(folder_id)
49
+ update(folder_id: folder_id)
50
+ end
51
+
48
52
  def starred?
49
53
  starred
50
54
  end
data/lib/nylas/types.rb CHANGED
@@ -86,6 +86,7 @@ module Nylas
86
86
  end
87
87
 
88
88
  def serialize(object)
89
+ return nil if object.nil?
89
90
  object.to_i
90
91
  end
91
92
  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.0"
4
+ VERSION = "4.6.5"
5
5
  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: 4.6.0
4
+ version: 4.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-27 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -240,7 +240,7 @@ dependencies:
240
240
  requirements:
241
241
  - - ">="
242
242
  - !ruby/object:Gem::Version
243
- version: '1.6'
243
+ version: '2.0'
244
244
  - - "<"
245
245
  - !ruby/object:Gem::Version
246
246
  version: '3.0'
@@ -250,10 +250,30 @@ dependencies:
250
250
  requirements:
251
251
  - - ">="
252
252
  - !ruby/object:Gem::Version
253
- version: '1.6'
253
+ version: '2.0'
254
254
  - - "<"
255
255
  - !ruby/object:Gem::Version
256
256
  version: '3.0'
257
+ - !ruby/object:Gem::Dependency
258
+ name: yajl-ruby
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '1.2'
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: 1.2.1
267
+ type: :runtime
268
+ prerelease: false
269
+ version_requirements: !ruby/object:Gem::Requirement
270
+ requirements:
271
+ - - "~>"
272
+ - !ruby/object:Gem::Version
273
+ version: '1.2'
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: 1.2.1
257
277
  description: Gem for interacting with the Nylas API.
258
278
  email: support@nylas.com
259
279
  executables: []
@@ -311,7 +331,7 @@ files:
311
331
  - lib/nylas/web_page.rb
312
332
  - lib/nylas/webhook.rb
313
333
  - lib/nylas/when.rb
314
- homepage:
334
+ homepage:
315
335
  licenses:
316
336
  - MIT
317
337
  metadata:
@@ -321,7 +341,7 @@ metadata:
321
341
  homepage_uri: https://www.nylas.com
322
342
  source_code_uri: https://github.com/nylas/nylas-ruby
323
343
  wiki_uri: https://github.com/nylas/nylas-ruby/wiki
324
- post_install_message:
344
+ post_install_message:
325
345
  rdoc_options: []
326
346
  require_paths:
327
347
  - lib
@@ -336,8 +356,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
356
  - !ruby/object:Gem::Version
337
357
  version: '0'
338
358
  requirements: []
339
- rubygems_version: 3.0.3
340
- signing_key:
359
+ rubygems_version: 3.1.2
360
+ signing_key:
341
361
  specification_version: 4
342
362
  summary: Gem for interacting with the Nylas API
343
363
  test_files: []