nylas 4.6.3 → 4.6.4

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: 34f645631bf41230a0c8709c0212c5b83fb24fa44bdf3b7b62429ec72ce92b41
4
- data.tar.gz: 2d043ada950f30d03b65f45cb1e0635868cd7c092d919f992b1d9359519c995b
3
+ metadata.gz: eac1943c9596d6042676b8c5eb3356e6986a5f41088b419fd6dcd8295ef41fd7
4
+ data.tar.gz: a6207a0b0004fcfcaf251675fe6ad9d70c0c3cd57bcb9b7ca6e83d95decdb8e6
5
5
  SHA512:
6
- metadata.gz: 3af07161869273f8fa33a38c97c286ec4c62aebb37b303e2fee348773c7d1c33ddb7c45531a95d792af21c90eca9055e1181b3fca2f5a412fd1809037ec5c70b
7
- data.tar.gz: ea27a61dee30fc747b42fd2713e4755ca7f50243bbcf47d2bb8582aec96f1613ae3795206c62a5905ee4fbdc353c69f1c3f191e40f5b5b319728ccdd4cb80085
6
+ metadata.gz: '018f5931707cc9bbb8ab43908619fd7fabb9eea0992cbcc486bc35c2d67ff9ae8ffb52a49a9bfa0beecf4eca4897849e4e2bcd1c33878a89f06756de24f60c59'
7
+ data.tar.gz: 0a215f1bcc5e9b19bbd5229ed350fefe07bfb415f7e1118f451f2e31998604fa1b730d325d68083cfe09fb9a9efc84a18a247f8a85ad41b48231732f37c57c81
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/file.rb CHANGED
@@ -56,7 +56,9 @@ module Nylas
56
56
  def retrieve_file
57
57
  response = api.get(path: "#{resource_path}/download")
58
58
  filename = response.headers.fetch(:content_disposition, "").gsub("attachment; filename=", "")
59
- temp_file = Tempfile.new(filename, encoding: "ascii-8bit")
59
+ # The returned filename can be longer than 256 chars which isn't supported by rb_sysopen.
60
+ # 128 chars here is more than enough given that TempFile ensure the filename will be unique.
61
+ temp_file = Tempfile.new(filename[0..127], encoding: "ascii-8bit")
60
62
  temp_file.write(response.body)
61
63
  temp_file.seek(0)
62
64
  temp_file
@@ -7,16 +7,20 @@ module Nylas
7
7
  class HttpClient # rubocop:disable Metrics/ClassLength
8
8
  HTTP_CODE_TO_EXCEPTIONS = {
9
9
  400 => InvalidRequest,
10
+ 401 => UnauthorizedRequest,
10
11
  402 => MessageRejected,
11
12
  403 => AccessDenied,
12
13
  404 => ResourceNotFound,
13
14
  405 => MethodNotAllowed,
15
+ 410 => ResourceRemoved,
16
+ 418 => TeapotError,
14
17
  422 => MailProviderError,
15
18
  429 => SendingQuotaExceeded,
16
19
  500 => InternalError,
17
20
  501 => EndpointNotYetImplemented,
18
21
  502 => BadGateway,
19
- 503 => ServiceUnavailable
22
+ 503 => ServiceUnavailable,
23
+ 504 => RequestTimedOut
20
24
  }.freeze
21
25
 
22
26
  ENDPOINT_TIMEOUTS = {
@@ -82,7 +86,14 @@ module Nylas
82
86
  timeout: timeout
83
87
  )
84
88
  rest_client_execute(**request) do |response, _request, result|
85
- 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
+
86
97
  handle_failed_response(result: result, response: response)
87
98
  response
88
99
  end
@@ -136,6 +147,8 @@ module Nylas
136
147
 
137
148
  json = StringIO.new(response)
138
149
  Yajl::Parser.new(symbolize_names: true).parse(json)
150
+ rescue Yajl::ParseError
151
+ raise Nylas::JsonParseError
139
152
  end
140
153
  inform_on :parse_response, level: :debug, also_log: { result: true }
141
154
 
@@ -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
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.3"
4
+ VERSION = "4.6.4"
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.3
4
+ version: 4.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-19 00:00:00.000000000 Z
11
+ date: 2021-02-04 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,7 +250,7 @@ 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'
@@ -356,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
356
356
  - !ruby/object:Gem::Version
357
357
  version: '0'
358
358
  requirements: []
359
- rubygems_version: 3.0.8
359
+ rubygems_version: 3.2.5
360
360
  signing_key:
361
361
  specification_version: 4
362
362
  summary: Gem for interacting with the Nylas API