nylas 6.0.0.beta.1 → 6.0.0.beta.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: 8695c7d105dd1621576a1cc5dfa3bd2d7ff482d171763bf9273a3797cc320675
4
- data.tar.gz: 88bda22c310af6c54061db72b6c19a5c4f8abed1e8e6a8518f4a4585d1ea6c38
3
+ metadata.gz: 5153fbe30a05d237c4e17da6ff51005ded6667ae710a50e349535079bfd5db91
4
+ data.tar.gz: 21e167b02e08cbf456ca45ffd94372fe6db8bf3fc7a1b5637ecf8bd5cde361bc
5
5
  SHA512:
6
- metadata.gz: cc213a177a26c78864c48e678f6ff2d01cf9a3f29305cb2169b192018a531f3b5d106dab1fdfd350b323e1bbb69c4069ed13ec8ff5319742805c559077d52ac5
7
- data.tar.gz: 2d51f8063938e335b00d9331f1beb9fb7c317c0af0954544c8ed40e3e4e14341452cdcf9be98a61ac4f9aae24d98eb0661434aea622a495fbd7f531d1293ec5c
6
+ metadata.gz: 232c65750e5e6027cf4414519be4e91a497c48b394d779ac2500af8bf82f3bf5317ecb1ec94261f80eb0cd46b373e88727c2aed65b036950f9d239a4276d313c
7
+ data.tar.gz: ccb50fddee574741f2baf36d4f44b46e246b219e0cb9d764d1ee2f1307cf8bf1a45aaec3a3bbe363f471b98ecc646fd60b79643ab730262308e9914a199b4719
data/lib/nylas/client.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "resources/calendars"
4
+ require_relative "resources/connectors"
5
+ require_relative "resources/messages"
4
6
  require_relative "resources/events"
5
7
  require_relative "resources/auth"
6
8
  require_relative "resources/webhooks"
7
9
  require_relative "resources/applications"
10
+ require_relative "resources/folders"
8
11
 
9
12
  module Nylas
10
13
  # Methods to retrieve data from the Nylas API as Ruby objects.
@@ -13,15 +16,15 @@ module Nylas
13
16
 
14
17
  # Initializes a client session.
15
18
  #
