nylas 4.6.3 → 5.0.0
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 +19 -0
- data/lib/nylas/account.rb +1 -0
- data/lib/nylas/api.rb +24 -1
- data/lib/nylas/collection.rb +22 -7
- data/lib/nylas/constraints.rb +1 -0
- data/lib/nylas/deltas_collection.rb +2 -1
- data/lib/nylas/draft.rb +4 -0
- data/lib/nylas/errors.rb +6 -0
- data/lib/nylas/event.rb +17 -3
- data/lib/nylas/file.rb +5 -1
- data/lib/nylas/free_busy.rb +13 -0
- data/lib/nylas/free_busy_collection.rb +48 -0
- data/lib/nylas/http_client.rb +17 -2
- data/lib/nylas/logging.rb +0 -3
- data/lib/nylas/message.rb +2 -2
- data/lib/nylas/model.rb +20 -6
- data/lib/nylas/model/attribute_definition.rb +1 -0
- data/lib/nylas/model/transferable.rb +1 -0
- data/lib/nylas/native_authentication.rb +1 -0
- data/lib/nylas/new_message.rb +2 -1
- data/lib/nylas/raw_message.rb +10 -2
- data/lib/nylas/registry.rb +1 -0
- data/lib/nylas/thread.rb +1 -1
- data/lib/nylas/time_slot.rb +14 -0
- data/lib/nylas/types.rb +2 -0
- data/lib/nylas/version.rb +1 -1
- metadata +12 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82a2a7e6af812dd58557c604deb553e18d586c373ee8c308b1eddc8492a44c28
|
4
|
+
data.tar.gz: 43b9a7943a854c10f2257d49220fc420ff4e3b022b76a527ba772041600d24dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c005ca3d6e0f61bc25ebdab118cc0dda5dd366c24b8ad1519b78a5bb32bd0de976b1070fb6dc35dfbd81ffd4540c636956c38f1248e412e80441cf12fb788d0
|
7
|
+
data.tar.gz: 05e47ffa2fb00e66adf7483b7eb7a0bd870c85dbff006dee3cfa7b968589173634d77d74519bc04e657d214efdfd17b1bc8ef492da0880edef5552fb012ac466
|
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
|
|
@@ -36,10 +51,13 @@ require_relative "nylas/timespan"
|
|
36
51
|
require_relative "nylas/web_page"
|
37
52
|
require_relative "nylas/nylas_date"
|
38
53
|
require_relative "nylas/when"
|
54
|
+
require_relative "nylas/free_busy"
|
55
|
+
require_relative "nylas/time_slot"
|
39
56
|
|
40
57
|
# Custom collection types
|
41
58
|
require_relative "nylas/search_collection"
|
42
59
|
require_relative "nylas/deltas_collection"
|
60
|
+
require_relative "nylas/free_busy_collection"
|
43
61
|
|
44
62
|
# Models supported by the API
|
45
63
|
require_relative "nylas/account"
|
@@ -89,4 +107,5 @@ module Nylas
|
|
89
107
|
Types.registry[:nylas_date] = NylasDateType.new
|
90
108
|
Types.registry[:contact_group] = Types::ModelType.new(model: ContactGroup)
|
91
109
|
Types.registry[:when] = Types::ModelType.new(model: When)
|
110
|
+
Types.registry[:time_slot] = Types::ModelType.new(model: TimeSlot)
|
92
111
|
end
|
data/lib/nylas/account.rb
CHANGED
data/lib/nylas/api.rb
CHANGED
@@ -4,8 +4,9 @@ module Nylas
|
|
4
4
|
# Methods to retrieve data from the Nylas API as Ruby objects
|
5
5
|
class API
|
6
6
|
attr_accessor :client
|
7
|
+
|
7
8
|
extend Forwardable
|
8
|
-
def_delegators :client, :execute, :get, :post, :put, :delete, :app_id
|
9
|
+
def_delegators :client, :execute, :get, :post, :put, :delete, :app_id, :api_server
|
9
10
|
|
10
11
|
include Logging
|
11
12
|
|
@@ -36,6 +37,19 @@ module Nylas
|
|
36
37
|
)
|
37
38
|
end
|
38
39
|
|
40
|
+
def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil)
|
41
|
+
params = {
|
42
|
+
client_id: app_id,
|
43
|
+
redirect_uri: redirect_uri,
|
44
|
+
response_type: response_type,
|
45
|
+
login_hint: login_hint
|
46
|
+
}
|
47
|
+
params[:state] = state if state
|
48
|
+
params[:scopes] = scopes.join(",") if scopes
|
49
|
+
|
50
|
+
"#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
|
51
|
+
end
|
52
|
+
|
39
53
|
def exchange_code_for_token(code)
|
40
54
|
data = {
|
41
55
|
"client_id" => app_id,
|
@@ -149,6 +163,15 @@ module Nylas
|
|
149
163
|
@webhooks ||= Collection.new(model: Webhook, api: as(client.app_secret))
|
150
164
|
end
|
151
165
|
|
166
|
+
def free_busy(emails:, start_time:, end_time:)
|
167
|
+
FreeBusyCollection.new(
|
168
|
+
api: self,
|
169
|
+
emails: emails,
|
170
|
+
start_time: start_time.to_i,
|
171
|
+
end_time: end_time.to_i
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
152
175
|
private
|
153
176
|
|
154
177
|
def prevent_calling_if_missing_access_token(method_name)
|
data/lib/nylas/collection.rb
CHANGED
@@ -4,6 +4,7 @@ module Nylas
|
|
4
4
|
# An enumerable for working with index and search endpoints
|
5
5
|
class Collection
|
6
6
|
attr_accessor :model, :api, :constraints
|
7
|
+
|
7
8
|
extend Forwardable
|
8
9
|
def_delegators :each, :map, :select, :reject, :to_a, :take
|
9
10
|
def_delegators :to_a, :first, :last, :[]
|
@@ -20,7 +21,7 @@ module Nylas
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def create(**attributes)
|
23
|
-
instance = model.new(attributes.merge(api: api))
|
24
|
+
instance = model.new(**attributes.merge(api: api))
|
24
25
|
instance.save
|
25
26
|
instance
|
26
27
|
end
|
@@ -68,7 +69,7 @@ module Nylas
|
|
68
69
|
return enum_for(:each) unless block_given?
|
69
70
|
|
70
71
|
execute.each do |result|
|
71
|
-
yield(model.new(result.merge(api: api)))
|
72
|
+
yield(model.new(**result.merge(api: api)))
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -118,7 +119,7 @@ module Nylas
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def find_raw(id)
|
121
|
-
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
|
122
123
|
end
|
123
124
|
|
124
125
|
def resources_path
|
@@ -126,9 +127,13 @@ module Nylas
|
|
126
127
|
end
|
127
128
|
|
128
129
|
def find_model(id)
|
129
|
-
|
130
|
-
|
131
|
-
|
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)
|
132
137
|
end
|
133
138
|
|
134
139
|
# @return [Hash] Specification for request to be passed to {API#execute}
|
@@ -140,7 +145,17 @@ module Nylas
|
|
140
145
|
# Retrieves the data from the API for the particular constraints
|
141
146
|
# @return [Hash,Array]
|
142
147
|
def execute
|
143
|
-
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
|
144
159
|
end
|
145
160
|
end
|
146
161
|
end
|
data/lib/nylas/constraints.rb
CHANGED
@@ -4,6 +4,7 @@ module Nylas
|
|
4
4
|
# The constraints a particular GET request will include in their query params
|
5
5
|
class Constraints
|
6
6
|
attr_accessor :where, :limit, :offset, :view, :per_page, :accept
|
7
|
+
|
7
8
|
def initialize(where: {}, limit: nil, offset: 0, view: nil, per_page: 100, accept: "application/json")
|
8
9
|
self.where = where
|
9
10
|
self.limit = limit
|
@@ -4,6 +4,7 @@ module Nylas
|
|
4
4
|
# Special collection for delta objects
|
5
5
|
class DeltasCollection < Collection
|
6
6
|
attr_accessor :deltas
|
7
|
+
|
7
8
|
extend Forwardable
|
8
9
|
def_delegators :execute, :cursor_start, :cursor_end,
|
9
10
|
:count, :each, :to_h, :to_a, :empty?
|
@@ -33,7 +34,7 @@ module Nylas
|
|
33
34
|
# Retrieves the data from the API for the particular constraints
|
34
35
|
# @return [Detlas]
|
35
36
|
def execute
|
36
|
-
self.deltas ||= Deltas.new(api.execute(to_be_executed))
|
37
|
+
self.deltas ||= Deltas.new(**api.execute(**to_be_executed))
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
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
@@ -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, exclude_when: %i[saving]
|
13
|
+
attribute :object, :string, exclude_when: %i[saving]
|
14
|
+
attribute :account_id, :string, exclude_when: %i[saving]
|
15
15
|
attribute :calendar_id, :string
|
16
16
|
attribute :master_event_id, :string
|
17
17
|
attribute :message_id, :string
|
@@ -29,6 +29,8 @@ module Nylas
|
|
29
29
|
attribute :when, :when
|
30
30
|
attribute :original_start_time, :unix_timestamp
|
31
31
|
|
32
|
+
attr_accessor :notify_participants
|
33
|
+
|
32
34
|
def busy?
|
33
35
|
busy
|
34
36
|
end
|
@@ -42,5 +44,17 @@ module Nylas
|
|
42
44
|
event_id: id, account_id: account_id)
|
43
45
|
rsvp.save
|
44
46
|
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def query_params
|
51
|
+
if notify_participants.nil?
|
52
|
+
{}
|
53
|
+
else
|
54
|
+
{
|
55
|
+
notify_participants: notify_participants
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
45
59
|
end
|
46
60
|
end
|
data/lib/nylas/file.rb
CHANGED
@@ -18,8 +18,10 @@ 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
|
24
|
+
|
23
25
|
# Downloads and caches a local copy of the file.
|
24
26
|
# @return [Tempfile] - Local copy of the file
|
25
27
|
def download
|
@@ -56,7 +58,9 @@ module Nylas
|
|
56
58
|
def retrieve_file
|
57
59
|
response = api.get(path: "#{resource_path}/download")
|
58
60
|
filename = response.headers.fetch(:content_disposition, "").gsub("attachment; filename=", "")
|
59
|
-
|
61
|
+
# The returned filename can be longer than 256 chars which isn't supported by rb_sysopen.
|
62
|
+
# 128 chars here is more than enough given that TempFile ensure the filename will be unique.
|
63
|
+
temp_file = Tempfile.new(filename[0..127], encoding: "ascii-8bit")
|
60
64
|
temp_file.write(response.body)
|
61
65
|
temp_file.seek(0)
|
62
66
|
temp_file
|
@@ -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
|
data/lib/nylas/http_client.rb
CHANGED
@@ -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 = {
|
@@ -27,6 +31,7 @@ module Nylas
|
|
27
31
|
"/delta/longpoll" => 3650,
|
28
32
|
"/delta/streaming" => 3650
|
29
33
|
}.freeze
|
34
|
+
SUPPORTED_API_VERSION = "2.2"
|
30
35
|
|
31
36
|
include Logging
|
32
37
|
attr_accessor :api_server, :service_domain
|
@@ -82,7 +87,14 @@ module Nylas
|
|
82
87
|
timeout: timeout
|
83
88
|
)
|
84
89
|
rest_client_execute(**request) do |response, _request, result|
|
85
|
-
|
90
|
+
content_type = nil
|
91
|
+
|
92
|
+
if response.headers && response.headers[:content_type]
|
93
|
+
content_type = response.headers[:content_type].downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
response = parse_response(response) if content_type == "application/json"
|
97
|
+
|
86
98
|
handle_failed_response(result: result, response: response)
|
87
99
|
response
|
88
100
|
end
|
@@ -126,6 +138,7 @@ module Nylas
|
|
126
138
|
@default_headers ||= {
|
127
139
|
"X-Nylas-API-Wrapper" => "ruby",
|
128
140
|
"X-Nylas-Client-Id" => @app_id,
|
141
|
+
"Nylas-API-Version" => SUPPORTED_API_VERSION,
|
129
142
|
"User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
|
130
143
|
"Content-types" => "application/json"
|
131
144
|
}
|
@@ -136,6 +149,8 @@ module Nylas
|
|
136
149
|
|
137
150
|
json = StringIO.new(response)
|
138
151
|
Yajl::Parser.new(symbolize_names: true).parse(json)
|
152
|
+
rescue Yajl::ParseError
|
153
|
+
raise Nylas::JsonParseError
|
139
154
|
end
|
140
155
|
inform_on :parse_response, level: :debug, also_log: { result: true }
|
141
156
|
|
data/lib/nylas/logging.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# We are explicitely choosing to allow clients to use or not use informed at their discretion
|
4
|
-
# rubocop:disable Lint/HandleExceptions
|
5
3
|
begin
|
6
4
|
require "informed"
|
7
5
|
rescue LoadError
|
8
6
|
end
|
9
|
-
# rubocop:enable Lint/HandleExceptions
|
10
7
|
|
11
8
|
module Nylas
|
12
9
|
# Exposes a shared logger for debugging purposes
|
data/lib/nylas/message.rb
CHANGED
@@ -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,7 @@ 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
70
|
self
|
71
71
|
end
|
72
72
|
|
data/lib/nylas/model.rb
CHANGED
@@ -39,28 +39,38 @@ module Nylas
|
|
39
39
|
!id.nil?
|
40
40
|
end
|
41
41
|
|
42
|
-
def execute(method:, payload: nil, path:)
|
43
|
-
api.execute(method: method, payload: payload, path: path)
|
42
|
+
def execute(method:, payload: nil, path:, query: {})
|
43
|
+
api.execute(method: method, payload: payload, path: path, query: query)
|
44
44
|
end
|
45
45
|
|
46
46
|
def create
|
47
47
|
raise ModelNotCreatableError, self unless creatable?
|
48
48
|
|
49
|
-
execute(
|
49
|
+
execute(
|
50
|
+
method: :post,
|
51
|
+
payload: attributes.serialize,
|
52
|
+
path: resources_path,
|
53
|
+
query: query_params
|
54
|
+
)
|
50
55
|
end
|
51
56
|
|
52
57
|
def update(**data)
|
53
58
|
raise ModelNotUpdatableError, model_class unless updatable?
|
54
59
|
|
55
60
|
attributes.merge(**data)
|
56
|
-
execute(
|
61
|
+
execute(
|
62
|
+
method: :put,
|
63
|
+
payload: attributes.serialize(keys: data.keys),
|
64
|
+
path: resource_path,
|
65
|
+
query: query_params
|
66
|
+
)
|
57
67
|
true
|
58
68
|
rescue Registry::MissingKeyError => e
|
59
69
|
raise ModelMissingFieldError.new(e.key, self)
|
60
70
|
end
|
61
71
|
|
62
72
|
def reload
|
63
|
-
assign(execute(method: :get, path: resource_path))
|
73
|
+
assign(**execute(method: :get, path: resource_path))
|
64
74
|
true
|
65
75
|
end
|
66
76
|
|
@@ -75,7 +85,7 @@ module Nylas
|
|
75
85
|
def destroy
|
76
86
|
raise ModelNotDestroyableError, self unless destroyable?
|
77
87
|
|
78
|
-
execute(method: :delete, path: resource_path)
|
88
|
+
execute(method: :delete, path: resource_path, query: query_params)
|
79
89
|
end
|
80
90
|
|
81
91
|
# @return [String] JSON String of the model.
|
@@ -99,6 +109,10 @@ module Nylas
|
|
99
109
|
)
|
100
110
|
end
|
101
111
|
|
112
|
+
def query_params
|
113
|
+
{}
|
114
|
+
end
|
115
|
+
|
102
116
|
# Allows you to narrow in exactly what kind of model you're working with
|
103
117
|
module ClassMethods
|
104
118
|
attr_accessor :raw_mime_type, :creatable, :showable, :filterable, :searchable, :listable, :updatable,
|
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/raw_message.rb
CHANGED
@@ -4,14 +4,22 @@ module Nylas
|
|
4
4
|
# Allows sending of email with nylas from an rfc822 compatible string
|
5
5
|
class RawMessage
|
6
6
|
attr_accessor :api, :mime_compatible_string
|
7
|
+
|
7
8
|
def initialize(mime_compatible_string, api:)
|
8
9
|
self.api = api
|
9
10
|
self.mime_compatible_string = mime_compatible_string
|
10
11
|
end
|
11
12
|
|
12
13
|
def send!
|
13
|
-
Message.new(api.execute(
|
14
|
-
|
14
|
+
Message.new(**api.execute(
|
15
|
+
method: :post,
|
16
|
+
path: "/send",
|
17
|
+
payload: mime_compatible_string,
|
18
|
+
headers: HEADERS
|
19
|
+
).merge(api: api))
|
15
20
|
end
|
21
|
+
|
22
|
+
HEADERS = { "Content-type" => "message/rfc822" }.freeze
|
23
|
+
private_constant :HEADERS
|
16
24
|
end
|
17
25
|
end
|
data/lib/nylas/registry.rb
CHANGED
data/lib/nylas/thread.rb
CHANGED
@@ -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/types.rb
CHANGED
@@ -24,6 +24,7 @@ module Nylas
|
|
24
24
|
# {Model} or Model-like thing.
|
25
25
|
class ModelType
|
26
26
|
attr_accessor :model
|
27
|
+
|
27
28
|
def initialize(model:)
|
28
29
|
self.model = model
|
29
30
|
end
|
@@ -87,6 +88,7 @@ module Nylas
|
|
87
88
|
|
88
89
|
def serialize(object)
|
89
90
|
return nil if object.nil?
|
91
|
+
|
90
92
|
object.to_i
|
91
93
|
end
|
92
94
|
end
|
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
|
+
version: 5.0.0
|
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-05-07 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
|
@@ -240,7 +226,7 @@ dependencies:
|
|
240
226
|
requirements:
|
241
227
|
- - ">="
|
242
228
|
- !ruby/object:Gem::Version
|
243
|
-
version: '
|
229
|
+
version: '2.0'
|
244
230
|
- - "<"
|
245
231
|
- !ruby/object:Gem::Version
|
246
232
|
version: '3.0'
|
@@ -250,7 +236,7 @@ dependencies:
|
|
250
236
|
requirements:
|
251
237
|
- - ">="
|
252
238
|
- !ruby/object:Gem::Version
|
253
|
-
version: '
|
239
|
+
version: '2.0'
|
254
240
|
- - "<"
|
255
241
|
- !ruby/object:Gem::Version
|
256
242
|
version: '3.0'
|
@@ -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
|
@@ -325,13 +313,14 @@ files:
|
|
325
313
|
- lib/nylas/rsvp.rb
|
326
314
|
- lib/nylas/search_collection.rb
|
327
315
|
- lib/nylas/thread.rb
|
316
|
+
- lib/nylas/time_slot.rb
|
328
317
|
- lib/nylas/timespan.rb
|
329
318
|
- lib/nylas/types.rb
|
330
319
|
- lib/nylas/version.rb
|
331
320
|
- lib/nylas/web_page.rb
|
332
321
|
- lib/nylas/webhook.rb
|
333
322
|
- lib/nylas/when.rb
|
334
|
-
homepage:
|
323
|
+
homepage:
|
335
324
|
licenses:
|
336
325
|
- MIT
|
337
326
|
metadata:
|
@@ -341,7 +330,7 @@ metadata:
|
|
341
330
|
homepage_uri: https://www.nylas.com
|
342
331
|
source_code_uri: https://github.com/nylas/nylas-ruby
|
343
332
|
wiki_uri: https://github.com/nylas/nylas-ruby/wiki
|
344
|
-
post_install_message:
|
333
|
+
post_install_message:
|
345
334
|
rdoc_options: []
|
346
335
|
require_paths:
|
347
336
|
- lib
|
@@ -356,8 +345,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
356
345
|
- !ruby/object:Gem::Version
|
357
346
|
version: '0'
|
358
347
|
requirements: []
|
359
|
-
rubygems_version: 3.
|
360
|
-
signing_key:
|
348
|
+
rubygems_version: 3.1.2
|
349
|
+
signing_key:
|
361
350
|
specification_version: 4
|
362
351
|
summary: Gem for interacting with the Nylas API
|
363
352
|
test_files: []
|