nylas 4.6.4 → 5.1.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/contact.rb +2 -2
- data/lib/nylas/delta.rb +6 -1
- data/lib/nylas/deltas.rb +1 -1
- data/lib/nylas/deltas_collection.rb +2 -1
- data/lib/nylas/draft.rb +31 -2
- data/lib/nylas/event.rb +18 -3
- data/lib/nylas/file.rb +2 -0
- data/lib/nylas/free_busy.rb +13 -0
- data/lib/nylas/free_busy_collection.rb +48 -0
- data/lib/nylas/http_client.rb +34 -3
- data/lib/nylas/logging.rb +0 -3
- data/lib/nylas/message.rb +4 -4
- data/lib/nylas/model.rb +56 -13
- data/lib/nylas/model/attributable.rb +12 -7
- data/lib/nylas/model/attribute_definition.rb +4 -3
- data/lib/nylas/model/attributes.rb +16 -0
- data/lib/nylas/model/list_attribute_definition.rb +3 -3
- data/lib/nylas/model/transferable.rb +1 -0
- data/lib/nylas/native_authentication.rb +1 -0
- data/lib/nylas/raw_message.rb +10 -2
- data/lib/nylas/registry.rb +1 -0
- data/lib/nylas/rsvp.rb +6 -2
- 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
- data/lib/nylas/when.rb +1 -1
- metadata +10 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2f677958900566f6aeb941f450e9bbe3b4dfd54f57c4cf4b87bb403f968f731
|
4
|
+
data.tar.gz: 5f4eb58cf5835a43a4034229d506d7662923fa110c4fe5e352f9d867ac69b295
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c727f58c5ecaeaca411d346b23d2176f8114f1cc441347326c8c26239f3ef78626007a443f89932fc955c68c295229d238a647cb7f42234f11d31fc0d02ec7e9
|
7
|
+
data.tar.gz: e1ce86d59fcdc7c7193688faf95833978e106fb5e0ea5166f009f9f06234e9a724e363b21133b6636c14398e4dcc177853347b13a5c821af765deaf5900a0cc4
|
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
|
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,
|
16
|
+
attribute :id, :string, read_only: true
|
17
17
|
attribute :object, :string, default: "contact"
|
18
|
-
attribute :account_id, :string,
|
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
@@ -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
@@ -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.
|
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,8 +27,11 @@ 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
|
|
33
|
+
attr_accessor :notify_participants
|
34
|
+
|
32
35
|
def busy?
|
33
36
|
busy
|
34
37
|
end
|
@@ -42,5 +45,17 @@ module Nylas
|
|
42
45
|
event_id: id, account_id: account_id)
|
43
46
|
rsvp.save
|
44
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def query_params
|
52
|
+
if notify_participants.nil?
|
53
|
+
{}
|
54
|
+
else
|
55
|
+
{
|
56
|
+
notify_participants: notify_participants
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
45
60
|
end
|
46
61
|
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
|
@@ -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
@@ -31,6 +31,7 @@ module Nylas
|
|
31
31
|
"/delta/longpoll" => 3650,
|
32
32
|
"/delta/streaming" => 3650
|
33
33
|
}.freeze
|
34
|
+
SUPPORTED_API_VERSION = "2.2"
|
34
35
|
|
35
36
|
include Logging
|
36
37
|
attr_accessor :api_server, :service_domain
|
@@ -103,8 +104,8 @@ module Nylas
|
|
103
104
|
also_log: { result: true, values: %i[method url path headers query payload] }
|
104
105
|
|
105
106
|
def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil)
|
106
|
-
headers[:params] = query
|
107
107
|
url ||= url_for_path(path)
|
108
|
+
url = add_query_params_to_url(url, query)
|
108
109
|
resulting_headers = default_headers.merge(headers)
|
109
110
|
{ method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
|
110
111
|
end
|
@@ -137,6 +138,7 @@ module Nylas
|
|
137
138
|
@default_headers ||= {
|
138
139
|
"X-Nylas-API-Wrapper" => "ruby",
|
139
140
|
"X-Nylas-Client-Id" => @app_id,
|
141
|
+
"Nylas-API-Version" => SUPPORTED_API_VERSION,
|
140
142
|
"User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
|
141
143
|
"Content-types" => "application/json"
|
142
144
|
}
|
@@ -176,10 +178,39 @@ module Nylas
|
|
176
178
|
|
177
179
|
def handle_anticipated_failure_mode(http_code:, response:)
|
178
180
|
return if http_code == 200
|
179
|
-
return unless response.is_a?(Hash)
|
180
181
|
|
181
182
|
exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
|
182
|
-
|
183
|
+
parsed_response = parse_response(response)
|
184
|
+
|
185
|
+
raise exception.new(
|
186
|
+
parsed_response[:type],
|
187
|
+
parsed_response[:message],
|
188
|
+
parsed_response.fetch(:server_error, nil)
|
189
|
+
)
|
190
|
+
end
|
191
|
+
|
192
|
+
def add_query_params_to_url(url, query)
|
193
|
+
unless query.empty?
|
194
|
+
uri = URI.parse(url)
|
195
|
+
query = custom_params(query)
|
196
|
+
params = URI.decode_www_form(uri.query || "") + query.to_a
|
197
|
+
uri.query = URI.encode_www_form(params)
|
198
|
+
url = uri.to_s
|
199
|
+
end
|
200
|
+
|
201
|
+
url
|
202
|
+
end
|
203
|
+
|
204
|
+
def custom_params(query)
|
205
|
+
# Convert hash to "<key>:<value>" form for metadata_pair query
|
206
|
+
if query.key?(:metadata_pair)
|
207
|
+
pairs = query[:metadata_pair].map do |key, value|
|
208
|
+
"#{key}:#{value}"
|
209
|
+
end
|
210
|
+
query[:metadata_pair] = pairs
|
211
|
+
end
|
212
|
+
|
213
|
+
query
|
183
214
|
end
|
184
215
|
end
|
185
216
|
end
|
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
@@ -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,
|
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,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
|
|
@@ -75,7 +75,7 @@ module Nylas
|
|
75
75
|
|
76
76
|
execute(
|
77
77
|
method: :put,
|
78
|
-
payload: attributes.
|
78
|
+
payload: attributes.serialize_for_api,
|
79
79
|
path: resource_path
|
80
80
|
)
|
81
81
|
end
|
data/lib/nylas/model.rb
CHANGED
@@ -39,28 +39,63 @@ 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_for_api,
|
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
|
-
|
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
|
+
|
57
92
|
true
|
58
93
|
rescue Registry::MissingKeyError => e
|
59
94
|
raise ModelMissingFieldError.new(e.key, self)
|
60
95
|
end
|
61
96
|
|
62
97
|
def reload
|
63
|
-
assign(execute(method: :get, path: resource_path))
|
98
|
+
assign(**execute(method: :get, path: resource_path))
|
64
99
|
true
|
65
100
|
end
|
66
101
|
|
@@ -75,7 +110,7 @@ module Nylas
|
|
75
110
|
def destroy
|
76
111
|
raise ModelNotDestroyableError, self unless destroyable?
|
77
112
|
|
78
|
-
execute(method: :delete, path: resource_path)
|
113
|
+
execute(method: :delete, path: resource_path, query: query_params)
|
79
114
|
end
|
80
115
|
|
81
116
|
# @return [String] JSON String of the model.
|
@@ -85,20 +120,28 @@ module Nylas
|
|
85
120
|
|
86
121
|
private
|
87
122
|
|
88
|
-
def allowed_keys_for_save
|
89
|
-
attributes.attribute_definitions.to_h.reject do |_k, v|
|
90
|
-
v.exclude_when.include?(:saving)
|
91
|
-
end.keys
|
92
|
-
end
|
93
|
-
|
94
123
|
def save_call
|
95
124
|
execute(
|
96
125
|
method: :put,
|
97
|
-
payload: attributes.
|
126
|
+
payload: attributes.serialize_for_api,
|
98
127
|
path: resource_path
|
99
128
|
)
|
100
129
|
end
|
101
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
|
+
|
141
|
+
def query_params
|
142
|
+
{}
|
143
|
+
end
|
144
|
+
|
102
145
|
# Allows you to narrow in exactly what kind of model you're working with
|
103
146
|
module ClassMethods
|
104
147
|
attr_accessor :raw_mime_type, :creatable, :showable, :filterable, :searchable, :listable, :updatable,
|
@@ -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,
|
38
|
-
attribute_definitions[name] = ListAttributeDefinition.new(
|
39
|
-
|
40
|
-
|
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,
|
46
|
-
attribute_definitions[name] = AttributeDefinition.new(
|
47
|
-
|
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,10 +6,11 @@ module Nylas
|
|
6
6
|
class AttributeDefinition
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :type, :cast, :serialize
|
9
|
-
attr_accessor :type_name, :
|
10
|
-
|
9
|
+
attr_accessor :type_name, :read_only, :default
|
10
|
+
|
11
|
+
def initialize(type_name:, read_only:, default:)
|
11
12
|
self.type_name = type_name
|
12
|
-
self.
|
13
|
+
self.read_only = read_only
|
13
14
|
self.default = default
|
14
15
|
end
|
15
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, :
|
7
|
+
attr_accessor :type_name, :read_only, :default
|
8
8
|
|
9
|
-
def initialize(type_name:,
|
9
|
+
def initialize(type_name:, read_only:, default:)
|
10
10
|
self.type_name = type_name
|
11
|
-
self.
|
11
|
+
self.read_only = read_only
|
12
12
|
self.default = default
|
13
13
|
end
|
14
14
|
|
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/rsvp.rb
CHANGED
@@ -13,8 +13,12 @@ module Nylas
|
|
13
13
|
attr_accessor :notify_participants
|
14
14
|
|
15
15
|
def save
|
16
|
-
api.execute(
|
17
|
-
|
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
@@ -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
data/lib/nylas/when.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.1.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: 2021-
|
11
|
+
date: 2021-06-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
|
@@ -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.2.
|
360
|
-
signing_key:
|
348
|
+
rubygems_version: 3.2.17
|
349
|
+
signing_key:
|
361
350
|
specification_version: 4
|
362
351
|
summary: Gem for interacting with the Nylas API
|
363
352
|
test_files: []
|