nylas 4.6.1 → 4.6.6

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: 70ffcaf730f5d3ee22c56de4a93675f0d2a180515226be18efcb4f772450a2ec
4
- data.tar.gz: de98665b0ca9f325ba70d7bc7c6336a5ff5cc6e71b6d95e36f13f78ec2fc4b1e
3
+ metadata.gz: baebc1d39fd0bc001c952f302dd417ac00399e139f90b6954080479c659d45ca
4
+ data.tar.gz: 554cf1807cb4432d1e7b75722c7da6846db751369085583adc08e09b0e1eaa9b
5
5
  SHA512:
6
- metadata.gz: c894b283e65168725049ab8f08e130d19d94e953969575487dcefe0c43f0e89d1c00249122d47ea917b7f1fada1080c133be1c02293b6b8195f9789c3789770e
7
- data.tar.gz: 724bc969684a5e113903f31c4ef32263bd16e49b359bd3aa349660199a19570c3f62ce47ae99732978ddb95d6eb0a25552de5ec221b434a319ef47a7cb4a7774
6
+ metadata.gz: 7e388d554f86e260cba3950dcd2e4ec559009af1e285c0cbc90c9b8111bed522016292dbf6e907b2a0da89dfedf98bd99d7bc67bab552c3368681b4c0224dc76
7
+ data.tar.gz: 947425b241a41b35904eba088d71c2ad6bbb2e0221eb36ba01ff215274e42e852db66c587e047076ab3a81e06d86fac0a98e327b799881097ba7a502ea9b939c
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
 
data/lib/nylas/account.rb CHANGED
@@ -12,6 +12,7 @@ module Nylas
12
12
  attribute :account_id, :string
13
13
  attribute :billing_state, :string
14
14
  attribute :sync_state, :string
15
+ attribute :provider, :string
15
16
 
16
17
  attribute :email, :string
17
18
  attribute :trial, :boolean
data/lib/nylas/api.rb CHANGED
@@ -4,6 +4,7 @@ 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
9
  def_delegators :client, :execute, :get, :post, :put, :delete, :app_id
9
10
 
@@ -15,6 +15,9 @@ module Nylas
15
15
 
16
16
  attribute :name, :string
17
17
  attribute :description, :string
18
+ attribute :is_primary, :boolean
19
+ attribute :location, :string
20
+ attribute :timezone, :string
18
21
 
19
22
  attribute :read_only, :boolean
20
23
 
@@ -22,6 +25,10 @@ module Nylas
22
25
  read_only == true
23
26
  end
24
27
 
28
+ def primary?
29
+ is_primary
30
+ end
31
+
25
32
  def events
26
33
  api.events.where(calendar_id: id)
27
34
  end
@@ -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, :[]
@@ -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
@@ -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?
data/lib/nylas/draft.rb CHANGED
@@ -33,9 +33,13 @@ module Nylas
33
33
  attribute :folder, :folder
34
34
  has_n_of_attribute :labels, :label
35
35
 
36
+ attribute :tracking, :message_tracking
37
+
36
38
  transfer :api, to: %i[events files folder labels]
37
39
 
38
40
  def send!
41
+ return execute(method: :post, path: "/send", payload: to_json) if tracking
42
+
39
43
  save
40
44
  execute(method: :post, path: "/send", payload: JSON.dump(draft_id: id, version: version))
41
45
  end
data/lib/nylas/errors.rb CHANGED
@@ -14,6 +14,8 @@ module Nylas
14
14
  class ModelNotUpdatableError < ModelActionError; end
15
15
  class ModelNotDestroyableError < ModelActionError; end
16
16
 
17
+ class JsonParseError < Error; end
18
+
17
19
  # Raised when attempting to set a field that is not on a model with mass assignment
18
20
  class ModelMissingFieldError < ModelActionError
19
21
  def initialize(field, model)
@@ -48,6 +50,10 @@ module Nylas
48
50
  ResourceNotFound = Class.new(APIError)
