nylas 4.2.4 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/nylas.rb +2 -0
- data/lib/nylas/account.rb +9 -0
- data/lib/nylas/api.rb +15 -7
- data/lib/nylas/calendar.rb +2 -0
- data/lib/nylas/collection.rb +9 -0
- data/lib/nylas/constraints.rb +4 -3
- data/lib/nylas/contact.rb +3 -0
- data/lib/nylas/contact_group.rb +2 -0
- data/lib/nylas/current_account.rb +2 -0
- data/lib/nylas/delta.rb +3 -0
- data/lib/nylas/deltas.rb +2 -0
- data/lib/nylas/deltas_collection.rb +3 -0
- data/lib/nylas/draft.rb +3 -1
- data/lib/nylas/email_address.rb +2 -0
- data/lib/nylas/errors.rb +2 -0
- data/lib/nylas/event.rb +2 -0
- data/lib/nylas/event_collection.rb +2 -0
- data/lib/nylas/file.rb +8 -1
- data/lib/nylas/folder.rb +2 -0
- data/lib/nylas/http_client.rb +40 -15
- data/lib/nylas/im_address.rb +2 -0
- data/lib/nylas/label.rb +2 -0
- data/lib/nylas/logging.rb +3 -0
- data/lib/nylas/message.rb +10 -1
- data/lib/nylas/message_headers.rb +2 -0
- data/lib/nylas/message_tracking.rb +2 -0
- data/lib/nylas/model.rb +6 -2
- data/lib/nylas/model/attributable.rb +3 -1
- data/lib/nylas/model/attribute_definition.rb +5 -1
- data/lib/nylas/model/attributes.rb +11 -7
- data/lib/nylas/model/list_attribute_definition.rb +3 -0
- data/lib/nylas/native_authentication.rb +12 -5
- data/lib/nylas/new_message.rb +2 -0
- data/lib/nylas/nylas_date.rb +2 -0
- data/lib/nylas/participant.rb +2 -0
- data/lib/nylas/phone_number.rb +2 -0
- data/lib/nylas/physical_address.rb +2 -0
- data/lib/nylas/raw_message.rb +2 -0
- data/lib/nylas/recurrence.rb +2 -0
- data/lib/nylas/registry.rb +2 -0
- data/lib/nylas/rsvp.rb +2 -0
- data/lib/nylas/search_collection.rb +2 -0
- data/lib/nylas/thread.rb +2 -0
- data/lib/nylas/timespan.rb +2 -0
- data/lib/nylas/types.rb +9 -0
- data/lib/nylas/version.rb +3 -1
- data/lib/nylas/web_page.rb +2 -0
- data/lib/nylas/webhook.rb +2 -0
- metadata +23 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4701f3dfdc9be923e70af2eb5540f82b0ff68904427596be7fa5239ea4bad41a
|
4
|
+
data.tar.gz: 3db7ec170cca6ed5060a66b60cb8b18e77811b5ffe7b6fc79d5be5396978dc23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 273fdaeb3e5389b57d5abb82d3a7c402dfb109973dc4e663fa5ab59d7c0412ea1ecf2b171a419cbe46ea0d9eac8a9ff4b0d31422d2ae119d44167333bf37992d
|
7
|
+
data.tar.gz: b89255b00a7fa491061c110e7687e275880456e4e65c131ace84b2f4ee8e040cf8e133dc50b48939de53f85a9898020b6a9bedd1e110e8767b87c0b1b5ce440e
|
data/lib/nylas.rb
CHANGED
data/lib/nylas/account.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Representation of the accounts for Account management purposes.
|
3
5
|
# @see https://docs.nylas.com/reference#account-management
|
@@ -24,6 +26,13 @@ module Nylas
|
|
24
26
|
response[:success]
|
25
27
|
end
|
26
28
|
|
29
|
+
def revoke_all(keep_access_token: nil)
|
30
|
+
payload = JSON.dump(keep_access_token: keep_access_token) if keep_access_token
|
31
|
+
|
32
|
+
response = execute(method: :post, path: "#{resource_path}/revoke-all", payload: payload)
|
33
|
+
response[:success]
|
34
|
+
end
|
35
|
+
|
27
36
|
def self.resources_path(api:)
|
28
37
|
"/a/#{api.app_id}/accounts"
|
29
38
|
end
|
data/lib/nylas/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Methods to retrieve data from the Nylas API as Ruby objects
|
3
5
|
class API
|
@@ -15,20 +17,23 @@ module Nylas
|
|
15
17
|
# you're using a self-hosted Nylas instance.
|
16
18
|
# @param service_domain [String] (Optional) Host you are authenticating OAuth against.
|
17
19
|
# @return [Nylas::API]
|
18
|
-
# rubocop:disable Metrics/ParameterLists
|
19
20
|
def initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil,
|
20
21
|
api_server: "https://api.nylas.com", service_domain: "api.nylas.com")
|
21
22
|
self.client = client || HttpClient.new(app_id: app_id, app_secret: app_secret,
|
22
23
|
access_token: access_token, api_server: api_server,
|
23
24
|
service_domain: service_domain)
|
24
25
|
end
|
25
|
-
# rubocop:enable Metrics/ParameterLists
|
26
26
|
|
27
27
|
# @return [String] A Nylas access token for that particular user.
|
28
|
-
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil)
|
29
|
-
NativeAuthentication.new(api: self).authenticate(
|
30
|
-
|
31
|
-
|
28
|
+
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil, scopes: nil)
|
29
|
+
NativeAuthentication.new(api: self).authenticate(
|
30
|
+
name: name,
|
31
|
+
email_address: email_address,
|
32
|
+
provider: provider,
|
33
|
+
settings: settings,
|
34
|
+
reauth_account_id: reauth_account_id,
|
35
|
+
scopes: scopes
|
36
|
+
)
|
32
37
|
end
|
33
38
|
|
34
39
|
# @return [Collection<Contact>] A queryable collection of Contacts
|
@@ -119,8 +124,11 @@ module Nylas
|
|
119
124
|
@webhooks ||= Collection.new(model: Webhook, api: as(client.app_secret))
|
120
125
|
end
|
121
126
|
|
122
|
-
private
|
127
|
+
private
|
128
|
+
|
129
|
+
def prevent_calling_if_missing_access_token(method_name)
|
123
130
|
return if client.access_token && !client.access_token.empty?
|
131
|
+
|
124
132
|
raise NoAuthToken, method_name
|
125
133
|
end
|
126
134
|
end
|
data/lib/nylas/calendar.rb
CHANGED
data/lib/nylas/collection.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# An enumerable for working with index and search endpoints
|
3
5
|
class Collection
|
@@ -27,11 +29,13 @@ module Nylas
|
|
27
29
|
# @return [Collection<Model>]
|
28
30
|
def where(filters)
|
29
31
|
raise ModelNotFilterableError, model unless model.filterable?
|
32
|
+
|
30
33
|
self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
|
31
34
|
end
|
32
35
|
|
33
36
|
def search(query)
|
34
37
|
raise ModelNotSearchableError, model unless model.searchable?
|
38
|
+
|
35
39
|
SearchCollection.new(model: model, api: api, constraints: constraints.merge(where: { q: query }))
|
36
40
|
end
|
37
41
|
|
@@ -40,6 +44,7 @@ module Nylas
|
|
40
44
|
# @return [Collection<String>]
|
41
45
|
def raw
|
42
46
|
raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw?
|
47
|
+
|
43
48
|
self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type))
|
44
49
|
end
|
45
50
|
|
@@ -61,6 +66,7 @@ module Nylas
|
|
61
66
|
# Iterates over a single page of results based upon current pagination settings
|
62
67
|
def each
|
63
68
|
return enum_for(:each) unless block_given?
|
69
|
+
|
64
70
|
execute.each do |result|
|
65
71
|
yield(model.new(result.merge(api: api)))
|
66
72
|
end
|
@@ -77,6 +83,7 @@ module Nylas
|
|
77
83
|
# Iterates over every result that meets the filters, retrieving a page at a time
|
78
84
|
def find_each
|
79
85
|
return enum_for(:find_each) unless block_given?
|
86
|
+
|
80
87
|
query = self
|
81
88
|
accumulated = 0
|
82
89
|
|
@@ -92,6 +99,7 @@ module Nylas
|
|
92
99
|
|
93
100
|
def next_page(accumulated:, current_page:)
|
94
101
|
return nil unless more_pages?(accumulated, current_page)
|
102
|
+
|
95
103
|
self.class.new(model: model, api: api, constraints: constraints.next_page)
|
96
104
|
end
|
97
105
|
|
@@ -99,6 +107,7 @@ module Nylas
|
|
99
107
|
return false if current_page.empty?
|
100
108
|
return false if constraints.limit && accumulated >= constraints.limit
|
101
109
|
return false if constraints.per_page && current_page.length < constraints.per_page
|
110
|
+
|
102
111
|
true
|
103
112
|
end
|
104
113
|
|
data/lib/nylas/constraints.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# The constraints a particular GET request will include in their query params
|
3
5
|
class Constraints
|
4
6
|
attr_accessor :where, :limit, :offset, :view, :per_page, :accept
|
5
|
-
# rubocop:disable Metrics/ParameterLists
|
6
7
|
def initialize(where: {}, limit: nil, offset: 0, view: nil, per_page: 100, accept: "application/json")
|
7
8
|
self.where = where
|
8
9
|
self.limit = limit
|
@@ -13,14 +14,13 @@ module Nylas
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def merge(where: {}, limit: nil, offset: nil, view: nil, per_page: nil, accept: nil)
|
16
|
-
Constraints.new(where: where.merge(where),
|
17
|
+
Constraints.new(where: self.where.merge(where),
|
17
18
|
limit: limit || self.limit,
|
18
19
|
per_page: per_page || self.per_page,
|
19
20
|
offset: offset || self.offset,
|
20
21
|
view: view || self.view,
|
21
22
|
accept: accept || self.accept)
|
22
23
|
end
|
23
|
-
# rubocop:enable Metrics/ParameterLists
|
24
24
|
|
25
25
|
def next_page
|
26
26
|
merge(offset: offset + per_page)
|
@@ -48,6 +48,7 @@ module Nylas
|
|
48
48
|
return constraints if constraints.is_a?(Constraints)
|
49
49
|
return new(**constraints) if constraints.respond_to?(:key?)
|
50
50
|
return new if constraints.nil?
|
51
|
+
|
51
52
|
raise TypeError, "passed in constraints #{constraints} cannot be cast to a set of constraints"
|
52
53
|
end
|
53
54
|
end
|
data/lib/nylas/contact.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# ActiveModel compliant interface for interacting with the Contacts API
|
3
5
|
# @see https://docs.nylas.com/reference#contacts
|
@@ -40,6 +42,7 @@ module Nylas
|
|
40
42
|
# to retrieve it from nylas every time.
|
41
43
|
def picture
|
42
44
|
return @picture_tempfile if @picture_tempfile
|
45
|
+
|
43
46
|
@picture_tempfile = Tempfile.new
|
44
47
|
@picture_tempfile.write(api.get(path: "#{resource_path}/picture"))
|
45
48
|
@picture_tempfile.close
|
data/lib/nylas/contact_group.rb
CHANGED
data/lib/nylas/delta.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Ruby object to represent a single change. Used both when receiving a webhook, as well as the deltas API.
|
3
5
|
# @see https://docs.nylas.com/reference#receiving-notifications
|
@@ -18,6 +20,7 @@ module Nylas
|
|
18
20
|
|
19
21
|
def model
|
20
22
|
return nil if object.nil?
|
23
|
+
|
21
24
|
@model ||= Types.registry[object.to_sym].cast(object_attributes_with_ids)
|
22
25
|
end
|
23
26
|
|
data/lib/nylas/deltas.rb
CHANGED
data/lib/nylas/draft.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Ruby representatin of a Nylas Draft object
|
3
5
|
# @see https://docs.nylas.com/reference#drafts
|
@@ -28,7 +30,7 @@ module Nylas
|
|
28
30
|
|
29
31
|
has_n_of_attribute :events, :event
|
30
32
|
has_n_of_attribute :files, :file
|
31
|
-
attribute :folder, :
|
33
|
+
attribute :folder, :folder
|
32
34
|
has_n_of_attribute :labels, :label
|
33
35
|
|
34
36
|
def send!
|
data/lib/nylas/email_address.rb
CHANGED
data/lib/nylas/errors.rb
CHANGED
data/lib/nylas/event.rb
CHANGED
data/lib/nylas/file.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Structure to represent a the File Schema.
|
3
5
|
# @see https://docs.nylas.com/reference#events
|
@@ -22,12 +24,14 @@ module Nylas
|
|
22
24
|
# @return [Tempfile] - Local copy of the file
|
23
25
|
def download
|
24
26
|
return file if file
|
27
|
+
|
25
28
|
self.file = retrieve_file
|
26
29
|
end
|
27
30
|
|
28
31
|
# Redownloads a file even if it's been cached. Closes and unlinks the tempfile to help memory usage.
|
29
32
|
def download!
|
30
33
|
return download if file.nil?
|
34
|
+
|
31
35
|
file.close
|
32
36
|
file.unlink
|
33
37
|
self.file = nil
|
@@ -40,13 +44,16 @@ module Nylas
|
|
40
44
|
|
41
45
|
def save
|
42
46
|
raise ModelNotUpdatableError if persisted?
|
47
|
+
|
43
48
|
response = api.execute(path: "/files", method: :post, headers: { multipart: true },
|
44
49
|
payload: { file: file })
|
45
50
|
attributes.merge(response.first)
|
46
51
|
true
|
47
52
|
end
|
48
53
|
|
49
|
-
private
|
54
|
+
private
|
55
|
+
|
56
|
+
def retrieve_file
|
50
57
|
response = api.get(path: "#{resource_path}/download")
|
51
58
|
filename = response.headers.fetch(:content_disposition, "").gsub("attachment; filename=", "")
|
52
59
|
temp_file = Tempfile.new(filename)
|
data/lib/nylas/folder.rb
CHANGED
data/lib/nylas/http_client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
|
3
|
-
class HttpClient
|
5
|
+
class HttpClient # rubocop:disable Metrics/ClassLength
|
4
6
|
HTTP_CODE_TO_EXCEPTIONS = {
|
5
7
|
400 => InvalidRequest,
|
6
8
|
402 => MessageRejected,
|
@@ -15,6 +17,15 @@ module Nylas
|
|
15
17
|
503 => ServiceUnavailable
|
16
18
|
}.freeze
|
17
19
|
|
20
|
+
ENDPOINT_TIMEOUTS = {
|
21
|
+
"/oauth/authorize" => 345,
|
22
|
+
"/messages/search" => 350,
|
23
|
+
"/threads/search" => 350,
|
24
|
+
"/delta" => 3650,
|
25
|
+
"/delta/longpoll" => 3650,
|
26
|
+
"/delta/streaming" => 3650
|
27
|
+
}.freeze
|
28
|
+
|
18
29
|
include Logging
|
19
30
|
attr_accessor :api_server, :service_domain
|
20
31
|
attr_writer :default_headers
|
@@ -34,6 +45,7 @@ module Nylas
|
|
34
45
|
unless api_server.include?("://")
|
35
46
|
raise "When overriding the Nylas API server address, you must include https://"
|
36
47
|
end
|
48
|
+
|
37
49
|
@api_server = api_server
|
38
50
|
@access_token = access_token
|
39
51
|
@app_secret = app_secret
|
@@ -56,24 +68,33 @@ module Nylas
|
|
56
68
|
# section of the URI fragment
|
57
69
|
# @param payload [String,Hash] (Optional, defaults to nil) - Body to send with the request.
|
58
70
|
# @return [Array Hash Stringn]
|
71
|
+
# rubocop:disable Metrics/MethodLength
|
59
72
|
def execute(method:, path: nil, headers: {}, query: {}, payload: nil)
|
60
|
-
|
73
|
+
timeout = ENDPOINT_TIMEOUTS.fetch(path, 230)
|
74
|
+
request = build_request(
|
75
|
+
method: method,
|
76
|
+
path: path,
|
77
|
+
headers: headers,
|
78
|
+
query: query,
|
79
|
+
payload: payload,
|
80
|
+
timeout: timeout
|
81
|
+
)
|
61
82
|
rest_client_execute(**request) do |response, _request, result|
|
62
83
|
response = parse_response(response)
|
63
84
|
handle_failed_response(result: result, response: response)
|
64
85
|
response
|
65
86
|
end
|
66
87
|
end
|
88
|
+
# rubocop:enable Metrics/MethodLength
|
67
89
|
inform_on :execute, level: :debug,
|
68
90
|
also_log: { result: true, values: %i[method url path headers query payload] }
|
69
91
|
|
70
|
-
def build_request(method:, path: nil, headers: {}, query: {}, payload: nil)
|
92
|
+
def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil)
|
71
93
|
headers[:params] = query
|
72
94
|
url ||= url_for_path(path)
|
73
95
|
resulting_headers = default_headers.merge(headers)
|
74
|
-
{ method: method, url: url, payload: payload, headers: resulting_headers }
|
96
|
+
{ method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
|
75
97
|
end
|
76
|
-
# rubocop:enable Metrics/ParameterLists
|
77
98
|
|
78
99
|
# Syntactical sugar for making GET requests via the API.
|
79
100
|
# @see #execute
|
@@ -98,18 +119,11 @@ module Nylas
|
|
98
119
|
def delete(path: nil, payload: nil, headers: {}, query: {})
|
99
120
|
execute(method: :delete, path: path, headers: headers, query: query, payload: payload)
|
100
121
|
end
|
101
|
-
# rubocop:enable Metrics/ParameterList
|
102
|
-
|
103
|
-
private def rest_client_execute(method:, url:, headers:, payload:, &block)
|
104
|
-
::RestClient::Request.execute(method: method, url: url, payload: payload,
|
105
|
-
headers: headers, &block)
|
106
|
-
end
|
107
|
-
inform_on :rest_client_execute, level: :debug,
|
108
|
-
also_log: { result: true, values: %i[method url headers payload] }
|
109
122
|
|
110
123
|
def default_headers
|
111
124
|
@default_headers ||= {
|
112
125
|
"X-Nylas-API-Wrapper" => "ruby",
|
126
|
+
"X-Nylas-Client-Id" => @app_id,
|
113
127
|
"User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
|
114
128
|
"Content-types" => "application/json"
|
115
129
|
}
|
@@ -127,16 +141,27 @@ module Nylas
|
|
127
141
|
"#{protocol}//#{access_token}:@#{domain}#{path}"
|
128
142
|
end
|
129
143
|
|
130
|
-
private
|
144
|
+
private
|
145
|
+
|
146
|
+
def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block)
|
147
|
+
::RestClient::Request.execute(method: method, url: url, payload: payload,
|
148
|
+
headers: headers, timeout: timeout, &block)
|
149
|
+
end
|
150
|
+
|
151
|
+
inform_on :rest_client_execute, level: :debug,
|
152
|
+
also_log: { result: true, values: %i[method url headers payload] }
|
153
|
+
|
154
|
+
def handle_failed_response(result:, response:)
|
131
155
|
http_code = result.code.to_i
|
132
156
|
|
133
157
|
handle_anticipated_failure_mode(http_code: http_code, response: response)
|
134
158
|
raise UnexpectedResponse, result.msg if result.is_a?(Net::HTTPClientError)
|
135
159
|
end
|
136
160
|
|
137
|
-
|
161
|
+
def handle_anticipated_failure_mode(http_code:, response:)
|
138
162
|
return if http_code == 200
|
139
163
|
return unless response.is_a?(Hash)
|
164
|
+
|
140
165
|
exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
|
141
166
|
raise exception.new(response[:type], response[:message], response.fetch(:server_error, nil))
|
142
167
|
end
|
data/lib/nylas/im_address.rb
CHANGED
data/lib/nylas/label.rb
CHANGED
data/lib/nylas/logging.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# We are explicitely choosing to allow clients to use or not use informed at their discretion
|
2
4
|
# rubocop:disable Lint/HandleExceptions
|
3
5
|
begin
|
@@ -20,6 +22,7 @@ module Nylas
|
|
20
22
|
|
21
23
|
def self.logger
|
22
24
|
return @logger if @logger
|
25
|
+
|
23
26
|
@logger = Logger.new(STDOUT)
|
24
27
|
@logger.level = level
|
25
28
|
@logger
|
data/lib/nylas/message.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Ruby representatin of a Nylas Message object
|
3
5
|
# @see https://docs.nylas.com/reference#messages
|
@@ -31,7 +33,7 @@ module Nylas
|
|
31
33
|
|
32
34
|
has_n_of_attribute :events, :event
|
33
35
|
has_n_of_attribute :files, :file
|
34
|
-
attribute :folder, :
|
36
|
+
attribute :folder, :folder
|
35
37
|
has_n_of_attribute :labels, :label
|
36
38
|
|
37
39
|
def starred?
|
@@ -41,5 +43,12 @@ module Nylas
|
|
41
43
|
def unread?
|
42
44
|
unread
|
43
45
|
end
|
46
|
+
|
47
|
+
def expanded
|
48
|
+
return self unless headers.nil?
|
49
|
+
|
50
|
+
assign(api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
|
51
|
+
self
|
52
|
+
end
|
44
53
|
end
|
45
54
|
end
|
data/lib/nylas/model.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "model/attribute_definition"
|
2
4
|
require_relative "model/list_attribute_definition"
|
3
5
|
require_relative "model/attributable"
|
@@ -23,6 +25,7 @@ module Nylas
|
|
23
25
|
def save
|
24
26
|
result = if persisted?
|
25
27
|
raise ModelNotUpdatableError, self unless updatable?
|
28
|
+
|
26
29
|
execute(method: :put, payload: attributes.serialize, path: resource_path)
|
27
30
|
else
|
28
31
|
create
|
@@ -40,11 +43,13 @@ module Nylas
|
|
40
43
|
|
41
44
|
def create
|
42
45
|
raise ModelNotCreatableError, self unless creatable?
|
46
|
+
|
43
47
|
execute(method: :post, payload: attributes.serialize, path: resources_path)
|
44
48
|
end
|
45
49
|
|
46
50
|
def update(**data)
|
47
51
|
raise ModelNotUpdatableError, model_class unless updatable?
|
52
|
+
|
48
53
|
attributes.merge(**data)
|
49
54
|
execute(method: :put, payload: attributes.serialize(keys: data.keys), path: resource_path)
|
50
55
|
true
|
@@ -67,6 +72,7 @@ module Nylas
|
|
67
72
|
|
68
73
|
def destroy
|
69
74
|
raise ModelNotDestroyableError, self unless destroyable?
|
75
|
+
|
70
76
|
execute(method: :delete, path: resource_path)
|
71
77
|
end
|
72
78
|
|
@@ -81,7 +87,6 @@ module Nylas
|
|
81
87
|
:destroyable
|
82
88
|
attr_writer :resources_path
|
83
89
|
|
84
|
-
# rubocop:disable Metrics/ParameterLists
|
85
90
|
def allows_operations(creatable: false, showable: false, listable: false, filterable: false,
|
86
91
|
searchable: false, updatable: false, destroyable: false)
|
87
92
|
|
@@ -94,7 +99,6 @@ module Nylas
|
|
94
99
|
self.destroyable ||= destroyable
|
95
100
|
end
|
96
101
|
|
97
|
-
# rubocop:enable Metrics/ParameterLists
|
98
102
|
def creatable?
|
99
103
|
creatable
|
100
104
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
module Model
|
3
5
|
# Allows defining of tyypecastable attributes on a model
|
@@ -10,7 +12,7 @@ module Nylas
|
|
10
12
|
assign(**initial_data)
|
11
13
|
end
|
12
14
|
|
13
|
-
protected def assign(**data)
|
15
|
+
protected def assign(**data) # rubocop:disable Style/AccessModifierDeclarations
|
14
16
|
data.each do |attribute_name, value|
|
15
17
|
if respond_to?(:"#{attribute_name}=")
|
16
18
|
send(:"#{attribute_name}=", value)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
module Model
|
3
5
|
# Define a particular attribute for a given model
|
@@ -11,7 +13,9 @@ module Nylas
|
|
11
13
|
self.default = default
|
12
14
|
end
|
13
15
|
|
14
|
-
private
|
16
|
+
private
|
17
|
+
|
18
|
+
def type
|
15
19
|
Types.registry[type_name]
|
16
20
|
end
|
17
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
module Model
|
3
5
|
# Stores the actual model data to allow for type casting and clean/dirty checking
|
@@ -17,12 +19,6 @@ module Nylas
|
|
17
19
|
data[key] = cast(key, value)
|
18
20
|
end
|
19
21
|
|
20
|
-
private def cast(key, value)
|
21
|
-
attribute_definitions[key].cast(value)
|
22
|
-
rescue TypeError => e
|
23
|
-
raise TypeError, "#{key} #{e.message}"
|
24
|
-
end
|
25
|
-
|
26
22
|
# Merges data into the registry while casting input types correctly
|
27
23
|
def merge(new_data)
|
28
24
|
new_data.each do |attribute_name, value|
|
@@ -41,7 +37,15 @@ module Nylas
|
|
41
37
|
JSON.dump(to_h(keys: keys))
|
42
38
|
end
|
43
39
|
|
44
|
-
private
|
40
|
+
private
|
41
|
+
|
42
|
+
def cast(key, value)
|
43
|
+
attribute_definitions[key].cast(value)
|
44
|
+
rescue TypeError => e
|
45
|
+
raise TypeError, "#{key} #{e.message}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_attributes
|
45
49
|
attribute_definitions.keys.zip([]).to_h
|
46
50
|
end
|
47
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
module Model
|
3
5
|
# Allows models to have an attribute which is a lists of another type of thing
|
@@ -12,6 +14,7 @@ module Nylas
|
|
12
14
|
|
13
15
|
def cast(list)
|
14
16
|
return default if list.nil? || list.empty?
|
17
|
+
|
15
18
|
list.map { |item| type.cast(item) }
|
16
19
|
end
|
17
20
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Authenticate your application using the native interface
|
3
5
|
# @see https://docs.nylas.com/reference#native-authentication-1
|
@@ -7,22 +9,27 @@ module Nylas
|
|
7
9
|
self.api = api
|
8
10
|
end
|
9
11
|
|
10
|
-
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil
|
12
|
+
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil,
|
13
|
+
scopes: nil)
|
14
|
+
scopes ||= %w[email calendar contacts]
|
15
|
+
scopes = scopes.join(",") unless scopes.is_a?(String)
|
11
16
|
code = retrieve_code(name: name, email_address: email_address, provider: provider,
|
12
|
-
settings: settings, reauth_account_id: reauth_account_id)
|
17
|
+
settings: settings, reauth_account_id: reauth_account_id, scopes: scopes)
|
13
18
|
|
14
19
|
exchange_code_for_access_token(code)
|
15
20
|
end
|
16
21
|
|
17
|
-
private
|
22
|
+
private
|
23
|
+
|
24
|
+
def retrieve_code(name:, email_address:, provider:, settings:, reauth_account_id:, scopes:)
|
18
25
|
payload = { client_id: api.client.app_id, name: name, email_address: email_address,
|
19
|
-
provider: provider, settings: settings }
|
26
|
+
provider: provider, settings: settings, scopes: scopes }
|
20
27
|
payload[:reauth_account_id] = reauth_account_id
|
21
28
|
response = api.execute(method: :post, path: "/connect/authorize", payload: JSON.dump(payload))
|
22
29
|
response[:code]
|
23
30
|
end
|
24
31
|
|
25
|
-
|
32
|
+
def exchange_code_for_access_token(code)
|
26
33
|
payload = { client_id: api.client.app_id, client_secret: api.client.app_secret, code: code }
|
27
34
|
response = api.execute(method: :post, path: "/connect/token", payload: JSON.dump(payload))
|
28
35
|
response[:access_token]
|
data/lib/nylas/new_message.rb
CHANGED
data/lib/nylas/nylas_date.rb
CHANGED
data/lib/nylas/participant.rb
CHANGED
data/lib/nylas/phone_number.rb
CHANGED
data/lib/nylas/raw_message.rb
CHANGED
data/lib/nylas/recurrence.rb
CHANGED
data/lib/nylas/registry.rb
CHANGED
data/lib/nylas/rsvp.rb
CHANGED
data/lib/nylas/thread.rb
CHANGED
data/lib/nylas/timespan.rb
CHANGED
data/lib/nylas/types.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Nylas
|
2
4
|
# Collection of attribute types
|
3
5
|
module Types
|
@@ -34,6 +36,7 @@ module Nylas
|
|
34
36
|
return model.new if value.nil?
|
35
37
|
return value if already_cast?(value)
|
36
38
|
return model.new(**actual_attributes(value)) if value.respond_to?(:key?)
|
39
|
+
|
37
40
|
raise TypeError, "Unable to cast #{value} to a #{model}"
|
38
41
|
end
|
39
42
|
|
@@ -74,6 +77,7 @@ module Nylas
|
|
74
77
|
return Time.at(object.to_i) if object.is_a?(String)
|
75
78
|
return Time.at(object) if object.is_a?(Numeric)
|
76
79
|
return object.to_time if object.is_a?(Date)
|
80
|
+
|
77
81
|
raise TypeError, "Unable to cast #{object} to Time"
|
78
82
|
end
|
79
83
|
|
@@ -91,11 +95,13 @@ module Nylas
|
|
91
95
|
class DateType < ValueType
|
92
96
|
def cast(value)
|
93
97
|
return nil if value.nil?
|
98
|
+
|
94
99
|
Date.parse(value)
|
95
100
|
end
|
96
101
|
|
97
102
|
def serialize(value)
|
98
103
|
return value.iso8601 if value.respond_to?(:iso8601)
|
104
|
+
|
99
105
|
value
|
100
106
|
end
|
101
107
|
end
|
@@ -106,6 +112,7 @@ module Nylas
|
|
106
112
|
# @param value [Object] Casts the passed in object to a string using #to_s
|
107
113
|
def cast(value)
|
108
114
|
return value if value.nil?
|
115
|
+
|
109
116
|
value.to_s
|
110
117
|
end
|
111
118
|
end
|
@@ -116,6 +123,7 @@ module Nylas
|
|
116
123
|
# @param value [Object] Casts the passed in object to an integer using to_i
|
117
124
|
def cast(value)
|
118
125
|
return nil if value.nil?
|
126
|
+
|
119
127
|
value.to_i
|
120
128
|
end
|
121
129
|
end
|
@@ -128,6 +136,7 @@ module Nylas
|
|
128
136
|
return nil if value.nil?
|
129
137
|
return true if value == true
|
130
138
|
return false if value == false
|
139
|
+
|
131
140
|
raise TypeError, "#{value} must be either true or false"
|
132
141
|
end
|
133
142
|
end
|
data/lib/nylas/version.rb
CHANGED
data/lib/nylas/web_page.rb
CHANGED
data/lib/nylas/webhook.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nylas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.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:
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jeweler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '3.7'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rspec-json_matcher
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.1'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.1'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: webmock
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -310,17 +324,16 @@ require_paths:
|
|
310
324
|
- lib
|
311
325
|
required_ruby_version: !ruby/object:Gem::Requirement
|
312
326
|
requirements:
|
313
|
-
- - "
|
327
|
+
- - ">="
|
314
328
|
- !ruby/object:Gem::Version
|
315
|
-
version: '2.
|
329
|
+
version: '2.4'
|
316
330
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
317
331
|
requirements:
|
318
332
|
- - ">="
|
319
333
|
- !ruby/object:Gem::Version
|
320
334
|
version: '0'
|
321
335
|
requirements: []
|
322
|
-
|
323
|
-
rubygems_version: 2.5.2.3
|
336
|
+
rubygems_version: 3.0.1
|
324
337
|
signing_key:
|
325
338
|
specification_version: 4
|
326
339
|
summary: Gem for interacting with the Nylas API
|