16
- # @param api_key [Hash, nil] API key to use for the client session.
17
- # @param api_uri [Hash] Client session's host.
18
- # @param timeout [Hash, nil] Timeout value to use for the client session.
19
- def initialize(api_key: nil,
19
+ # @param api_key [String, nil] API key to use for the client session.
20
+ # @param api_uri [String] Client session's host.
21
+ # @param timeout [String, nil] Timeout value to use for the client session.
22
+ def initialize(api_key:,
20
23
  api_uri: Config::DEFAULT_REGION_URL,
21
24
  timeout: nil)
22
25
  @api_key = api_key
23
26
  @api_uri = api_uri
24
- @timeout = timeout
27
+ @timeout = timeout || 30
25
28
  end
26
29
 
27
30
  # The application resources for your Nylas application.
@@ -31,6 +34,20 @@ module Nylas
31
34
  Applications.new(self)
32
35
  end
33
36
 
37
+ # The attachments resources for your Nylas application.
38
+ #
39
+ # @return [Nylas::Attachments] Attachment resources for your Nylas application.
40
+ def attachments
41
+ Attachments.new(self)
42
+ end
43
+
44
+ # The auth resources for your Nylas application.
45
+ #
46
+ # @return [Nylas::Auth] Auth resources for your Nylas application.
47
+ def auth
48
+ Auth.new(self)
49
+ end
50
+
34
51
  # The calendar resources for your Nylas application.
35
52
  #
36
53
  # @return [Nylas::Calendars] Calendar resources for your Nylas application.
@@ -38,6 +55,27 @@ module Nylas
38
55
  Calendars.new(self)
39
56
  end
40
57
 
58
+ # The connector resources for your Nylas application.
59
+ #
60
+ # @return [Nylas::Connectors] Connector resources for your Nylas application.
61
+ def connectors
62
+ Connectors.new(self)
63
+ end
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
+
72
+ # The draft resources for your Nylas application.
73
+ #
74
+ # @return [Nylas::Drafts] Draft resources for your Nylas application.
75
+ def drafts
76
+ Drafts.new(self)
77
+ end
78
+
41
79
  # The event resources for your Nylas application.
42
80
  #
43
81
  # @return [Nylas::Events] Event resources for your Nylas application
@@ -45,11 +83,32 @@ module Nylas
45
83
  Events.new(self)
46
84
  end
47
85
 
48
- # The auth resources for your Nylas application.
86
+ # The folder resources for your Nylas application.
49
87
  #
50
- # @return [Nylas::Auth] Auth resources for your Nylas application.
51
- def auth
52
- Auth.new(self)
88
+ # @return [Nylas::Folder] Folder resources for your Nylas application
89
+ def folders
90
+ Folders.new(self)
91
+ end
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
+
100
+ # The message resources for your Nylas application.
101
+ #
102
+ # @return [Nylas::Messages] Message resources for your Nylas application
103
+ def messages
104
+ Messages.new(self)
105
+ end
106
+
107
+ # The thread resources for your Nylas application.
108
+ #
109
+ # @return [Nylas::Threads] Thread resources for your Nylas application.
110
+ def threads
111
+ Threads.new(self)
53
112
  end
54
113
 
55
114
  # The webhook resources for your Nylas application.
data/lib/nylas/errors.rb CHANGED
@@ -3,17 +3,24 @@
3
3
  module Nylas
4
4
  Error = Class.new(::StandardError)
5
5
 
6
- class JsonParseError < Error; end
6
+ # Base error class for API-related errors.
7
+ class AbstractNylasApiError < Error; end
7
8
 
8
- # Base class to inflate the standard errors returned from the Nylas API.
9
- class NylasApiError < Error
9
+ # Base error class for SDK-related errors.
10
+ class AbstractNylasSdkError < Error; end
11
+
12
+ # Error class representing a failed parse of a JSON response from the Nylas API.
13
+ class JsonParseError < AbstractNylasSdkError; end
14
+
15
+ # Error class representing a failed response from the Nylas API.
16
+ class NylasApiError < AbstractNylasApiError
10
17
  attr_accessor :type, :request_id, :provider_error, :status_code
11
18
 
12
19
  # Initializes an error and assigns the given attributes to it.
13
20
  #
14
21
  # @param type [Hash] Error type.
15
22
  # @param message [String] Error message.
16
- # @param status_code [Hash] Error status code.
23
+ # @param status_code [Integer] Error status code.
17
24
  # @param provider_error [String, nil] Provider error.
18
25
  # @param request_id [Hash, nil] The ID of the request.
19
26
  def initialize(type, message, status_code, provider_error = nil, request_id = nil)
@@ -27,7 +34,7 @@ module Nylas
27
34
  # Parses the error response.
28
35
  #
29
36
  # @param response [Hash] Response from the Nylas API.
30
- # @param status_code [String] Error status code.
37
+ # @param status_code [Integer] Error status code.
31
38
  def self.parse_error_response(response, status_code)
32
39
  new(
33
40
  response["type"],
@@ -38,17 +45,17 @@ module Nylas
38
45
  end
39
46
  end
40
47
 
41
- # Base class to inflate the standard errors returned from the Nylas OAuth integration.
42
- class NylasOAuthError < Error
48
+ # Error class representing a failed response from the Nylas OAuth integration.
49
+ class NylasOAuthError < AbstractNylasApiError
43
50
  attr_accessor :error, :error_description, :error_uri, :error_code, :status_code
44
51
 
45
52
  # Initializes an error and assigns the given attributes to it.
46
53
  #
47
- # @param error [Hash] Error type.
54
+ # @param error [String] Error type.
48
55
  # @param error_description [String] Description of the error.
49
- # @param error_uri [Hash] Error URI.
50
- # @param error_code [Hash] Error code.
51
- # @param status_code [Hash] Error status code.
56
+ # @param error_uri [String] Error URI.
57
+ # @param error_code [String] Error code.
58
+ # @param status_code [String] Error status code.
52
59
  def initialize(error, error_description, error_uri, error_code, status_code)
53
60
  super(error_description)
54
61
  self.error = error
@@ -59,5 +66,20 @@ module Nylas
59
66
  end
60
67
  end
61
68
 
69
+ # Error class representing a timeout from the Nylas SDK.
70
+ class NylasSdkTimeoutError < AbstractNylasSdkError
71
+ attr_accessor :url, :timeout
72
+
73
+ # Initializes an error and assigns the given attributes to it.
74
+ # @param url [String] URL that timed out.
75
+ # @param timeout [Integer] Timeout in seconds.
76
+ # @return [NylasSdkTimeoutError] The error object.
77
+ def initialize(url, timeout)
78
+ super("Nylas SDK timed out before receiving a response from the server.")
79
+ self.url = url
80
+ self.timeout = timeout
81
+ end
82
+ end
83
+
62
84
  HTTP_SUCCESS_CODES = [200, 201, 202, 302].freeze
63
85
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "http_client"
4
+
3
5
  module Nylas
4
6
  # Allows resources to perform API operations on the Nylas API endpoints without exposing the HTTP
5
7
  # client to the end user.
@@ -13,7 +15,7 @@ module Nylas
13
15
  #
14
16
  # @param path [String] Destination path for the call.
15
17
  # @param query_params [Hash, {}] Query params to pass to the call.
16
- # @return [Array(Hash, String)] List of Nylas objects and API Request ID.
18
+ # @return Nylas data object and API Request ID.
17
19
  def get(path:, query_params: {})
18
20
  response = execute(
19
21
  method: :get,
@@ -39,7 +41,7 @@ module Nylas
39
41
  # @param query_params [Hash, {}] Query params to pass to the call.
40
42
  # @param request_body [String, Hash, nil] Request body to pass to the call.
41
43
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
42
- # @return [Array(Hash, String)] List of Nylas objects and API Request ID.
44
+ # @return Nylas data object and API Request ID.
43
45
  def post(path:, query_params: {}, request_body: nil, headers: {})
44
46
  response = execute(
45
47
  method: :post,
@@ -66,7 +68,7 @@ module Nylas
66
68
  # @param query_params [Hash, {}] Query params to pass to the call.
67
69
  # @param request_body [String, Hash, nil] Request body to pass to the call.
68
70
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
69
- # @return [Array(Hash, String)] List of Nylas objects and API Request ID.
71
+ # @return Nylas data object and API Request ID.
70
72
  def put(path:, query_params: {}, request_body: nil, headers: {})
71
73
  response = execute(
72
74
  method: :put,
@@ -93,7 +95,7 @@ module Nylas
93
95
  # @param query_params [Hash, {}] Query params to pass to the call.
94
96
  # @param request_body [String, Hash, nil] Request body to pass to the call.
95
97
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
96
- # @return [Array(Hash, String)] List of Nylas objects and API Request ID.
98
+ # @return Nylas data object and API Request ID.
97
99
  def patch(path:, query_params: {}, request_body: nil, headers: {})
98
100
  response = execute(
99
101
  method: :patch,
@@ -119,7 +121,7 @@ module Nylas
119
121
  # @param path [String] Destination path for the call.
120
122
  # @param query_params [Hash, {}] Query params to pass to the call.
121
123
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
122
- # @return [Array(Hash, String)] List of Nylas objects and API Request ID.
124
+ # @return Nylas data object and API Request ID.
123
125
  def delete(path:, query_params: {}, headers: {})
124
126
  response = execute(
125
127
  method: :delete,
@@ -5,6 +5,7 @@ require "rest-client"
5
5
  require_relative "../errors"
6
6
  require_relative "../version"
7
7
 
8
+ # Module for working with HTTP Client
8
9
  module Nylas
9
10
  require "yajl"
10
11
  require "base64"
@@ -22,32 +23,57 @@ module Nylas
22
23
  # @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch.
23
24
  # @param path [String, nil] Relative path from the API Base. This is the preferred way to execute
24
25
  # arbitrary or-not-yet-SDK-ified API commands.
26
+ # @param timeout [Integer, nil] Timeout value to send with the request.
25
27
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
26
28
  # @param query [Hash, {}] Hash of names and values to include in the query section of the URI
27
29
  # fragment.
28
- # @param payload [String, Hash, nil] Body to send with the request.
30
+ # @param payload [Hash, nil] Body to send with the request.
29
31
  # @param api_key [Hash, nil] API key to send with the request.
30
- # @param timeout [Hash, nil] Timeout value to send with the request.
31
32
  # @return [Object] Parsed JSON response from the API.
32
- def execute(method:, path: nil, headers: {}, query: {}, payload: nil, api_key: nil, timeout: nil)
33
+ def execute(method:, path:, timeout:, headers: {}, query: {}, payload: nil, api_key: nil)
33
34
  request = build_request(method: method, path: path, headers: headers,
34
35
  query: query, payload: payload, api_key: api_key, timeout: timeout)
35
- rest_client_execute(**request) do |response, _request, result|
36
- content_type = nil
37
-
38
- if response.headers && response.headers[:content_type]
39
- content_type = response.headers[:content_type].downcase
36
+ begin
37
+ rest_client_execute(**request) do |response, _request, result|
38
+ content_type = nil
39
+ if response.headers && response.headers[:content_type]
40
+ content_type = response.headers[:content_type].downcase
41
+ end
42
+
43
+ parse_json_evaluate_error(result.code.to_i, response, path, content_type)
40
44
  end
45
+ rescue Timeout::Error => _e
46
+ raise Nylas::NylasSdkTimeoutError.new(request.path, timeout)
47
+ end
48
+ end
41
49
 
42
- begin
43
- response = parse_response(response) if content_type == "application/json"
44
- rescue Nylas::JsonParseError
45
- handle_failed_response(result, response, path)
46
- raise
50
+ # Sends a request to the Nylas API, specifically for downloading data.
51
+ # This method supports streaming the response by passing a block, which will be executed
52
+ # with each chunk of the response body as it is read. If no block is provided, the entire
53
+ # response body is returned.
54
+ #
55
+ # @param path [String] Relative path from the API Base. This is the preferred way to execute
56
+ # arbitrary or-not-yet-SDK-ified API commands.
57
+ # @param timeout [Integer] Timeout value to send with the request.
58
+ # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
59
+ # @param query [Hash, {}] Hash of names and values to include in the query section of the URI
60
+ # fragment.
61
+ # @param api_key [Hash, nil] API key to send with the request.
62
+ # @yieldparam chunk [String] A chunk of the response body.
63
+ # @return [nil, String] Returns nil when a block is given (streaming mode).
64
+ # When no block is provided, the return is the entire raw response body.
65
+ def download_request(path:, timeout:, headers: {}, query: {}, api_key: nil, &block)
66
+ request, uri, http = setup_http(path, timeout, headers, query, api_key)
67
+
68
+ begin
69
+ http.start do |setup_http|
70
+ get_request = Net::HTTP::Get.new(uri)
71
+ request[:headers].each { |key, value| get_request[key] = value }
72
+
73
+ handle_response(setup_http, get_request, path, &block)
47
74
  end
48
-
49
- handle_failed_response(result, response, path)
50
- return response
75
+ rescue Net::OpenTimeout, Net::ReadTimeout
76
+ raise Nylas::NylasSdkTimeoutError.new(request[:url], timeout)
51
77
  end
52
78
  end
53
79
 
@@ -58,8 +84,8 @@ module Nylas
58
84
  # @param headers [Hash, {}] Additional HTTP headers to include in the payload.
59
85
  # @param query [Hash, {}] Hash of names and values to include in the query section of the URI
60
86
  # fragment.
61
- # @param payload [String, Hash, nil] Body to send with the request.
62
- # @param timeout [Hash, nil] Timeout value to send with the request.
87
+ # @param payload [Hash, nil] Body to send with the request.
88
+ # @param timeout [Integer, nil] Timeout value to send with the request.
63
89
  # @param api_key [Hash, nil] API key to send with the request.
64
90
  # @return [Object] The request information after processing. This includes an updated payload
65
91
  # and headers.
@@ -69,17 +95,21 @@ module Nylas
69
95
  url = path
70
96
  url = add_query_params_to_url(url, query)
71
97
  resulting_headers = default_headers.merge(headers).merge(auth_header(api_key))
72
- serialized_payload = payload&.to_json
98
+ if !payload.nil? && !payload["multipart"]
99
+ payload = payload&.to_json
100
+ resulting_headers["Content-type"] = "application/json"
101
+ elsif !payload.nil? && payload["multipart"]
102
+ payload.delete("multipart")
103
+ end
73
104
 
74
- { method: method, url: url, payload: serialized_payload, headers: resulting_headers, timeout: timeout }
105
+ { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout }
75
106
  end
76
107
 
77
108
  # Sets the default headers for API requests.
78
109
  def default_headers
79
110
  @default_headers ||= {
80
111
  "X-Nylas-API-Wrapper" => "ruby",
81
- "User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}",
82
- "Content-type" => "application/json"
112
+ "User-Agent" => "Nylas Ruby SDK #{Nylas::VERSION} - #{RUBY_VERSION}"
83
113
  }
84
114
  end
85
115
 
@@ -106,15 +136,45 @@ module Nylas
106
136
  headers: headers, timeout: timeout, &block)
107
137
  end
108
138
 
109
- # Handles failed responses from the Nylas API.
110
- def handle_failed_response(result, response, path)
111
- http_code = result.code.to_i
139
+ def setup_http(path, timeout, headers, query, api_key)
140
+ request = build_request(method: :get, path: path, headers: headers,
141
+ query: query, api_key: api_key, timeout: timeout)
142
+ uri = URI(request[:url])
143
+ http = Net::HTTP.new(uri.host, uri.port)
144
+ http.use_ssl = true
145
+ http.read_timeout = timeout
146
+ http.open_timeout = timeout
147
+ [request, uri, http]
148
+ end
112
149
 
113
- handle_anticipated_failure_mode(http_code, response, path)
150
+ def handle_response(http, get_request, path, &block)
151
+ http.request(get_request) do |response|
152
+ if response.is_a?(Net::HTTPSuccess)
153
+ return response.body unless block_given?
154
+
155
+ response.read_body(&block)
156
+ else
157
+ parse_json_evaluate_error(response.code.to_i, response.body, path, response["Content-Type"])
158
+ break
159
+ end
160
+ end
161
+ end
162
+
163
+ # Parses the response from the Nylas API and evaluates for errors.
164
+ def parse_json_evaluate_error(http_code, response, path, content_type = nil)
165
+ begin
166
+ response = parse_response(response) if content_type == "application/json"
167
+ rescue Nylas::JsonParseError
168
+ handle_failed_response(http_code, response, path)
169
+ raise
170
+ end
171
+
172
+ handle_failed_response(http_code, response, path)
173
+ response
114
174
  end
115
175
 
116
- # Handles anticipated failure states in the Nylas API.
117
- def handle_anticipated_failure_mode(http_code, response, path)
176
+ # Handles failed responses from the Nylas API.
177
+ def handle_failed_response(http_code, response, path)
118
178
  return if HTTP_SUCCESS_CODES.include?(http_code)
119
179
 
120
180
  case response
@@ -133,19 +193,23 @@ module Nylas
133
193
  NylasOAuthError.new(response[:error], response[:error_description], response[:error_uri],
134
194
  response[:error_code], status_code)
135
195
  else
136
- error_obj = response[:error]
137
- provider_error = error_obj.fetch(:provider_error, nil)
138
-
139
- NylasApiError.new(error_obj[:type], error_obj[:message], status_code, provider_error,
140
- response[:request_id])
196
+ throw_error(response, status_code)
141
197
  end
142
198
  end
143
199
 
200
+ def throw_error(response, status_code)
201
+ error_obj = response[:error]
202
+ provider_error = error_obj.fetch(:provider_error, nil)
203
+
204
+ NylasApiError.new(error_obj[:type], error_obj[:message], status_code, provider_error,
205
+ response[:request_id])
206
+ end
207
+
144
208
  # Adds query parameters to a URL.
145
209
  #
146
210
  # @return [String] Processed URL, including query params.
147
211
  def add_query_params_to_url(url, query)
148
- unless query.empty?
212
+ unless query.nil? || query.empty?
149
213
  uri = URI.parse(url)
150
214
  query = custom_params(query)
151
215
  params = URI.decode_www_form(uri.query || "") + query.to_a
@@ -13,7 +13,7 @@ module Nylas
13
13
 
14
14
  # Initializes the application.
15
15
  def initialize(sdk_instance)
16
- super("applications", sdk_instance)
16
+ super(sdk_instance)
17
17
  @redirect_uris = RedirectUris.new(sdk_instance)
18
18
  end
19
19
 
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "resource"
4
+ require_relative "../handler/api_operations"
5
+
6
+ module Nylas
7
+ # Nylas Attachment API
8
+ class Attachments < Resource
9
+ include ApiOperations::Get
10
+
11
+ # Return metadata of an attachment.
12
+ #
13
+ # @param identifier [String] Grant ID or email account to query.
14
+ # @param attachment_id [String] The id of the attachment to retrieve.
15
+ # @param query_params [Hash] The query parameters to include in the request.
16
+ # @return [Array(Hash, String)] The attachment and API request ID.
17
+ def find(identifier:, attachment_id:, query_params:)
18
+ get(
19
+ path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}",
20
+ query_params: query_params
21
+ )
22
+ end
23
+
24
+ # Download the attachment data.
25
+ #
26
+ # This method supports streaming the download by passing a block, which will
27
+ # be called with each chunk of the response body as it is read. If no block
28
+ # is given, the entire response will be read into memory and returned (not recommended
29
+ # for large files).
30
+ #
31
+ # @param identifier [String] Grant ID or email account to query.
32
+ # @param attachment_id [String] The ID of the attachment to be downloaded.
33
+ # @param query_params [Hash] The query parameters to include in the request.
34
+ # @yieldparam chunk [String] A chunk of the response body.
35
+ # @return [nil, String] Returns nil when a block is given (streaming mode).
36
+ # When no block is provided, the return is the entire raw response body.
37
+ def download(identifier:, attachment_id:, query_params:, &block)
38
+ download_request(
39
+ path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}/download",
40
+ query: query_params,
41
+ api_key: api_key,
42
+ timeout: timeout,
43
+ &block
44
+ )
45
+ end
46
+
47
+ # Download the attachment as a byte array.
48
+ #
49
+ # @param identifier [String] Grant ID or email account to query.
50
+ # @param attachment_id [String] The ID of the attachment to be downloaded.
51
+ # @param query_params [Hash] The query parameters to include in the request.
52
+ # @return [nil, Array(Integer)] Returns nil when a block is given (streaming mode).
53
+ # When no block is provided, the return is the entire raw response body.
54
+ def download_bytes(identifier:, attachment_id:, query_params:)
55
+ data = download_request(
56
+ path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}/download",
57
+ query: query_params,
58
+ api_key: api_key,
59
+ timeout: timeout
60
+ )
61
+
62
+ data&.bytes
63
+ end
64
+ end
65
+ 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("auth", 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.
@@ -156,16 +158,15 @@ module Nylas
156
158
  "access_type" => config[:access_type] || "online",
157
159
  "response_type" => "code"
158
160
  }
159
-
160
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]
161
166
  if config[:login_hint]
162
167
  params["login_hint"] = config[:login_hint]
163
168
  params["include_grant_scopes"] = config[:include_grant_scopes].to_s if config[:include_grant_scopes]
164
169
  end
165
- params["scope"] = config[:scope].join(" ") if config[:scope]
166
- params["prompt"] = config[:prompt] if config[:prompt]
167
- params["metadata"] = config[:metadata] if config[:metadata]
168
- params["state"] = config[:state] if config[:state]
169
170
 
170
171
  URI.encode_www_form(params)
171
172
  end