Skip to content

Commit 9eaed79

Browse files
committed
Allow httpoison request options in config
1 parent 87a22f2 commit 9eaed79

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import Config
2424
config :lemon_ex,
2525
api_key: System.get_env("LEMONSQUEEZY_API_KEY"),
2626
webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET")
27+
# (Optional) You can provide HTTPoision options which are added to every request.
28+
# See all options here: https://hexdocs.pm/httpoison/HTTPoison.Request.html#content
29+
request_optionts: [timeout: 10_000]
2730
```
2831

2932
If you don't provide a valid API key, you will receive `401: Unauthorized` error responses.

config/config.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import Config
33
if Mix.env() in [:dev, :test] do
44
config :lemon_ex,
55
api_key: System.get_env("LEMONSQUEEZY_API_KEY", "foobar"),
6-
webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET", "barfoo")
6+
webhook_secret: System.get_env("LEMONSQUEEZY_WEBHOOK_SECRET", "barfoo"),
7+
request_options: [recv_timeout: 5000]
78
end

lib/lemon_ex/request.ex

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ defmodule LemonEx.Request do
66
headers = get_headers()
77
url = "#{@api_base_url}#{url}"
88
payload = prepare_payload(payload)
9-
response = HTTPoison.post(url, payload, headers)
9+
opts = request_options()
10+
response = HTTPoison.post(url, payload, headers, opts)
1011
handle_response(response)
1112
end
1213

@@ -15,7 +16,8 @@ defmodule LemonEx.Request do
1516
headers = get_headers()
1617
url = "#{@api_base_url}#{url}"
1718
filter = prepare_filter(params)
18-
response = HTTPoison.get(url, headers, params: filter)
19+
opts = [params: filter] ++ request_options()
20+
response = HTTPoison.get(url, headers, opts)
1921
handle_response(response)
2022
end
2123

@@ -24,22 +26,28 @@ defmodule LemonEx.Request do
2426
headers = get_headers()
2527
url = "#{@api_base_url}#{url}"
2628
payload = prepare_payload(payload)
27-
response = HTTPoison.patch(url, payload, headers)
29+
opts = request_options()
30+
response = HTTPoison.patch(url, payload, headers, opts)
2831
handle_response(response)
2932
end
3033

3134
@spec delete(binary()) :: :ok | {:ok, map()} | {:error, any()} | {:error, integer(), any()}
3235
def delete(url) do
3336
headers = get_headers()
3437
url = "#{@api_base_url}#{url}"
35-
response = HTTPoison.delete(url, headers)
38+
opts = request_options()
39+
response = HTTPoison.delete(url, headers, opts)
3640
handle_response(response)
3741
end
3842

3943
defp api_key do
4044
Application.get_env(:lemon_ex, :api_key, "")
4145
end
4246

47+
defp request_options do
48+
Application.get_env(:lemon_ex, :request_options, [])
49+
end
50+
4351
defp get_headers do
4452
[
4553
{"Authorization", "Bearer #{api_key()}"},

0 commit comments

Comments
 (0)