nylas 6.0.0.beta.2 → 6.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fa40920f9d190cc73e988935bdd235ad3a4bb342c8762be925fdb81f8c1c45f
4
- data.tar.gz: 6bf0722aae4e7b9699abeda1e25436ac62256aa7c14a1f9d330eff2d8908c9c6
3
+ metadata.gz: 15031848530cb5f183abdfb133349ec89309ae8bfc723e1a3d3c52941035e5e0
4
+ data.tar.gz: 6d2924c481e0d971cbfcafd95168e75d5a45f9880535451083dbedd9ef9c18cd
5
5
  SHA512:
6
- metadata.gz: 3fb796e62d9c6545d5632c0112ac328ee69ce0fbda26e82a31ce4adf790bea75096a172a7252a4b75da850cf6268a864ea6365137e40f8ff6e7682767bc7f3da
7
- data.tar.gz: 13b91300931cc49f195f1a3ab01d5c72fe7100bf0c83dcfac5acdd965c0da4b2a7c547bc0611482916c3de8a6f7255604f9ca47f3894f94aba09a483da1f8c73
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)
@@ -62,6 +62,13 @@ module Nylas
62
62
  Connectors.new(self)
63
63
  end
64
64
 
65
+ # The contact resources for your Nylas application.
66
+ #
67
+ # @return [Nylas::Contacts] Contact resources for your Nylas application.
68
+ def contacts
69
+ Contacts.new(self)
70
+ end
71
+
65
72
  # The draft resources for your Nylas application.
66
73
  #
67
74
  # @return [Nylas::Drafts] Draft resources for your Nylas application.
@@ -83,6 +90,13 @@ module Nylas
83
90
  Folders.new(self)
84
91
  end
85
92
 
93
+ # The grants resources for your Nylas application.
94
+ #
95
+ # @return [Nylas::Grants] Grant resources for your Nylas application
96
+ def grants
97
+ Grants.new(self)
98
+ end
99
+
86
100
  # The message resources for your Nylas application.
87
101
  #
88
102
  # @return [Nylas::Messages] Message resources for your Nylas application
@@ -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
@@ -16,15 +16,6 @@ module Nylas
16
16
  include ApiOperations::Post
17
17
  include ApiOperations::Get
18
18
 
19
- # Initializes Auth.
20
- def initialize(sdk_instance)
21
- super(sdk_instance)
22
-
23
- @grants = Grants.new(sdk_instance)
24
- end
25
-
26
- attr_reader :grants
27
-
28
19
  # Builds the URL for authenticating users to your application with OAuth 2.0.
29
20
  #
30
21
  # @param config [Hash] Configuration for building the URL.
@@ -43,6 +34,17 @@ module Nylas
43
34
  execute_token_request(request)
44
35
  end
45
36
 
37
+ # Create a Grant via Custom Authentication.
38
+ #
39
+ # @param request_body [Hash] The values to create the Grant with.
40
+ # @return [Array(Hash, String)] Created grant and API Request ID.
41
+ def custom_authentication(request_body)
42
+ post(
43
+ path: "#{api_uri}/v3/connect/custom",
44
+ request_body: request_body
45
+ )
46
+ end
47
+
46
48
  # Refreshes an access token.
47
49
  #
48
50
  # @param request [Hash] Code exchange request.
@@ -57,7 +59,7 @@ module Nylas
57
59
  # IMPORTANT: You must store the 'secret' returned to use it inside the CodeExchange flow.
58
60
  #
59
61
  # @param config [Hash] Configuration for building the URL.
60
- # @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.
61
63
  def url_for_oauth2_pkce(config)
62
64
  url = url_auth_builder(config)
63
65
 
@@ -69,7 +71,7 @@ module Nylas
69
71
  url.query = build_query_with_pkce(config, secret_hash)
70
72
 
71
73
  # Returns the URL with secret and hashed secret.
