nylas 5.13.0 → 5.14.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/api.rb +4 -7
- data/lib/nylas/errors.rb +48 -1
- data/lib/nylas/http_client.rb +12 -4
- data/lib/nylas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0c54fb8e13535027a5f3a6eda146fcf5d71c91b093877c2729d96ae0b2b1292
|
4
|
+
data.tar.gz: 9b9457001de3dc893352b50909269d83e418e96b4d9eb09cac23d992217af532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ba9746e31db9afd0de0e11180fd547895ee1454b8483b6234ace01a57477a6c9ba26db27ca2c7785e07cc80176b115a34ee0b1a3dc9040e5d21105f1b01704
|
7
|
+
data.tar.gz: d25d687696cbc5f6cc95b5e9aadaaf3ad26af664f2550436616997091a7d55d42c519424657e11f1eb008b6cb79496ab83169abc2978f8d6a9be50adc0ce6642
|
data/lib/nylas/api.rb
CHANGED
@@ -36,18 +36,15 @@ module Nylas
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil,
|
39
|
-
provider: nil, redirect_on_error: nil)
|
40
|
-
params = {
|
41
|
-
|
42
|
-
redirect_uri: redirect_uri,
|
43
|
-
response_type: response_type,
|
44
|
-
login_hint: login_hint
|
45
|
-
}
|
39
|
+
provider: nil, redirect_on_error: nil, disable_provider_selection: nil)
|
40
|
+
params = { client_id: app_id, redirect_uri: redirect_uri, response_type: response_type,
|
41
|
+
login_hint: login_hint }
|
46
42
|
|
47
43
|
params[:state] = state if state
|
48
44
|
params[:scopes] = scopes.join(",") if scopes
|
49
45
|
params[:provider] = provider if provider
|
50
46
|
params[:redirect_on_error] = redirect_on_error if redirect_on_error
|
47
|
+
params[:disable_provider_selection] = disable_provider_selection if disable_provider_selection
|
51
48
|
|
52
49
|
"#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
|
53
50
|
end
|
data/lib/nylas/errors.rb
CHANGED
@@ -45,7 +45,54 @@ module Nylas
|
|
45
45
|
self.message = message
|
46
46
|
self.server_error = server_error
|
47
47
|
end
|
48
|
+
|
49
|
+
def self.parse_error_response(response)
|
50
|
+
new(
|
51
|
+
response["type"],
|
52
|
+
response["message"],
|
53
|
+
response["server_error"]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Error class representing a 429 error response, with details on the rate limit
|
59
|
+
class RateLimitError < APIError
|
60
|
+
attr_accessor :rate_limit
|
61
|
+
attr_accessor :rate_limit_reset
|
62
|
+
|
63
|
+
RATE_LIMIT_LIMIT_HEADER = "x_ratelimit_limit"
|
64
|
+
RATE_LIMIT_RESET_HEADER = "x_ratelimit_reset"
|
65
|
+
|
66
|
+
def initialize(type, message, server_error = nil, rate_limit = nil, rate_limit_reset = nil)
|
67
|
+
super(type, message, server_error)
|
68
|
+
self.rate_limit = rate_limit
|
69
|
+
self.rate_limit_reset = rate_limit_reset
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.parse_error_response(response)
|
73
|
+
rate_limit, rate_limit_rest = extract_rate_limit_details(response)
|
74
|
+
|
75
|
+
new(
|
76
|
+
response["type"],
|
77
|
+
response["message"],
|
78
|
+
response["server_error"],
|
79
|
+
rate_limit,
|
80
|
+
rate_limit_rest
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.extract_rate_limit_details(response)
|
85
|
+
return nil, nil unless response.respond_to?(:headers)
|
86
|
+
|
87
|
+
rate_limit = response.headers[RATE_LIMIT_LIMIT_HEADER.to_sym].to_i
|
88
|
+
rate_limit_rest = response.headers[RATE_LIMIT_RESET_HEADER.to_sym].to_i
|
89
|
+
|
90
|
+
[rate_limit, rate_limit_rest]
|
91
|
+
end
|
92
|
+
|
93
|
+
private_class_method :extract_rate_limit_details
|
48
94
|
end
|
95
|
+
|
49
96
|
AccessDenied = Class.new(APIError)
|
50
97
|
ResourceNotFound = Class.new(APIError)
|
51
98
|
MethodNotAllowed = Class.new(APIError)
|
@@ -55,7 +102,7 @@ module Nylas
|
|
55
102
|
TeapotError = Class.new(APIError)
|
56
103
|
RequestTimedOut = Class.new(APIError)
|
57
104
|
MessageRejected = Class.new(APIError)
|
58
|
-
SendingQuotaExceeded = Class.new(
|
105
|
+
SendingQuotaExceeded = Class.new(RateLimitError)
|
59
106
|
ServiceUnavailable = Class.new(APIError)
|
60
107
|
BadGateway = Class.new(APIError)
|
61
108
|
InternalError = Class.new(APIError)
|
data/lib/nylas/http_client.rb
CHANGED
@@ -189,8 +189,7 @@ module Nylas
|
|
189
189
|
def parse_response(response)
|
190
190
|
return response if response.is_a?(Enumerable)
|
191
191
|
|
192
|
-
|
193
|
-
Yajl::Parser.new(symbolize_names: true).parse(json)
|
192
|
+
Yajl::Parser.new(symbolize_names: true).parse(response)
|
194
193
|
rescue Yajl::ParseError
|
195
194
|
raise Nylas::JsonParseError
|
196
195
|
end
|
@@ -222,9 +221,18 @@ module Nylas
|
|
222
221
|
return if HTTP_SUCCESS_CODES.include?(http_code)
|
223
222
|
|
224
223
|
exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
|
225
|
-
|
224
|
+
case response
|
225
|
+
when Hash
|
226
|
+
raise error_hash_to_exception(exception, response)
|
227
|
+
when RestClient::Response
|
228
|
+
raise exception.parse_error_response(response)
|
229
|
+
else
|
230
|
+
raise exception.new(http_code, response)
|
231
|
+
end
|
232
|
+
end
|
226
233
|
|
227
|
-
|
234
|
+
def error_hash_to_exception(exception, response)
|
235
|
+
exception.new(
|
228
236
|
response[:type],
|
229
237
|
response[:message],
|
230
238
|
response.fetch(:server_error, nil)
|
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: 5.
|
4
|
+
version: 5.14.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: 2022-
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|