mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
31 lines
875 B
Elixir
31 lines
875 B
Elixir
defmodule PhilomenaMedia.Req do
|
|
@behaviour ExAws.Request.HttpClient
|
|
|
|
@moduledoc """
|
|
Configuration for `m:Req`.
|
|
|
|
Options can be set for `m:Req` with the following config:
|
|
|
|
config :philomena, :req_opts,
|
|
receive_timeout: 30_000
|
|
|
|
The default config handles setting the above.
|
|
"""
|
|
|
|
@default_opts [receive_timeout: 30_000]
|
|
|
|
@impl true
|
|
def request(method, url, body \\ "", headers \\ [], http_opts \\ []) do
|
|
[method: method, url: url, body: body, headers: headers, decode_body: false]
|
|
|> Keyword.merge(Application.get_env(:philomena, :req_opts, @default_opts))
|
|
|> Keyword.merge(http_opts)
|
|
|> Req.request()
|
|
|> case do
|
|
{:ok, %{status: status, headers: headers, body: body}} ->
|
|
{:ok, %{status_code: status, headers: headers, body: body}}
|
|
|
|
{:error, reason} ->
|
|
{:error, %{reason: reason}}
|
|
end
|
|
end
|
|
end
|