72
- OpenStruct.new(secret: secret, secret_hash: secret_hash, url: url.to_s)
74
+ { secret: secret, secret_hash: secret_hash, url: url.to_s }
73
75
  end
74
76
 
75
77
  # Builds the URL for admin consent authentication for Microsoft.
@@ -79,9 +81,7 @@ module Nylas
79
81
  def url_for_admin_consent(config)
80
82
  config_with_provider = config.merge("provider" => "microsoft")
81
83
  url = url_auth_builder(config_with_provider)
82
-
83
- query_params = build_query_with_admin_consent(config)
84
- url.query = URI.encode_www_form(query_params)
84
+ url.query = build_query_with_admin_consent(config)
85
85
 
86
86
  url.to_s
87
87
  end
@@ -100,47 +100,58 @@ module Nylas
100
100
  true
101
101
  end
102
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
+
103
113
  private
104
114
 
105
115
  # Builds the query with admin consent authentication for Microsoft.
106
116
  #
107
117
  # @param config [Hash] Configuration for the query.
108
- # @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
109
119
  # consent.
110
120
  def build_query_with_admin_consent(config)
111
121
  params = build_query(config)
112
122
 
113
123
  # Appends new params specific for admin consent.
114
- params["response_type"] = "adminconsent"
115
- 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]
116
127
 
117
- params
128
+ URI.encode_www_form(params).gsub("+", "%20")
118
129
  end
119
130
 
120
131
  # Builds the query with PKCE.
121
132
  #
122
133
  # @param config [Hash] Configuration for the query.
123
134
  # @param secret_hash [Hash] Hashed secret.
124
- # @return [Array(Hash, String)] Updated list of encoded parameters, including those specific
135
+ # @return [String] Updated list of encoded parameters, including those specific
125
136
  # to PKCE.
126
137
  def build_query_with_pkce(config, secret_hash)
127
138
  params = build_query(config)
128
139
 
129
140
  # Appends new PKCE specific params.
130
- params["code_challenge_method"] = "s256"
131
- params["code_challenge"] = secret_hash
141
+ params[:code_challenge_method] = "s256"
142
+ params[:code_challenge] = secret_hash
132
143
 
133
- URI.encode_www_form(params)
144
+ URI.encode_www_form(params).gsub("+", "%20")
134
145
  end
135
146
 
136
147
  # Builds the authentication URL.
137
148
  #
138
149
  # @param config [Hash] Configuration for the query.
139
- # @return [Array(Hash, String)] List of components for the authentication URL.
150
+ # @return [URI] List of components for the authentication URL.
140
151
  def url_auth_builder(config)
141
152
  builder = URI.parse(api_uri)
142
153
  builder.path = "/v3/connect/auth"
143
- builder.query = build_query(config)
154
+ builder.query = URI.encode_www_form(build_query(config)).gsub!("+", "%20")
144
155
 
145
156
  builder
146
157
  end
@@ -148,55 +159,42 @@ module Nylas
148
159
  # Builds the query.
149
160
  #
150
161
  # @param config [Hash] Configuration for the query.
151
- # @return [Array(Hash, String)] List of encoded parameters for the query.
162
+ # @return [Hash] List of parameters to encode in the query.
152
163
  def build_query(config)
153
164
  params = {
154
- "client_id" => config[:client_id],
155
- "redirect_uri" => config[:redirect_uri],
156
- "access_type" => config[:access_type] || "online",
157
- "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"
158
169
  }
159
- set_params(config)
160
-
161
- URI.encode_www_form(params)
162
- end
163
-
164
- # Set the parameters for the query
165
- def set_params(config)
166
- params["provider"] = config[:provider] if config[:provider]
167
- set_config_params(config)
168
- set_more_config(config)
169
- end
170
-
171
- # Set login related configurations
172
- def set_config_params(config)
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]
173
175
  if config[:login_hint]
174
- params["login_hint"] = config[:login_hint]
175
- 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]
176
178
  end
