nylas 6.0.0.beta.3 → 6.0.0.beta.4

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: 5153fbe30a05d237c4e17da6ff51005ded6667ae710a50e349535079bfd5db91
4
- data.tar.gz: 21e167b02e08cbf456ca45ffd94372fe6db8bf3fc7a1b5637ecf8bd5cde361bc
3
+ metadata.gz: 15031848530cb5f183abdfb133349ec89309ae8bfc723e1a3d3c52941035e5e0
4
+ data.tar.gz: 6d2924c481e0d971cbfcafd95168e75d5a45f9880535451083dbedd9ef9c18cd
5
5
  SHA512:
6
- metadata.gz: 232c65750e5e6027cf4414519be4e91a497c48b394d779ac2500af8bf82f3bf5317ecb1ec94261f80eb0cd46b373e88727c2aed65b036950f9d239a4276d313c
7
- data.tar.gz: ccb50fddee574741f2baf36d4f44b46e246b219e0cb9d764d1ee2f1307cf8bf1a45aaec3a3bbe363f471b98ecc646fd60b79643ab730262308e9914a199b4719
6
+ metadata.gz: 55891a3badca093a691e83d5422a4a913de488ea87ac62b60f3d5316879e18532249fe7d7ff3a286a02af82bc42bcad551b2fad96d8c69cf2a69347dcbada7b7
7
+ data.tar.gz: 91bbb29bed0d52991c53a6619064057dba815e52a16fb616127545aefa78caaa8745e03285fc6f5521f16faed61d0b8ee2dd6bc68f828a6dc65f73ba139d60b6
data/lib/nylas/client.rb CHANGED
@@ -18,7 +18,7 @@ module Nylas
18
18
  #
19
19
  # @param api_key [String, nil] API key to use for the client session.
20
20
  # @param api_uri [String] Client session's host.
21
- # @param timeout [String, nil] Timeout value to use for the client session.
21
+ # @param timeout [Integer, nil] Timeout value to use for the client session.
22
22
  def initialize(api_key:,
23
23
  api_uri: Config::DEFAULT_REGION_URL,
24
24
  timeout: nil)
@@ -42,8 +42,8 @@ module Nylas
42
42
 
43
43
  parse_json_evaluate_error(result.code.to_i, response, path, content_type)
44
44
  end
45
- rescue Timeout::Error => _e
46
- raise Nylas::NylasSdkTimeoutError.new(request.path, timeout)
45
+ rescue RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout
46
+ raise Nylas::NylasSdkTimeoutError.new(request[:path], timeout)
47
47
  end
48
48
  end
49
49
 
@@ -92,8 +92,7 @@ module Nylas
92
92
  def build_request(
93
93
  method:, path: nil, headers: {}, query: {}, payload: nil, timeout: nil, api_key: nil
94
94
  )
95
- url = path
96
- url = add_query_params_to_url(url, query)
95
+ url = build_url(path, query)
97
96
  resulting_headers = default_headers.merge(headers).merge(auth_header(api_key))
98
97
  if !payload.nil? && !payload["multipart"]
99
98
  payload = payload&.to_json
@@ -206,33 +205,43 @@ module Nylas
206
205
  end
207
206
 
208
207
  # Adds query parameters to a URL.
209
- #
208
+ # @param url [String] The base URL.
209
+ # @param query [Hash] The query parameters to add to the URL.
210
210
  # @return [String] Processed URL, including query params.
211
- def add_query_params_to_url(url, query)
211
+ def build_url(url, query = nil)
212
212
  unless query.nil? || query.empty?
213
213
  uri = URI.parse(url)
214
- query = custom_params(query)
215
- params = URI.decode_www_form(uri.query || "") + query.to_a
216
- uri.query = URI.encode_www_form(params)
214
+ uri = build_query(uri, query)
217
215
  url = uri.to_s
218
216
  end
219
217
 
220
218
  url
221
219
  end
222
220
 