49
51
  MethodNotAllowed = Class.new(APIError)
50
52
  InvalidRequest = Class.new(APIError)
53
+ UnauthorizedRequest = Class.new(APIError)
54
+ ResourceRemoved = Class.new(APIError)
55
+ TeapotError = Class.new(APIError)
56
+ RequestTimedOut = Class.new(APIError)
51
57
  MessageRejected = Class.new(APIError)
52
58
  SendingQuotaExceeded = Class.new(APIError)
53
59
  ServiceUnavailable = Class.new(APIError)
data/lib/nylas/event.rb CHANGED
@@ -29,6 +29,8 @@ module Nylas
29
29
  attribute :when, :when
30
30
  attribute :original_start_time, :unix_timestamp
31
31
 
32
+ attr_accessor :notify_participants
33
+
32
34
  def busy?
33
35
  busy
34
36
  end
@@ -42,5 +44,17 @@ module Nylas
42
44
  event_id: id, account_id: account_id)
43
45
  rsvp.save
44
46
  end
47
+
48
+ private
49
+
50
+ def query_params
51
+ if notify_participants.nil?
52
+ {}
53
+ else
54
+ {
55
+ notify_participants: notify_participants
56
+ }
57
+ end
58
+ end
45
59
  end
46
60
  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
@@ -56,7 +58,9 @@ module Nylas
56
58
  def retrieve_file
57
59
  response = api.get(path: "#{resource_path}/download")
58
60
  filename = response.headers.fetch(:content_disposition, "").gsub("attachment; filename=", "")
59
- temp_file = Tempfile.new(filename, encoding: "ascii-8bit")
61
+ # The returned filename can be longer than 256 chars which isn't supported by rb_sysopen.
62
+ # 128 chars here is more than enough given that TempFile ensure the filename will be unique.
63
+ temp_file = Tempfile.new(filename[0..127], encoding: "ascii-8bit")
60
64
  temp_file.write(response.body)
61
65
  temp_file.seek(0)
62
66
  temp_file
@@ -1,20 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
+ require "yajl"
5
+
4
6
  # Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
5
7
  class HttpClient # rubocop:disable Metrics/ClassLength
6
8
  HTTP_CODE_TO_EXCEPTIONS = {
7
9
  400 => InvalidRequest,
10
+ 401 => UnauthorizedRequest,
8
11
  402 => MessageRejected,
9
12
  403 => AccessDenied,
10
13
  404 => ResourceNotFound,
11
14
  405 => MethodNotAllowed,
15
+ 410 => ResourceRemoved,
16
+ 418 => TeapotError,
12
17
  422 => MailProviderError,
13
18
  429 => SendingQuotaExceeded,
14
19
  500 => InternalError,
15
20
  501 => EndpointNotYetImplemented,
16
21
  502 => BadGateway,
17
- 503 => ServiceUnavailable
22
+ 503 => ServiceUnavailable,
23
+ 504 => RequestTimedOut
18
24
  }.freeze
19
25
 
20
26
  ENDPOINT_TIMEOUTS = {
@@ -80,7 +86,14 @@ module Nylas
80
86
  timeout: timeout
81
87
  )
82
88
  rest_client_execute(**request) do |response, _request, result|
83
- response = parse_response(response)
89
+ content_type = nil
90
+
91
+ if response.headers && response.headers[:content_type]
92
+ content_type = response.headers[:content_type].downcase
93
+ end
94
+
95
+ response = parse_response(response) if content_type == "application/json"
96
+
84
97
  handle_failed_response(result: result, response: response)
85
98
  response
86
99
  end
@@ -130,9 +143,12 @@ module Nylas
130
143
  end
131
144
 
132
145
  def parse_response(response)