177
- params["scope"] = config[:scope].join(" ") if config[:scope]
178
- end
179
179
 
180
- # More config
181
- def set_more_config(config)
182
- params["prompt"] = config[:prompt] if config[:prompt]
183
- params["metadata"] = config[:metadata] if config[:metadata]
184
- params["state"] = config[:state] if config[:state]
180
+ params
185
181
  end
186
182
 
187
- # Hashes the secret for PKCE authentication.
183
+ # Hash a plain text secret for use in PKCE.
188
184
  #
189
- # @param secret [String] Randomly-generated authentication secret.
190
- # @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).
191
187
  def hash_pkce_secret(secret)
192
- Digest::SHA256.digest(secret).unpack1("H*")
193
- Base64.strict_encode64(Digest::SHA256.digest(secret))
188
+ sha256_hash = Digest::SHA256.hexdigest(secret)
189
+ Base64.urlsafe_encode64(sha256_hash, padding: false)
194
190
  end
195
191
 
196
192
  # Sends the token request to the Nylas API.
197
193
  #
198
194
  # @param request [Hash] Code exchange request.
199
195
  def execute_token_request(request)
196
+ request[:client_secret] = api_key if request[:client_secret].nil?
197
+
200
198
  execute(
201
199
  method: :post,
202
200
  path: "#{api_uri}/v3/connect/token",
@@ -93,7 +93,7 @@ module Nylas
93
93
  # @return [Array(Array(Hash), String)] The free/busy response.
94
94
  def get_free_busy(identifier:, request_body:)
95
95
  post(
96
- path: "#{api_uri}/v3/grants/#{identifier}/calendars/availability",
96
+ path: "#{api_uri}/v3/grants/#{identifier}/calendars/free-busy",
97
97
  request_body: request_body
98
98
  )
99
99
  end
@@ -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
  )
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/api_operations"
5
+
6
+ module Nylas
7
+ # Nylas Contact API
8
+ class Contacts < Resource
9
+ include ApiOperations::Get
10
+ include ApiOperations::Post
11
+ include ApiOperations::Put
12
+ include ApiOperations::Delete
13
+
14
+ # Return all contacts.
15
+ #
16
+ # @param identifier [String] Grant ID or email account to query.
17
+ # @param query_params [Hash, nil] Query params to pass to the request.
18
+ # @return [Array(Array(Hash), String)] The list of contacts and API Request ID.
19
+ def list(identifier:, query_params: nil)
20
+ get(
21
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts",
22
+ query_params: query_params
23
+ )
24
+ end
25
+
26
+ # Return a contact.
27
+ #
28
+ # @param identifier [String] Grant ID or email account to query.
29
+ # @param contact_id [String] The id of the contact to return.
30
+ # @param query_params [Hash, nil] Query params to pass to the request.
31
+ # @return [Array(Hash, String)] The contact and API request ID.
32
+ def find(identifier:, contact_id:, query_params: nil)
33
+ get(
34
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}",
35
+ query_params: query_params
36
+ )
37
+ end
38
+
39
+ # Create a contact.
40
+ #
41
+ # @param identifier [String] Grant ID or email account in which to create the object.
42
+ # @param request_body [Hash] The values to create the contact with.
43
+ # @return [Array(Hash, String)] The created contact and API Request ID.
44
+ def create(identifier:, request_body:)
45
+ post(
46
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts",
47
+ request_body: request_body
48
+ )
49
+ end
50
+
51
+ # Update a contact.
52
+ #
53
+ # @param identifier [String] Grant ID or email account in which to update an object.
54
+ # @param contact_id [String] The id of the contact to update.
55
+ # @param request_body [Hash] The values to update the contact with
56
+ # @return [Array(Hash, String)] The updated contact and API Request ID.
57
+ def update(identifier:, contact_id:, request_body:)
58
+ put(
59
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}",
60
+ request_body: request_body
61
+ )
62
+ end
63
+
64
+ # Delete a contact.
65
+ #
66
+ # @param identifier [String] Grant ID or email account from which to delete an object.
67
+ # @param contact_id [String] The id of the contact to delete.
68
+ # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
69
+ def destroy(identifier:, contact_id:)
70
+ _, request_id = delete(
71
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts/#{contact_id}"
72
+ )
73
+
74
+ [true, request_id]
75
+ end
76
+
77
+ # Return all contact groups.
78
+ #
79
+ # @param identifier [String] Grant ID or email account to query.
80
+ # @param query_params [Hash, nil] Query params to pass to the request.
81
+ # @return [Array(Array(Hash), String)] The list of contact groups and API Request ID.
82
+ def list_groups(identifier:, query_params: nil)
83
+ get(
84
+ path: "#{api_uri}/v3/grants/#{identifier}/contacts/groups",
85
+ query_params: query_params
86
+ )
87
+ end
88
+ end
89
+ end
@@ -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
  )