223
- # Defines custom parameters for a metadata_pair query.
224
- #
225
- # @return [String] Custom parameter in "<key>:<value>" format.
226
- def custom_params(query)
227
- # Convert hash to "<key>:<value>" form for metadata_pair query.
228
- if query.key?(:metadata_pair)
229
- pairs = query[:metadata_pair].map do |key, value|
230
- "#{key}:#{value}"
221
+ # Build the query string for a URI.
222
+ # @param uri [URI] URL to add the query to.
223
+ # @param query [Hash] The query params to include in the query.
224
+ # @return [URI] The URI object with the query parameters included.
225
+ def build_query(uri, query)
226
+ query.each do |key, value|
227
+ case value
228
+ when Array
229
+ value.each do |item|
230
+ qs = "#{URI.encode_www_form_component(key)}=#{URI.encode_www_form_component(item)}"
231
+ uri.query = [uri.query, qs].compact.join("&")
232
+ end
233
+ when Hash
234
+ value.each do |k, v|
235
+ qs = "#{URI.encode_www_form_component(key)}=#{URI.encode_www_form_component("#{k}:#{v}")}"
236
+ uri.query = [uri.query, qs].compact.join("&")
237
+ end
238
+ else
239
+ qs = "#{URI.encode_www_form_component(key)}=#{URI.encode_www_form_component(value)}"
240
+ uri.query = [uri.query, qs].compact.join("&")
231
241
  end
232
- query[:metadata_pair] = pairs
233
242
  end
234
243
 
235
- query
244
+ uri
236
245
  end
237
246
 
238
247
  # Set the authorization header for an API query.
@@ -17,10 +17,10 @@ module Nylas
17
17
  @redirect_uris = RedirectUris.new(sdk_instance)
18
18
  end
19
19
 
20
- # Gets the application object.
20
+ # Get application details.
21
21
  #
22
- # @return [Array(Hash, String)] Application object and API Request ID.
23
- def info
22
+ # @return [Array(Hash, String)] Application details and API Request ID.
23
+ def get_details
24
24
  get(path: "#{api_uri}/v3/applications")
25
25
  end
26
26
  end
@@ -59,7 +59,7 @@ module Nylas
59
59
  # IMPORTANT: You must store the 'secret' returned to use it inside the CodeExchange flow.
60
60
  #
61
61
  # @param config [Hash] Configuration for building the URL.
62
- # @return [OpenStruct] URL for hosted authentication with the secret and the hashed secret.
62
+ # @return [Hash] URL for hosted authentication with the secret and the hashed secret.
63
63
  def url_for_oauth2_pkce(config)
64
64
  url = url_auth_builder(config)
65
65
 
@@ -71,7 +71,7 @@ module Nylas
71
71
  url.query = build_query_with_pkce(config, secret_hash)
72
72
 
73
73
  # Returns the URL with secret and hashed secret.
74
- OpenStruct.new(secret: secret, secret_hash: secret_hash, url: url.to_s)
74
+ { secret: secret, secret_hash: secret_hash, url: url.to_s }
75
75
  end
76
76
 
77
77
  # Builds the URL for admin consent authentication for Microsoft.
@@ -81,9 +81,7 @@ module Nylas
81
81
  def url_for_admin_consent(config)
82
82
  config_with_provider = config.merge("provider" => "microsoft")
83
83
  url = url_auth_builder(config_with_provider)
84
-
85
- query_params = build_query_with_admin_consent(config)
86
- url.query = URI.encode_www_form(query_params)
84
+ url.query = build_query_with_admin_consent(config)
87
85
 
88
86
  url.to_s
89
87
  end
@@ -102,47 +100,58 @@ module Nylas
102
100
  true
103
101
  end
104
102
 
103
+ # Detects the provider of an email address.
104
+ # @param params [Hash] Parameters to detect the provider.
105
+ # @return [Array(Hash, String)] Detected provider, if found and API Request ID.
106
+ def detect_provider(params)
107
+ post(
108
+ path: "#{api_uri}/v3/providers/detect",
109
+ query_params: params
110
+ )
111
+ end
112
+
105
113
  private
106
114
 
107
115
  # Builds the query with admin consent authentication for Microsoft.
108
116
  #
109
117
  # @param config [Hash] Configuration for the query.
110
- # @return [Array(Hash, String)] Updated list of parameters, including those specific to admin
118
+ # @return [String] Updated list of parameters, including those specific to admin
111
119
  # consent.
112
120
  def build_query_with_admin_consent(config)
113
121
  params = build_query(config)
114
122
 
115
123
  # Appends new params specific for admin consent.
116
- params["response_type"] = "adminconsent"
117
- params["credential_id"] = config["credentialId"]
124
+ params[:provider] = "microsoft"
125
+ params[:response_type] = "adminconsent"
126
+ params[:credential_id] = config[:credential_id] if config[:credential_id]
118
127
 
119
- params
128
+ URI.encode_www_form(params).gsub("+", "%20")
120
129
  end
121
130
 
122
131
  # Builds the query with PKCE.
123
132
  #
124
133
  # @param config [Hash] Configuration for the query.
125
134
  # @param secret_hash [Hash] Hashed secret.