133
- response.is_a?(Enumerable) ? response : JSON.parse(response, symbolize_names: true)
134
- rescue JSON::ParserError
135
- response
146
+ return response if response.is_a?(Enumerable)
147
+
148
+ json = StringIO.new(response)
149
+ Yajl::Parser.new(symbolize_names: true).parse(json)
150
+ rescue Yajl::ParseError
151
+ raise Nylas::JsonParseError
136
152
  end
137
153
  inform_on :parse_response, level: :debug, also_log: { result: true }
138
154
 
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
@@ -69,5 +69,23 @@ module Nylas
69
69
  assign(api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
70
70
  self
71
71
  end
72
+
73
+ def save_call
74
+ handle_folder
75
+
76
+ execute(
77
+ method: :put,
78
+ payload: attributes.serialize(keys: allowed_keys_for_save),
79
+ path: resource_path
80
+ )
81
+ end
82
+
83
+ def handle_folder
84
+ return if folder.nil?
85
+
86
+ self.folder_id = folder.id if folder_id.nil? && !self.to_h.dig(:folder, :id).nil?
87
+
88
+ self.folder = nil
89
+ end
72
90
  end
73
91
  end
data/lib/nylas/model.rb CHANGED
@@ -39,21 +39,31 @@ 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(method: :post, payload: attributes.serialize, path: resources_path)
49
+ execute(
50
+ method: :post,
51
+ payload: attributes.serialize,
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
- execute(method: :put, payload: attributes.serialize(keys: data.keys), path: resource_path)
61
+ execute(
62
+ method: :put,
63
+ payload: attributes.serialize(keys: data.keys),
64
+ path: resource_path,
65
+ query: query_params
66
+ )
57
67
  true
58
68
  rescue Registry::MissingKeyError => e
59
69
  raise ModelMissingFieldError.new(e.key, self)
@@ -75,7 +85,7 @@ module Nylas
75
85
  def destroy
76
86
  raise ModelNotDestroyableError, self unless destroyable?
77
87
 
78
- execute(method: :delete, path: resource_path)
88
+ execute(method: :delete, path: resource_path, query: query_params)
79
89
  end
80
90
 
81
91
  # @return [String] JSON String of the model.
@@ -99,6 +109,10 @@ module Nylas
99
109
  )
100
110
  end
101
111
 
112
+ def query_params
113
+ {}
114
+ end
115
+
102
116
  # Allows you to narrow in exactly what kind of model you're working with
103
117
  module ClassMethods
104
118
  attr_accessor :raw_mime_type, :creatable, :showable, :filterable, :searchable, :listable, :updatable,
@@ -27,8 +27,6 @@ module Nylas
27
27
  data.each do |attribute_name, value|
28
28
  if respond_to?(:"#{attribute_name}=")
29
29
  send(:"#{attribute_name}=", value)
30
- else
31
- Logging.logger.warn("#{attribute_name} is not defined as an attribute on #{self.class.name}")
32
30
  end
33
31
  end
34
32
  end
@@ -7,6 +7,7 @@ module Nylas
7
7
  extend Forwardable
8
8
  def_delegators :type, :cast, :serialize
9
9
  attr_accessor :type_name, :exclude_when, :default
10
+
10
11
  def initialize(type_name:, exclude_when:, default:)
11
12
  self.type_name = type_name
12
13
  self.exclude_when = exclude_when
@@ -17,6 +17,8 @@ module Nylas
17
17
 
18
18
  def []=(key, value)
19
19
  data[key] = cast(key, value)
20
+ rescue Nylas::Registry::MissingKeyError
21
+ # Don't crash when a new attribute is added
20
22
  end
21
23
 
22
24
  # Merges data into the registry while casting input types correctly
@@ -39,6 +39,7 @@ module Nylas
39
39
  # Methods to call when tweaking Transferable classes
40
40
  module ClassMethods
41
41
  attr_accessor :attribute_recipients
42
+
42
43
  def init_attribute_recipients
43
44
  self.attribute_recipients ||= {}
44
45
  end
@@ -5,6 +5,7 @@ module Nylas
5
5
  # @see https://docs.nylas.com/reference#native-authentication-1
6
6
  class NativeAuthentication
7
7
  attr_accessor :api
8
+
8
9
  def initialize(api:)
9
10
  self.api = api
10
11
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- # Data structure for seending a message via the Nylas API
4
+ # Data structure for sending a message via the Nylas API
5
5
  class NewMessage
6
6
  include Model
7
7
  self.creatable = false
@@ -15,6 +15,7 @@ module Nylas
15
15
  has_n_of_attribute :from, :email_address
16
16
  has_n_of_attribute :cc, :email_address
17
17
  has_n_of_attribute :bcc, :email_address
18
+ has_n_of_attribute :reply_to, :email_address
18
19
 
19
20
  attribute :subject, :string
20
21
  attribute :body, :string
@@ -12,5 +12,6 @@ module Nylas
12
12
  attribute :state, :string
13
13
  attribute :city, :string
14
14
  attribute :country, :string
15
+ attribute :secondary_address, :string
15
16
  end
16
17
  end
@@ -4,6 +4,7 @@ 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
@@ -8,6 +8,7 @@ module Nylas
8
8
  # Includes the list of keys in the registry for debug purposes.
9
9
  class MissingKeyError < Error
10
10
  attr_accessor :key
11
+
11
12
  def initialize(key, keys)
12
13
  super("key #{key} not in #{keys}")
13
14
  self.key = key
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "4.6.1"
4
+ VERSION = "4.6.6"
5
5
  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: 4.6.1
4
+ version: 4.6.6
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: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -240,7 +240,7 @@ dependencies:
240
240
  requirements:
241
241
  - - ">="
242
242
  - !ruby/object:Gem::Version
243
- version: '1.6'
243
+ version: '2.0'
244
244
  - - "<"
245
245
  - !ruby/object:Gem::Version
246
246
  version: '3.0'
@@ -250,10 +250,30 @@ dependencies:
250
250
  requirements:
251
251
  - - ">="
252
252
  - !ruby/object:Gem::Version
253
- version: '1.6'
253
+ version: '2.0'
254
254
  - - "<"
255
255
  - !ruby/object:Gem::Version
256
256
  version: '3.0'
257
+ - !ruby/object:Gem::Dependency
258
+ name: yajl-ruby
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '1.2'
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: 1.2.1
267
+ type: :runtime
268
+ prerelease: false
269
+ version_requirements: !ruby/object:Gem::Requirement
270
+ requirements:
271
+ - - "~>"
272
+ - !ruby/object:Gem::Version
273
+ version: '1.2'
274
+ - - ">="
275
+ - !ruby/object:Gem::Version
276
+ version: 1.2.1
257
277
  description: Gem for interacting with the Nylas API.
258
278
  email: support@nylas.com
259
279
  executables: []
@@ -311,7 +331,7 @@ files:
311
331
  - lib/nylas/web_page.rb
312
332
  - lib/nylas/webhook.rb
313
333
  - lib/nylas/when.rb
314
- homepage:
334
+ homepage:
315
335
  licenses:
316
336
  - MIT
317
337
  metadata:
@@ -321,7 +341,7 @@ metadata:
321
341
  homepage_uri: https://www.nylas.com
322
342
  source_code_uri: https://github.com/nylas/nylas-ruby
323
343
  wiki_uri: https://github.com/nylas/nylas-ruby/wiki
324
- post_install_message:
344
+ post_install_message:
325
345
  rdoc_options: []
326
346
  require_paths:
327
347
  - lib
@@ -336,9 +356,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
356
  - !ruby/object:Gem::Version
337
357
  version: '0'
338
358
  requirements: []
339
- rubyforge_project:
340
- rubygems_version: 2.7.6.2
341
- signing_key:
359
+ rubygems_version: 3.1.2
360
+ signing_key:
342
361
  specification_version: 4
343
362
  summary: Gem for interacting with the Nylas API
344
363
  test_files: []