Upgrade poison (#12)

* Allow http_client to provide HTTP options to HTTPoison

* Add redirection HTTP options

* Move file in API module because it is related to HTTPClient

* Upgrade HTTPoison version

* Docs update

* Add lock file
master
Nicolas 2019-01-21 22:52:47 +01:00 committed by Milton Mazzarri
parent f578833eef
commit bbb55e5876
7 changed files with 37 additions and 11 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## Unreleased
* Updates
- Upgrade to `httpoison ~> 1.4`
* Features
- Allow HTTPClient to get use HTTPoison [HTTP options](https://hexdocs.pm/httpoison/HTTPoison.Request.html) from configuration
## v0.4.0
* Features

View File

@ -419,6 +419,18 @@ iex> Hunter.update_credentials(conn, %{note: "Enum.random(~w(programming cycling
Returns a `Hunter.Account`
### Configuration
Hunter uses [HTTPoison](https://hex.pm/packages/httpoison) as HTTP client layer.
HTTPoison understands a set of [HTTP options](https://hexdocs.pm/httpoison/HTTPoison.Request.html) which can be configured through Hunter configuration :
```
config :hunter, http_options: [follow_redirect: true, hackney: [{:force_redirect, true}]]
```
will tell HTTPoison to follow redirected (301) links when calling mastodon API.
## License
Hunter source code is released under Apache 2 License.

View File

@ -1,3 +1,4 @@
use Mix.Config
config :hunter, hunter_api: Hunter.Api.HTTPClient
config :hunter, http_options: [follow_redirect: true, hackney: [{:force_redirect, true}]]

View File

@ -3,10 +3,12 @@ defmodule Hunter.Api.HTTPClient do
HTTP Client for Hunter
"""
alias Hunter.Request
alias Hunter.Api.Request
@behaviour Hunter.Api
@http_options Application.get_env(:hunter, :http_options, [])
def verify_credentials(conn) do
"/api/v1/accounts/verify_credentials"
|> process_url(conn)
@ -154,7 +156,7 @@ defmodule Hunter.Api.HTTPClient do
def status(conn, id) do
"/api/v1/statuses/#{id}"
|> process_url(conn)
|> request!(conn, :status, :get!, [], get_headers(conn))
|> request!(:status, :get!, [], get_headers(conn))
end
def destroy_status(conn, id) do
@ -330,8 +332,8 @@ defmodule Hunter.Api.HTTPClient do
end
## Helpers
defp request!(url, to, method, payload, headers \\ [], options \\ []) do
with {:ok, body} <- Request.request(method, url, payload, headers, options) do
defp request!(url, to, method, payload, headers \\ []) do
with {:ok, body} <- Request.request(method, url, payload, headers, @http_options) do
transform(body, to)
else
{:error, reason} ->

View File

@ -1,4 +1,4 @@
defmodule Hunter.Request do
defmodule Hunter.Api.Request do
@moduledoc false
def request(http_method, url, data \\ [], headers \\ [], options \\ []) do

View File

@ -27,7 +27,7 @@ defmodule Hunter.Mixfile do
defp deps do
[
{:httpoison, "~> 0.10.0"},
{:httpoison, "~> 1.4"},
{:poison, "~> 3.0"},
{:ex_doc, "~> 0.14", only: :dev, runtime: false}
]

View File

@ -1,10 +1,14 @@
%{"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []},
%{
"certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.6", "5564b4695d48fd87859e9df77a7fa4b4d284d24519f0cd7cc898f09e8fbdc8a3", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"httpoison": {:hex, :httpoison, "0.10.0", "4727b3a5e57e9a4ff168a3c2883e20f1208103a41bccc4754f15a9366f49b676", [:mix], [{:hackney, "~> 1.6.3", [hex: :hackney, optional: false]}]},
"idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []},
"hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.4.0", "e0b3c2ad6fa573134e42194d13e925acfa8f89d138bc621ffb7b1989e6d22e73", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}}
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}