@@ -87,5 +87,16 @@ module Nylas
87
87
 
88
88
  [true, request_id]
89
89
  end
90
+
91
+ # Send an draft.
92
+ #
93
+ # @param identifier [String] Grant ID or email account from which to send the draft.
94
+ # @param draft_id [String] The id of the draft to send.
95
+ # @return [Array(Hash, String)] The sent message draft and the API Request ID.
96
+ def send(identifier:, draft_id:)
97
+ post(
98
+ path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}"
99
+ )
100
+ end
90
101
  end
91
102
  end
@@ -79,5 +79,20 @@ module Nylas
79
79
 
80
80
  [true, request_id]
81
81
  end
82
+
83
+ # Send RSVP. Allows users to respond to events they have been added to as an attendee.
84
+ #
85
+ # @param identifier [String] Grant ID or email account from which to send RSVP with.
86
+ # @param event_id [String] The id of the event to respond to.
87
+ # @param request_body [Hash] The status values to send the RSVP with.
88
+ # @param query_params [Hash] The query parameters to include in the request
89
+ # @return [(Hash, String)] Response object with the API Request ID.
90
+ def send_rsvp(identifier:, event_id:, request_body:, query_params:)
91
+ post(
92
+ path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}/send-rsvp",
93
+ query_params: query_params,
94
+ request_body: request_body
95
+ )
96
+ end
82
97
  end
83
98
  end
@@ -7,7 +7,6 @@ module Nylas
7
7
  # Grants
8
8
  class Grants < Resource
9
9
  include ApiOperations::Get
10
- include ApiOperations::Post
11
10
  include ApiOperations::Put
12
11
  include ApiOperations::Delete
13
12
 
@@ -17,7 +16,7 @@ module Nylas
17
16
  # @return [Array(Array(Hash), String)] The list of grants and API Request ID.
18
17
  def list(query_params: nil)
19
18
  get(
20
- path: "#{api_uri}/v3/grant",
19
+ path: "#{api_uri}/v3/grants",
21
20
  query_params: query_params
22
21
  )
23
22
  end
@@ -28,18 +27,7 @@ module Nylas
28
27
  # @return [Array(Hash, String)] The grant and API request ID.
29
28
  def find(grant_id:)
30
29
  get(
31
- path: "#{api_uri}/v3/grant/#{grant_id}"
32
- )
33
- end
34
-
35
- # Create a Grant via Custom Authentication.
36
- #
37
- # @param request_body [Hash] The values to create the Grant with.
38
- # @return [Array(Hash, String)] Created grant and API Request ID.
39
- def create(request_body)
40
- post(
41
- path: "#{api_uri}/v3/#{resource_name}/custom",
42
- request_body: request_body
30
+ path: "#{api_uri}/v3/grants/#{grant_id}"
43
31
  )
44
32
  end
45
33
 
@@ -50,7 +38,7 @@ module Nylas
50
38
  # @return [Array(Hash, String)] The updated grant and API Request ID.
