@@ -77,137 +77,23 @@ defmodule {{moduleName}}.Connection do
7777 defdelegate request(client, options), to: Tesla
7878
7979 @doc """
80- Configure a client with no authentication.
81-
82- ### Returns
83-
84- Tesla.Env.client
85- """
86- @spec new() :: Tesla.Env.client()
87- def new do
88- Tesla.client(middleware(), adapter())
89- end
90-
91- @doc """
92- Configure a client that may have authentication.
80+ Configure a { {moduleName} } client.
9381
9482 ### Parameters
9583
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} }
105- - `options`: a keyword list of { {moduleName} }.Connection.options.
84+ - `options`: an optional keyword list of { {moduleName} }.Connection.options.
10685
10786 ### Returns
10887
10988 Tesla.Env.client
11089 """
111- { {#hasOAuthMethods} }
112- @spec new(String.t() | token_fetcher | options) :: Tesla.Env.client()
113- { {/hasOAuthMethods} }
114- { {^hasOAuthMethods} }
11590 @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-
123- def new(options) when is_list(options) do
91+ def new(options \\ []) do
12492 options
12593 |> middleware()
12694 |> Tesla.client(adapter())
12795 end
12896
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-
21197 @doc """
21298 Returns fully configured middleware for passing to Tesla.client/2.
21399 """
0 commit comments