nylas 6.0.2 → 6.0.3

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: 4210ab41b7981d0dee78c6c08cad413063e621f0142909ef9e156e477092c572
4
- data.tar.gz: 8845808ca7a7a993676b02373ab89d9db702742f2f3ad89678b529392e9596b0
3
+ metadata.gz: 3bd6fdcadf69439f1f8a8549e26e3b43f4df3cfeb8ae0c5a2aef5aca8fb3acce
4
+ data.tar.gz: b1f939a98c16ec5bf390791df31bb0f76feb45af07e4e6bcfc32c52e79e3b53f
5
5
  SHA512:
6
- metadata.gz: 47e3479b8c975bd0bb4d5d25dd336abb1f8fa469e06d2eeda5b039ae4d09d7a3f5cab3efb7f2d9ec4b9124a991ccdd531766a32b6a89b70c6a26b878f6f03792
7
- data.tar.gz: c69da1ded4c8f953009b747b999e743e6bc6ef1418d88544f3d33991a655ad40a9c95a94db6ed2f13a0bf2bda133858f35f738e4e2cdfa0c9130061e5a35098b
6
+ metadata.gz: 591735adfae3cfefdbc513762eff603390779f14321a543bf0a2115f3a368f1b674175c6e5cbea9052b4e10db157d74a3cda80b74773b212bbda2e38fc25aea0
7
+ data.tar.gz: 17dc68c13af649f533d206a546a72cf45b508864f71d2daae1eb020f686ce5b79c39829d841dd919cc944cd038042f4075116a7a941c2f782b6ae127c35d63a8
data/lib/nylas/client.rb CHANGED
@@ -24,7 +24,7 @@ module Nylas
24
24
  timeout: nil)
25
25
  @api_key = api_key
26
26
  @api_uri = api_uri
27
- @timeout = timeout || 30
27
+ @timeout = timeout || 90
28
28
  end
29
29
 
30
30
  # The application resources for your Nylas application.
@@ -118,7 +118,7 @@ module Nylas
118
118
  # @return [String] Updated list of parameters, including those specific to admin
119
119
  # consent.
120
120
  def build_query_with_admin_consent(config)
121
- params = build_query(config)
121
+ params = build_http_query(config)
122
122
 
123
123
  # Appends new params specific for admin consent.
124
124
  params[:provider] = "microsoft"
@@ -135,7 +135,7 @@ module Nylas
135
135
  # @return [String] Updated list of encoded parameters, including those specific
136
136
  # to PKCE.
137
137
  def build_query_with_pkce(config, secret_hash)
138
- params = build_query(config)
138
+ params = build_http_query(config)
139
139
 
140
140
  # Appends new PKCE specific params.
141
141
  params[:code_challenge_method] = "s256"
@@ -151,7 +151,7 @@ module Nylas
151
151
  def url_auth_builder(config)
152
152
  builder = URI.parse(api_uri)
153
153
  builder.path = "/v3/connect/auth"
154
- builder.query = URI.encode_www_form(build_query(config)).gsub(/\+/, "%20")
154
+ builder.query = URI.encode_www_form(build_http_query(config)).gsub(/\+/, "%20")
155
155
 
156
156
  builder
157
157
  end
@@ -160,7 +160,7 @@ module Nylas
160
160
  #
161
161
  # @param config [Hash] Configuration for the query.
162
162
  # @return [Hash] List of parameters to encode in the query.
163
- def build_query(config)
163
+ def build_http_query(config)
164
164
  params = {
165
165
  client_id: config[:client_id],
166
166
  redirect_uri: config[:redirect_uri],
@@ -43,10 +43,20 @@ module Nylas
43
43
  # you can use {FileUtils::attach_file_request_builder} to build each object attach.
44
44
  # @return [Array(Hash, String)] The created draft and API Request ID.
45
45
  def create(identifier:, request_body:)
46
- form_body, opened_files = FileUtils.build_form_request(request_body)
46
+ payload = request_body
47
+ opened_files = []
48
+
49
+ # Use form data only if the attachment size is greater than 3mb
50
+ attachments = request_body[:attachments] || request_body["attachments"] || []
51
+ attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
52
+
53
+ if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
54
+ payload, opened_files = FileUtils.build_form_request(request_body)
55
+ end
56
+
47
57
  response = post(
48
58
  path: "#{api_uri}/v3/grants/#{identifier}/drafts",
49
- request_body: form_body
59
+ request_body: payload
50
60
  )
51
61
 
52
62
  opened_files.each(&:close)
@@ -63,11 +73,20 @@ module Nylas
63
73
  # you can use {FileUtils::attach_file_request_builder} to build each object attach.
64
74
  # @return [Array(Hash, String)] The updated draft and API Request ID.
65
75
  def update(identifier:, draft_id:, request_body:)
66
- form_body, opened_files = FileUtils.build_form_request(request_body)
76
+ payload = request_body
77
+ opened_files = []
78
+
79
+ # Use form data only if the attachment size is greater than 3mb
80
+ attachments = request_body[:attachments] || request_body["attachments"] || []
81
+ attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
82
+
83
+ if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
84
+ payload, opened_files = FileUtils.build_form_request(request_body)
85
+ end
67
86
 
68
87
  response = put(
69
88
  path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}",
70
- request_body: form_body
89
+ request_body: payload
71
90
  )
72
91
 
73
92
  opened_files.each(&:close)
@@ -79,11 +79,20 @@ module Nylas
79
79
  # you can use {FileUtils::attach_file_request_builder} to build each object attach.
80
80
  # @return [Array(Hash, String)] The sent message and the API Request ID.
81
81
  def send(identifier:, request_body:)
82
- form_body, opened_files = FileUtils.build_form_request(request_body)
82
+ payload = request_body
83
+ opened_files = []
84
+
85
+ # Use form data only if the attachment size is greater than 3mb
86
+ attachments = request_body[:attachments] || request_body["attachments"] || []
87
+ attachment_size = attachments&.sum { |attachment| attachment[:size] || 0 } || 0
88
+
89
+ if attachment_size >= FileUtils::FORM_DATA_ATTACHMENT_SIZE
90
+ payload, opened_files = FileUtils.build_form_request(request_body)
91
+ end
83
92
 
84
93
  response = post(
85
94
  path: "#{api_uri}/v3/grants/#{identifier}/messages/send",
86
- request_body: form_body
95
+ request_body: payload
87
96
  )
88
97
 
89
98
  opened_files.each(&:close)
@@ -5,6 +5,9 @@ require "mime/types"
5
5
  module Nylas
6
6
  # A collection of file-related utilities.
7
7
  module FileUtils
8
+ # The maximum size of an attachment that can be sent using json
9
+ FORM_DATA_ATTACHMENT_SIZE = 3 * 1024 * 1024
10
+
8
11
  # Build a form request for the API.
9
12
  # @param request_body The values to create the message with.
10
13
  # @return The form data to send to the API and the opened files.
data/lib/nylas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "6.0.2"
4
+ VERSION = "6.0.3"
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: 6.0.2
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-27 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types