@@ -93,121 +93,19 @@ defmodule {{moduleName}}.Connection do
9393
9494 ### Parameters
9595
96- { {#hasOAuthMethods} }
97- The first parameter *may* be a `token` (a string, a token fetcher class,
98- or a module/function tuple) or a keyword list of `options`. They are
99- documented separately, but only *one* of them will be passed.
100-
101- - `token`: a String or a function of arity one. This value, or the result
102- of the function call, will be set as a bearer token in the
103- `authorization` header.
104- { {/hasOAuthMethods} }
10596 - `options`: a keyword list of { {moduleName} }.Connection.options.
10697
10798 ### Returns
10899
109100 Tesla.Env.client
110101 """
111- { {#hasOAuthMethods} }
112- @spec new(String.t() | token_fetcher | options) :: Tesla.Env.client()
113- { {/hasOAuthMethods} }
114- { {^hasOAuthMethods} }
115102 @spec new(options) :: Tesla.Env.client()
116- { {/hasOAuthMethods} }
117- { {#hasOAuthMethods} }
118- def new(token) when is_binary(token) or is_function(token, 1) or is_tuple(token) do
119- new(token: token)
120- end
121- { {/hasOAuthMethods} }
122-
123103 def new(options) when is_list(options) do
124104 options
125105 |> middleware()
126106 |> Tesla.client(adapter())
127107 end
128108
129- { {#hasOAuthMethods} }
130- { {#hasHttpBasicMethods} }
131- @doc """
132- Configure a client using bearer authentication with scopes, or with
133- username and password for basic authentication.
134-
135- ### Parameters
136-
137- - `token_or_username`: a String representing a bearer token or a username,
138- depending on the type of the next parameter, or a function arity one
139- that returns a bearer token.
140- - `scopes_or_password`: a list of Strings represenging OAuth2 scopes, or
141- a single string that is the password for the username provided.
142- - `options`: a keyword list of { {moduleName} }.Connection.options.
143-
144- ### Returns
145-
146- Tesla.Env.client
147- """
148- @spec new(
149- token_or_username :: String.t() | token_fetcher,
150- scopes_or_password :: list(String.t()) | String.t(),
151- options
152- ) :: Tesla.Env.client()
153- { {/hasHttpBasicMethods} }
154- { {^hasHttpBasicMethods} }
155- @doc """
156- Configure a client using bearer authentication with scopes.
157-
158- ### Parameters
159-
160- - `token`: a String or a function of arity one. This value, or the result
161- of the function call, will be set as a bearer token in the
162- `authorization` header.
163- - `scopes`: a list of Strings represenging OAuth2 scopes.
164- - `options`: a keyword list of { {moduleName} }.Connection.options.
165-
166- ### Returns
167-
168- Tesla.Env.client
169- """
170- @spec new(String.t() | token_fetcher, list(String.t()), options) :: Tesla.Env.client()
171- { {/hasHttpBasicMethods} }
172- { {/hasOAuthMethods} }
173- { {^hasOAuthMethods} }
174- { {#hasHttpBasicMethods} }
175- @doc """
176- Configure a client using username and password for basic authentication.
177-
178- ### Parameters
179-
180- - `username`: a String representing a username.
181- - `password`: a String representing a password.
182- - `options`: a keyword list of { {moduleName} }.Connection.options.
183-
184- ### Returns
185-
186- Tesla.Env.client
187- """
188- @spec new(String.t(), String.t()), options) :: Tesla.Env.client()
189- { {/hasHttpBasicMethods} }
190- { {/hasOAuthMethods} }
191-
192- { {#hasOAuthMethods} }
193- def new(token_or_username, scopes_or_password, options \\ [])
194-
195- def new(token, scopes, options)
196- when (is_binary(token) or is_function(token, 1) or is_tuple(token)) and is_list(scopes) do
197- options
198- |> Keyword.merge(token: token, token_scopes: scopes)
199- |> new()
200- end
201- { {/hasOAuthMethods} }
202-
203- { {#hasHttpBasicMethods} }
204- def new(username, password, options) when is_binary(username) and is_binary(password) do
205- options
206- |> Keyword.merge(username: username, password: password)
207- |> new()
208- end
209- { {/hasHttpBasicMethods} }
210-
211109 @doc """
212110 Returns fully configured middleware for passing to Tesla.client/2.
213111 """
0 commit comments