nylas 5.12.1 → 5.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1e352b09e650aa0cbc5dff7363b8a0997aab35c94e73a5f4a77b5503de70448
4
- data.tar.gz: a7830ea4cc6a9028669ca6c0e502cba4f2dfc70402a2c00f85cd1f6d315d0594
3
+ metadata.gz: c0c54fb8e13535027a5f3a6eda146fcf5d71c91b093877c2729d96ae0b2b1292
4
+ data.tar.gz: 9b9457001de3dc893352b50909269d83e418e96b4d9eb09cac23d992217af532
5
5
  SHA512:
6
- metadata.gz: 7aeed921859461105491d8394f845b79d6419ecc10a17ae0989f2239382cce8e4ad1fb3936bd7a4cebd730e40bac60b28dafe8e145e63a10d424a9e9b46915f0
7
- data.tar.gz: 47fdeaa77f5e1037934fc421b7b869edc031f956aad054d2888d29aee0a75ecb537c063e4c89e3c30e4f14f2be2da0860b5ec546e39034590f137773b73ef3cc
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
- client_id: app_id,
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
@@ -29,6 +29,7 @@ module Nylas
29
29
  attribute :read_only, :boolean
30
30
  attribute :metadata, :hash
31
31
  attribute :job_status_id, :string, read_only: true
32
+ attribute :hex_color, :string, read_only: true
32
33
 
33
34
  def read_only?
34
35
  read_only == true
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(APIError)
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/event.rb CHANGED
@@ -43,6 +43,7 @@ module Nylas
43
43
  attribute :reminder_minutes, :string
44
44
  attribute :reminder_method, :string
45
45
  attribute :job_status_id, :string, read_only: true
46
+ attribute :visibility, :string
46
47
 
47
48
  attr_accessor :notify_participants
48
49
 
@@ -189,8 +189,7 @@ module Nylas
189
189
  def parse_response(response)
190
190
  return response if response.is_a?(Enumerable)
191
191
 
192
- json = StringIO.new(response)
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
- raise exception.new(http_code, response) unless response.is_a?(Hash)
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
- raise exception.new(
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "5.12.1"
4
+ VERSION = "5.14.0"
5
5
  end
data/lib/nylas/when.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
+ require "tzinfo"
5
+
4
6
  # Structure to represent all the Nylas time types.
5
7
  # @see https://docs.nylas.com/reference#section-time
6
8
  class When
@@ -19,10 +21,15 @@ module Nylas
19
21
 
20
22
  # when object == 'time'
21
23
  attribute :time, :unix_timestamp
24
+ # Timezone must be set to a valid IANA database timezone name
25
+ attribute :timezone, :string
22
26
 
23
27
  # when object == 'timespan'
24
28
  attribute :start_time, :unix_timestamp
25
29
  attribute :end_time, :unix_timestamp
30
+ # Both timezone fields must be set to a valid IANA database timezone name
31
+ attribute :start_timezone, :string
32
+ attribute :end_timezone, :string
26
33
 
27
34
  def_delegators :range, :cover?
28
35
 
@@ -44,5 +51,25 @@ module Nylas
44
51
  Range.new(time, time)
45
52
  end
46
53
  end
54
+
55
+ # Validates the When object
56
+ # @return [Boolean] True if the When is valid
57
+ # @raise [ArgumentError] If any of the timezone fields are not valid IANA database names
58
+ def valid?
59
+ validate_timezone(timezone) if timezone
60
+ validate_timezone(start_timezone) if start_timezone
61
+ validate_timezone(end_timezone) if end_timezone
62
+
63
+ true
64
+ end
65
+
66
+ private
67
+
68
+ def validate_timezone(timezone_var)
69
+ return if TZInfo::Timezone.all_identifiers.include?(timezone_var)
70
+
71
+ raise ArgumentError,
72
+ format("The timezone provided (%s) is not a valid IANA timezone database name", timezone_var)
73
+ end
47
74
  end
48
75
  end
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.12.1
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-08-12 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: tzinfo
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.5
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.5
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: overcommit
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +226,28 @@ dependencies:
212
226
  requirements:
213
227
  - - "~>"
214
228
  - !ruby/object:Gem::Version
215
- version: '0.15'
229
+ version: 0.21.2
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 0.21.2
237
+ - !ruby/object:Gem::Dependency
238
+ name: simplecov-cobertura
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 2.1.0
216
244
  type: :development
217
245
  prerelease: false
218
246
  version_requirements: !ruby/object:Gem::Requirement
219
247
  requirements:
220
248
  - - "~>"
221
249
  - !ruby/object:Gem::Version
222
- version: '0.15'
250
+ version: 2.1.0
223
251
  - !ruby/object:Gem::Dependency
224
252
  name: rest-client
225
253
  requirement: !ruby/object:Gem::Requirement
@@ -380,7 +408,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
408
  - !ruby/object:Gem::Version
381
409
  version: '0'
382
410
  requirements: []
383
- rubygems_version: 3.3.7
411
+ rubygems_version: 3.0.9
384
412
  signing_key:
385
413
  specification_version: 4
386
414
  summary: Gem for interacting with the Nylas API