diff --git a/README.md b/README.md index c807ff2..0ff8617 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ import Config config :lemon_ex, api_key: System.get_env("LEMONSQUEEZY_API_KEY"), webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET") + # (Optional) You can provide HTTPoision options which are added to every request. + # See all options here: https://hexdocs.pm/httpoison/HTTPoison.Request.html#content + request_optionts: [timeout: 10_000] ``` If you don't provide a valid API key, you will receive `401: Unauthorized` error responses. diff --git a/config/config.exs b/config/config.exs index ac15b18..aa15e01 100644 --- a/config/config.exs +++ b/config/config.exs @@ -3,5 +3,6 @@ import Config if Mix.env() in [:dev, :test] do config :lemon_ex, api_key: System.get_env("LEMONSQUEEZY_API_KEY", "foobar"), - webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET", "barfoo") + webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET", "barfoo"), + request_options: [recv_timeout: 5000] end diff --git a/lib/lemon_ex/request.ex b/lib/lemon_ex/request.ex index b20e53e..c129cfb 100644 --- a/lib/lemon_ex/request.ex +++ b/lib/lemon_ex/request.ex @@ -6,7 +6,8 @@ defmodule LemonEx.Request do headers = get_headers() url = "#{@api_base_url}#{url}" payload = prepare_payload(payload) - response = HTTPoison.post(url, payload, headers) + opts = request_options() + response = HTTPoison.post(url, payload, headers, opts) handle_response(response) end @@ -15,7 +16,8 @@ defmodule LemonEx.Request do headers = get_headers() url = "#{@api_base_url}#{url}" filter = prepare_filter(params) - response = HTTPoison.get(url, headers, params: filter) + opts = [params: filter] ++ request_options() + response = HTTPoison.get(url, headers, opts) handle_response(response) end @@ -24,7 +26,8 @@ defmodule LemonEx.Request do headers = get_headers() url = "#{@api_base_url}#{url}" payload = prepare_payload(payload) - response = HTTPoison.patch(url, payload, headers) + opts = request_options() + response = HTTPoison.patch(url, payload, headers, opts) handle_response(response) end @@ -32,7 +35,8 @@ defmodule LemonEx.Request do def delete(url) do headers = get_headers() url = "#{@api_base_url}#{url}" - response = HTTPoison.delete(url, headers) + opts = request_options() + response = HTTPoison.delete(url, headers, opts) handle_response(response) end @@ -40,6 +44,10 @@ defmodule LemonEx.Request do Application.get_env(:lemon_ex, :api_key, "") end + defp request_options do + Application.get_env(:lemon_ex, :request_options, []) + end + defp get_headers do [ {"Authorization", "Bearer #{api_key()}"},