nylas 4.6.0 → 4.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nylas.rb +15 -0
- data/lib/nylas/api.rb +12 -0
- data/lib/nylas/calendar.rb +7 -0
- data/lib/nylas/contact.rb +0 -1
- data/lib/nylas/draft.rb +4 -0
- data/lib/nylas/errors.rb +6 -0
- data/lib/nylas/event.rb +1 -0
- data/lib/nylas/file.rb +4 -1
- data/lib/nylas/http_client.rb +21 -5
- data/lib/nylas/message.rb +22 -0
- data/lib/nylas/model/attributable.rb +1 -3
- data/lib/nylas/model/attributes.rb +2 -0
- data/lib/nylas/new_message.rb +2 -1
- data/lib/nylas/physical_address.rb +1 -0
- data/lib/nylas/thread.rb +4 -0
- data/lib/nylas/types.rb +1 -0
- data/lib/nylas/version.rb +1 -1
- metadata +29 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc59654b2a73962455afa89f51aa5bd9b5dcfe7867c6a10add1da68725982db6
|
4
|
+
data.tar.gz: 6df2f0c708e16d688666429edb793f736f9df1ae65fc310f3c1ffdf8fa197672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/nylas/calendar.rb
CHANGED
@@ -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
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
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
|
-
|
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
|
data/lib/nylas/http_client.rb
CHANGED
@@ -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
|
-
|
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)
|
134
|
-
|
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
|
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
|
data/lib/nylas/new_message.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nylas
|
4
|
-
# Data structure for
|
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/thread.rb
CHANGED
data/lib/nylas/types.rb
CHANGED
data/lib/nylas/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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.
|
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: []
|