126
- # @return [Array(Hash, String)] Updated list of encoded parameters, including those specific
135
+ # @return [String] Updated list of encoded parameters, including those specific
127
136
  # to PKCE.
128
137
  def build_query_with_pkce(config, secret_hash)
129
138
  params = build_query(config)
130
139
 
131
140
  # Appends new PKCE specific params.
132
- params["code_challenge_method"] = "s256"
133
- params["code_challenge"] = secret_hash
141
+ params[:code_challenge_method] = "s256"
142
+ params[:code_challenge] = secret_hash
134
143
 
135
- URI.encode_www_form(params)
144
+ URI.encode_www_form(params).gsub("+", "%20")
136
145
  end
137
146
 
138
147
  # Builds the authentication URL.
139
148
  #
140
149
  # @param config [Hash] Configuration for the query.
141
- # @return [Array(Hash, String)] List of components for the authentication URL.
150
+ # @return [URI] List of components for the authentication URL.
142
151
  def url_auth_builder(config)
143
152
  builder = URI.parse(api_uri)
144
153
  builder.path = "/v3/connect/auth"
145
- builder.query = build_query(config)
154
+ builder.query = URI.encode_www_form(build_query(config)).gsub!("+", "%20")
146
155
 
147
156
  builder
148
157
  end
@@ -150,40 +159,42 @@ module Nylas
150
159
  # Builds the query.
151
160
  #
152
161
  # @param config [Hash] Configuration for the query.
153
- # @return [Array(Hash, String)] List of encoded parameters for the query.
162
+ # @return [Hash] List of parameters to encode in the query.
154
163
  def build_query(config)
155
164
  params = {
156
- "client_id" => config[:client_id],
157
- "redirect_uri" => config[:redirect_uri],
158
- "access_type" => config[:access_type] || "online",
159
- "response_type" => "code"
165
+ client_id: config[:client_id],
166
+ redirect_uri: config[:redirect_uri],
167
+ access_type: config[:access_type] || "online",
168
+ response_type: "code"
160
169
  }
161
- params["provider"] = config[:provider] if config[:provider]
162
- params["prompt"] = config[:prompt] if config[:prompt]
163
- params["metadata"] = config[:metadata] if config[:metadata]
164
- params["state"] = config[:state] if config[:state]
165
- params["scope"] = config[:scope].join(" ") if config[:scope]
170
+ params[:provider] = config[:provider] if config[:provider]
171
+ params[:prompt] = config[:prompt] if config[:prompt]
172
+ params[:metadata] = config[:metadata] if config[:metadata]
173
+ params[:state] = config[:state] if config[:state]
174
+ params[:scope] = config[:scope].join(" ") if config[:scope]
166
175
  if config[:login_hint]
167
- params["login_hint"] = config[:login_hint]
168
- params["include_grant_scopes"] = config[:include_grant_scopes].to_s if config[:include_grant_scopes]
176
+ params[:login_hint] = config[:login_hint]
177
+ params[:include_grant_scopes] = config[:include_grant_scopes].to_s if config[:include_grant_scopes]
169
178
  end
170
179
 
171
- URI.encode_www_form(params)
180
+ params
172
181
  end
173
182
 
174
- # Hashes the secret for PKCE authentication.
183
+ # Hash a plain text secret for use in PKCE.
175
184
  #
176
- # @param secret [String] Randomly-generated authentication secret.
177
- # @return [Hash] Hashed authentication secret.
185
+ # @param secret [String] The plain text secret to hash.
186
+ # @return [String] The hashed secret with base64 encoding (without padding).
178
187
  def hash_pkce_secret(secret)
179
- Digest::SHA256.digest(secret).unpack1("H*")
180
- Base64.strict_encode64(Digest::SHA256.digest(secret))
188
+ sha256_hash = Digest::SHA256.hexdigest(secret)
189
+ Base64.urlsafe_encode64(sha256_hash, padding: false)
181
190
  end
182
191
 
183
192
  # Sends the token request to the Nylas API.
184
193
  #
185
194
  # @param request [Hash] Code exchange request.
186
195
  def execute_token_request(request)
