-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aec1004
commit 1f16155
Showing
63 changed files
with
2,488 additions
and
1,264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Used by "mix format" and to export configuration. | ||
export_locals_without_parens = [ | ||
plug: 1, | ||
plug: 2, | ||
get: 2 | ||
] | ||
|
||
[ | ||
inputs: ["{mix,.formatter}.exs", "{integration,lib,test}/**/*.{ex,exs}"], | ||
locals_without_parens: export_locals_without_parens, | ||
export: [locals_without_parens: export_locals_without_parens] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,46 @@ | ||
if Code.ensure_loaded?(Finch) do | ||
defmodule Assent.HTTPAdapter.Finch do | ||
@moduledoc """ | ||
HTTP adapter module for making http requests with Finch. | ||
defmodule Assent.HTTPAdapter.Finch do | ||
@moduledoc """ | ||
HTTP adapter module for making http requests with Finch. | ||
The Finch adapter must be configured with the supervisor by passing it as an | ||
option: | ||
The Finch adapter must be configured with the supervisor by passing it as an | ||
option: | ||
http_adapter: {Assent.HTTPAdapter.Finch, [supervisor: MyFinch]} | ||
http_adapter: {Assent.HTTPAdapter.Finch, [supervisor: MyFinch]} | ||
See `Assent.HTTPAdapter` for more. | ||
""" | ||
alias Assent.{HTTPAdapter, HTTPAdapter.HTTPResponse} | ||
See `Assent.HTTPAdapter` for more. | ||
""" | ||
alias Assent.{HTTPAdapter, HTTPAdapter.HTTPResponse} | ||
|
||
@behaviour HTTPAdapter | ||
@behaviour HTTPAdapter | ||
|
||
@impl HTTPAdapter | ||
def request(method, url, body, headers, finch_opts \\ nil) do | ||
headers = headers ++ [HTTPAdapter.user_agent_header()] | ||
opts = finch_opts || [] | ||
@impl HTTPAdapter | ||
def request(method, url, body, headers, finch_opts \\ nil) do | ||
headers = headers ++ [HTTPAdapter.user_agent_header()] | ||
opts = finch_opts || [] | ||
|
||
supervisor = Keyword.get(opts, :supervisor) || raise "Missing `:supervisor` option for the #{inspect __MODULE__} configuration" | ||
build_opts = Keyword.get(opts, :build, []) | ||
request_opts = Keyword.get(opts, :request, []) | ||
supervisor = | ||
Keyword.get(opts, :supervisor) || | ||
raise "Missing `:supervisor` option for the #{inspect(__MODULE__)} configuration" | ||
|
||
method | ||
|> Finch.build(url, headers, body, build_opts) | ||
|> Finch.request(supervisor, request_opts) | ||
|> case do | ||
{:ok, response} -> {:ok, %HTTPResponse{status: response.status, headers: response.headers, body: response.body}} | ||
{:error, error} -> {:error, error} | ||
build_opts = Keyword.get(opts, :build, []) | ||
request_opts = Keyword.get(opts, :request, []) | ||
|
||
method | ||
|> Finch.build(url, headers, body, build_opts) | ||
|> Finch.request(supervisor, request_opts) | ||
|> case do | ||
{:ok, response} -> | ||
{:ok, | ||
%HTTPResponse{ | ||
status: response.status, | ||
headers: response.headers, | ||
body: response.body | ||
}} | ||
|
||
{:error, error} -> | ||
{:error, error} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.