-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
0a1a5eb
commit 5bbd5ee
Showing
14 changed files
with
277 additions
and
31 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
if Code.ensure_loaded?(Req) do | ||
defmodule Assent.HTTPAdapter.Req do | ||
@moduledoc """ | ||
HTTP adapter module for making http requests with Req. | ||
You can also override the Req options by updating the configuration: | ||
http_adapter: {Assent.HTTPAdapter.Req, [...]} | ||
See `Assent.HTTPAdapter` for more. | ||
""" | ||
alias Assent.{HTTPAdapter, HTTPAdapter.HTTPResponse} | ||
|
||
@behaviour HTTPAdapter | ||
|
||
@impl HTTPAdapter | ||
def request(method, url, body, headers, req_opts \\ nil) do | ||
headers = headers ++ [HTTPAdapter.user_agent_header()] | ||
opts = req_opts || [] | ||
|
||
opts = | ||
Keyword.merge([ | ||
method: method, | ||
url: url, | ||
headers: headers, | ||
body: body | ||
], opts) | ||
|
||
opts | ||
|> Req.new() | ||
|> Req.request() | ||
|> case do | ||
{:ok, response} -> | ||
headers = Enum.map(headers, fn {key, value} -> {String.downcase(to_string(key)), to_string(value)} end) | ||
|
||
{:ok, %HTTPResponse{status: response.status, headers: headers, body: response.body}} | ||
|
||
{:error, error} -> | ||
{:error, error} | ||
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
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
Oops, something went wrong.