nylas 5.0.0 → 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/contact.rb +2 -2
- data/lib/nylas/delta.rb +6 -1
- data/lib/nylas/deltas.rb +1 -1
- data/lib/nylas/draft.rb +31 -2
- data/lib/nylas/event.rb +4 -3
- data/lib/nylas/http_client.rb +32 -3
- data/lib/nylas/message.rb +2 -2
- data/lib/nylas/model.rb +43 -14
- data/lib/nylas/model/attributable.rb +12 -7
- data/lib/nylas/model/attribute_definition.rb +3 -3
- data/lib/nylas/model/attributes.rb +16 -0
- data/lib/nylas/model/list_attribute_definition.rb +3 -3
- data/lib/nylas/rsvp.rb +6 -2
- data/lib/nylas/version.rb +1 -1
- data/lib/nylas/when.rb +1 -1
- metadata +3 -3
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/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
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,6 +27,7 @@ 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
|
|
32
33
|
attr_accessor :notify_participants
|
data/lib/nylas/http_client.rb
CHANGED
@@ -104,8 +104,8 @@ module Nylas
|
|
104
104
|
also_log: { result: true, values: %i[method url path headers query payload] }
|
105
105
|
|
106
106
|
def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil)
|
107
|
-
headers[:params] = query
|
108
107
|
url ||= url_for_path(path)
|
108
|
+
url = add_query_params_to_url(url, query)
|
109
109
|
resulting_headers = default_headers.merge(headers)
|
110
110
|
{ method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
|
111
111
|
end
|
@@ -178,10 +178,39 @@ module Nylas
|
|
178
178
|
|
179
179
|
def handle_anticipated_failure_mode(http_code:, response:)
|
180
180
|
return if http_code == 200
|
181
|
-
return unless response.is_a?(Hash)
|
182
181
|
|
183
182
|
exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
|
184
|
-
|
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
|
185
214
|
end
|
186
215
|
end
|
187
216
|
end
|
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]
|
@@ -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
@@ -48,7 +48,7 @@ module Nylas
|
|
48
48
|
|
49
49
|
execute(
|
50
50
|
method: :post,
|
51
|
-
payload: attributes.
|
51
|
+
payload: attributes.serialize_for_api,
|
52
52
|
path: resources_path,
|
53
53
|
query: query_params
|
54
54
|
)
|
@@ -58,12 +58,37 @@ module Nylas
|
|
58
58
|
raise ModelNotUpdatableError, model_class unless updatable?
|
59
59
|
|
60
60
|
attributes.merge(**data)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
)
|
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
|
+
|
67
92
|
true
|
68
93
|
rescue Registry::MissingKeyError => e
|
69
94
|
raise ModelMissingFieldError.new(e.key, self)
|
@@ -95,20 +120,24 @@ module Nylas
|
|
95
120
|
|
96
121
|
private
|
97
122
|
|
98
|
-
def allowed_keys_for_save
|
99
|
-
attributes.attribute_definitions.to_h.reject do |_k, v|
|
100
|
-
v.exclude_when.include?(:saving)
|
101
|
-
end.keys
|
102
|
-
end
|
103
|
-
|
104
123
|
def save_call
|
105
124
|
execute(
|
106
125
|
method: :put,
|
107
|
-
payload: attributes.
|
126
|
+
payload: attributes.serialize_for_api,
|
108
127
|
path: resource_path
|
109
128
|
)
|
110
129
|
end
|
111
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
|
+
|
112
141
|
def query_params
|
113
142
|
{}
|
114
143
|
end
|
@@ -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,11 +6,11 @@ module Nylas
|
|
6
6
|
class AttributeDefinition
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :type, :cast, :serialize
|
9
|
-
attr_accessor :type_name, :
|
9
|
+
attr_accessor :type_name, :read_only, :default
|
10
10
|
|
11
|
-
def initialize(type_name:,
|
11
|
+
def initialize(type_name:, read_only:, default:)
|
12
12
|
self.type_name = type_name
|
13
|
-
self.
|
13
|
+
self.read_only = read_only
|
14
14
|
self.default = default
|
15
15
|
end
|
16
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/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/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: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nylas, Inc.
|
8
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
|
@@ -345,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
345
345
|
- !ruby/object:Gem::Version
|
346
346
|
version: '0'
|
347
347
|
requirements: []
|
348
|
-
rubygems_version: 3.
|
348
|
+
rubygems_version: 3.2.17
|
349
349
|
signing_key:
|
350
350
|
specification_version: 4
|
351
351
|
summary: Gem for interacting with the Nylas API
|