196
+ request[:client_secret] = api_key if request[:client_secret].nil?
197
+
187
198
  execute(
188
199
  method: :post,
189
200
  path: "#{api_uri}/v3/connect/token",
@@ -8,7 +8,7 @@ module Nylas
8
8
  class Connectors < Resource
9
9
  include ApiOperations::Get
10
10
  include ApiOperations::Post
11
- include ApiOperations::Put
11
+ include ApiOperations::Patch
12
12
  include ApiOperations::Delete
13
13
 
14
14
  # Access the Credentials API
@@ -59,7 +59,7 @@ module Nylas
59
59
  # @param request_body [Hash] The values to update the connector with
60
60
  # @return [Array(Hash, String)] The updated connector and API Request ID.
61
61
  def update(provider:, request_body:)
62
- put(
62
+ patch(
63
63
  path: "#{api_uri}/v3/connectors/#{provider}",
64
64
  request_body: request_body
65
65
  )
@@ -79,7 +79,7 @@ module Nylas
79
79
  # @param identifier [String] Grant ID or email account to query.
80
80
  # @param query_params [Hash, nil] Query params to pass to the request.
81
81
  # @return [Array(Array(Hash), String)] The list of contact groups and API Request ID.
82
- def contact_groups(identifier:, query_params: nil)
82
+ def list_groups(identifier:, query_params: nil)
83
83
  get(
84
84
  path: "#{api_uri}/v3/grants/#{identifier}/contacts/groups",
85
85
  query_params: query_params
@@ -8,7 +8,7 @@ module Nylas
8
8
  class Credentials < Resource
9
9
  include ApiOperations::Get
10
10
  include ApiOperations::Post
11
- include ApiOperations::Put
11
+ include ApiOperations::Patch
12
12
  include ApiOperations::Delete
13
13
 
14
14
  # Return all credentials.
@@ -53,7 +53,7 @@ module Nylas
53
53
  # @param request_body [Hash] The values to update the connector with
54
54
  # @return [Array(Hash, String)] The updated connector and API Request ID.
55
55
  def update(provider:, credential_id:, request_body:)
56
- put(
56
+ patch(
57
57
  path: "#{api_uri}/v3/connectors/#{provider}/creds/#{credential_id}",
58
58
  request_body: request_body
59
59
  )
@@ -86,7 +86,7 @@ module Nylas
86
86
  # @param event_id [String] The id of the event to respond to.
87
87
  # @param request_body [Hash] The status values to send the RSVP with.
88
88
  # @param query_params [Hash] The query parameters to include in the request
89
- # @return [Hash] Response object with the API Request ID.
89
+ # @return [(Hash, String)] Response object with the API Request ID.
90
90
  def send_rsvp(identifier:, event_id:, request_body:, query_params:)
91
91
  post(
92
92
  path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}/send-rsvp",
@@ -16,7 +16,7 @@ module Nylas
16
16
  # @return [Array(Array(Hash), String)] The list of grants and API Request ID.
17
17
  def list(query_params: nil)
18
18
  get(
19
- path: "#{api_uri}/v3/grant",
19
+ path: "#{api_uri}/v3/grants",
20
20
  query_params: query_params
21
21
  )
22
22
  end
@@ -27,7 +27,7 @@ module Nylas
27
27
  # @return [Array(Hash, String)] The grant and API request ID.
28
28
  def find(grant_id:)
29
29
  get(
30
- path: "#{api_uri}/v3/grant/#{grant_id}"
30
+ path: "#{api_uri}/v3/grants/#{grant_id}"
31
31
  )
32
32
  end
33
33
 
@@ -38,7 +38,7 @@ module Nylas
38
38
  # @return [Array(Hash, String)] The updated grant and API Request ID.
39
39
  def update(grant_id:, request_body:)
40
40
  put(
41
- path: "#{api_uri}/v3/grant/#{grant_id}",
41
+ path: "#{api_uri}/v3/grants/#{grant_id}",
42
42
  request_body: request_body
43
43
  )
44
44
  end
@@ -49,7 +49,7 @@ module Nylas
49
49
  # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
50
50
  def destroy(grant_id:)
51
51
  _, request_id = delete(
52
- path: "#{api_uri}/v3/grant/#{grant_id}"
52
+ path: "#{api_uri}/v3/grants/#{grant_id}"
53
53
  )
54
54
 
55
55
  [true, request_id]
@@ -94,21 +94,21 @@ module Nylas
94
94
  # Retrieve your scheduled messages.
95
95
  #
96
96
  # @param identifier [String] Grant ID or email account from which to find the scheduled message from.
97
- # @param schedule_id [String] The id of the scheduled message to stop.
98
97
  # @return [Array(Hash, String)] The list of scheduled messages and the API Request ID.
99
- def list_scheduled_messages(identifier:, schedule_id:)
98
+ def list_scheduled_messages(identifier:)
100
99
  get(
101
- path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
100
+ path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules"
102
101
  )
103
102
  end
104
103
 
105
104
  # Retrieve your scheduled messages.
106
105
  #
107
106
  # @param identifier [String] Grant ID or email account from which to list the scheduled messages from.
107
+ # @param schedule_id [String] The id of the scheduled message to stop.
108
108
  # @return [Array(Hash, String)] The scheduled message and the API Request ID.
109
- def find_scheduled_messages(identifier:)
109
+ def find_scheduled_messages(identifier:, schedule_id:)
110
110
  get(
111
- path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules"
111
+ path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
112
112
  )
113
113
  end
114
114
 
@@ -84,5 +84,38 @@ module Nylas
84
84
 
85
85
  [true, request_id]
86
86
  end
87
+
88
+ # Update the webhook secret value for a destination.
89
+ # @param webhook_id [String] The ID of the webhook destination to update.
90
+ # @return [Array(Hash, String)] The updated webhook destination and API Request ID.
91
+ def rotate_secret(webhook_id:)
92
+ put(
93
+ path: "#{api_uri}/v3/webhooks/#{webhook_id}/rotate-secret",
94
+ request_body: {}
95
+ )
96
+ end
97
+
98
+ # Get the current list of IP addresses that Nylas sends webhooks from
99
+ # @return [Array(Hash, String)] List of IP addresses that Nylas sends webhooks from and API Request ID.
100
+ def ip_addresses
101
+ get(
102
+ path: "#{api_uri}/v3/webhooks/ip-addresses"
103
+ )
104
+ end
105
+
106
+ # Extract the challenge parameter from a URL
107
+ # @param url [String] The URL sent by Nylas containing the challenge parameter
108
+ # @return [String] The challenge parameter
109
+ def self.extract_challenge_parameter(url)
110
+ url_object = URI.parse(url)
111
+ query = CGI.parse(url_object.query || "")
112
+
113
+ challenge_parameter = query["challenge"]
114
+ if challenge_parameter.nil? || challenge_parameter.empty? || challenge_parameter.first.nil?
115
+ raise "Invalid URL or no challenge parameter found."
116
+ end
117
+
118
+ challenge_parameter.first
119
+ end
87
120
  end
88
121
  end
data/lib/nylas/test.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nylas"
4
+
5
+ nylas = Nylas::Client.new(api_key: "abc123")
6
+ config = {
7
+ client_id: ENV["V3_CLIENT"],
8
+ provider: "google",
9
+ redirect_uri: "http://localhost:4567/oauth/exchange",
10
+ login_hint: "atejada@gmail.com"
11
+ }
12
+
13
+ auth_data = nylas.auth.url_for_oauth2_pkce(config)
14
+ puts auth_data
@@ -38,8 +38,12 @@ module Nylas
38
38
  # @return [Hash] The request that will attach the file to the message/draft
39
39
  def self.attach_file_request_builder(file_path)
40
40
  filename = File.basename(file_path)
41
- content_type = MIME::Types.type_for(file_path).first.to_s
42
- content_type = "application/octet-stream" if content_type.empty?
41
+ content_type = MIME::Types.type_for(file_path)
42
+ content_type = if !content_type.nil? && !content_type.empty?
43
+ content_type.first.to_s
44
+ else
45
+ "application/octet-stream"
46
+ end
43
47
  size = File.size(file_path)
44
48
  content = File.new(file_path, "rb")
45
49
 
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.0.beta.3"
4
+ VERSION = "6.0.0.beta.4"
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.0.beta.3
4
+ version: 6.0.0.beta.4
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-01-04 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -180,14 +180,14 @@ dependencies:
180
180
  requirements:
181
181
  - - "~>"
182
182
  - !ruby/object:Gem::Version
183
- version: 0.21.2
183
+ version: 0.22.0
184
184
  type: :development
185
185
  prerelease: false
186
186
  version_requirements: !ruby/object:Gem::Requirement
187
187
  requirements:
188
188
  - - "~>"
189
189
  - !ruby/object:Gem::Version
190
- version: 0.21.2
190
+ version: 0.22.0
191
191
  - !ruby/object:Gem::Dependency
192
192
  name: simplecov-cobertura
193
193
  requirement: !ruby/object:Gem::Requirement
@@ -251,6 +251,7 @@ files:
251
251
  - lib/nylas/resources/smart_compose.rb
252
252
  - lib/nylas/resources/threads.rb
253
253
  - lib/nylas/resources/webhooks.rb
254
+ - lib/nylas/test.rb
254
255
  - lib/nylas/utils/file_utils.rb
255
256
  - lib/nylas/version.rb
256
257
  homepage: