Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from angelikatyborska/allow-custom-http-client
- Loading branch information
Showing
15 changed files
with
191 additions
and
24 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
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,18 @@ | ||
defmodule Vnu.HTTPClient do | ||
@moduledoc """ | ||
Specification for a Vnu HTTP client. | ||
""" | ||
|
||
@type url() :: String.t() | ||
@type body() :: String.t() | ||
@type header() :: {String.t(), String.t()} | ||
|
||
@type status() :: non_neg_integer() | ||
|
||
@type response() :: %{status: status(), body: body()} | ||
|
||
@doc """ | ||
A callback to make a POST HTTP request. | ||
""" | ||
@callback post(url(), body(), [header()]) :: {:ok, response()} | {:error, any()} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule Vnu.HTTPClient.Hackney do | ||
@moduledoc """ | ||
HTTPoison-based HTTP client adapter. | ||
""" | ||
|
||
@behaviour Vnu.HTTPClient | ||
require Logger | ||
|
||
@impl true | ||
def post(url, body, headers) do | ||
if Code.ensure_loaded?(:hackney) do | ||
with {:ok, status, _headers, body_ref} <- | ||
:hackney.request(:post, url, headers, body, follow_redirect: true), | ||
{:ok, body} <- :hackney.body(body_ref) do | ||
{:ok, %{status: status, body: body}} | ||
else | ||
{:error, error} -> | ||
{:error, error} | ||
end | ||
else | ||
Logger.error(""" | ||
Could not find hackney dependency. | ||
Please add :httpoison to your dependencies: | ||
{:hackney, "~> 1.17"} | ||
Or use a different HTTP client. See Vnu.HTTPClient for more information. | ||
""") | ||
|
||
raise "missing hackney dependency" | ||
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