51
39
  def update(grant_id:, request_body:)
52
40
  put(
53
- path: "#{api_uri}/v3/grant/#{grant_id}",
41
+ path: "#{api_uri}/v3/grants/#{grant_id}",
54
42
  request_body: request_body
55
43
  )
56
44
  end
@@ -61,7 +49,7 @@ module Nylas
61
49
  # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
62
50
  def destroy(grant_id:)
63
51
  _, request_id = delete(
64
- path: "#{api_uri}/v3/grant/#{grant_id}"
52
+ path: "#{api_uri}/v3/grants/#{grant_id}"
65
53
  )
66
54
 
67
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
 
@@ -19,6 +19,9 @@ module Nylas
19
19
  GRANT_EXPIRED = "grant.expired"
20
20
  MESSAGE_SEND_SUCCESS = "message.send_success"
21
21
  MESSAGE_SEND_FAILED = "message.send_failed"
22
+ MESSAGE_OPENED = "message.opened"
23
+ MESSAGE_LINK_CLICKED = "message.link_clicked"
24
+ THREAD_REPLIED = "thread.replied"
22
25
  end
23
26
 
24
27
  # Nylas Webhooks API
@@ -81,5 +84,38 @@ module Nylas
81
84
 
82
85
  [true, request_id]
83
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
84
120
  end
85
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
@@ -11,9 +11,14 @@ module Nylas
11
11
  # @!visibility private
12
12
  def self.build_form_request(request_body)
13
13
  attachments = request_body.delete(:attachments) || request_body.delete("attachments") || []
14
- message_payload = request_body.to_json
14
+
15
+ # RestClient will not send a multipart request if there are no attachments
16
+ # so we need to return the message payload to be used as a json payload
17
+ return [request_body, []] if attachments.empty?
15
18
 
16
19
  # Prepare the data to return
20
+ message_payload = request_body.to_json
21
+
17
22
  form_data = {}
18
23
  opened_files = []
19
24
 
@@ -33,8 +38,12 @@ module Nylas
33
38
  # @return [Hash] The request that will attach the file to the message/draft
34
39
  def self.attach_file_request_builder(file_path)
35
40
  filename = File.basename(file_path)
36
- content_type = MIME::Types.type_for(file_path).first.to_s
37
- 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
38
47
  size = File.size(file_path)
39
48
  content = File.new(file_path, "rb")
40
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.2"
4
+ VERSION = "6.0.0.beta.4"
5
5
  end
data/lib/nylas.rb CHANGED
@@ -32,6 +32,7 @@ require_relative "nylas/resources/attachments"
32
32
  require_relative "nylas/resources/auth"
33
33
  require_relative "nylas/resources/calendars"
34
34
  require_relative "nylas/resources/connectors"
35
+ require_relative "nylas/resources/contacts"
35
36
  require_relative "nylas/resources/credentials"
36
37
  require_relative "nylas/resources/drafts"
37
38
  require_relative "nylas/resources/events"
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.2
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: 2023-11-21 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
@@ -239,6 +239,7 @@ files:
239
239
  - lib/nylas/resources/auth.rb
240
240
  - lib/nylas/resources/calendars.rb
241
241
  - lib/nylas/resources/connectors.rb
242
+ - lib/nylas/resources/contacts.rb
242
243
  - lib/nylas/resources/credentials.rb
243
244
  - lib/nylas/resources/drafts.rb
244
245
  - lib/nylas/resources/events.rb
@@ -250,6 +251,7 @@ files:
250
251
  - lib/nylas/resources/smart_compose.rb
251
252
  - lib/nylas/resources/threads.rb
252
253
  - lib/nylas/resources/webhooks.rb
254
+ - lib/nylas/test.rb
253
255
  - lib/nylas/utils/file_utils.rb
254
256
  - lib/nylas/version.rb
255
257
  homepage: