Skip to content

Commit

Permalink
Merge pull request #3 from Recruitee/make-possible-configure-timeouts
Browse files Browse the repository at this point in the history
feat(config): make timeouts configurable
  • Loading branch information
siepet authored Dec 18, 2023
2 parents ce4de36 + 4b63c2b commit 852e059
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions lib/viex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ defmodule Viex do
defp is_valid?({:error, _reason}), do: false

defp request({country, vat}, nil) do
HTTPoison.post(@url, body(country, vat), headers(), params: params())
HTTPoison.post(@url, body(country, vat), headers(), options())
end

defp request({country, vat}, requester_vat) do
{requester_country, requester_vat} = String.split_at(requester_vat, 2)

HTTPoison.post(@url, body(country, vat, requester_country, requester_vat), headers(),
params: params()
HTTPoison.post(
@url,
body(country, vat, requester_country, requester_vat),
headers(),
options()
)
end

Expand All @@ -63,7 +66,7 @@ defmodule Viex do
defp handle_soap_response({:ok, %HTTPoison.Response{status_code: 200, body: body}}),
do: {:ok, body}

defp headers do
defp headers() do
[
{"SOAPAction", ""},
{"Content-Type", "text/xml;charset=UTF-8"}
Expand Down Expand Up @@ -96,5 +99,13 @@ defmodule Viex do
</soapenv:Envelope>)
end

defp params, do: []
defp options() do
[
{:timeout, Application.get_env(:viex, :timeout, 10_000)},
{:recv_timeout, Application.get_env(:viex, :recv_timeout, 10_000)},
{:params, params()}
]
end

defp params(), do: []
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Viex.Mixfile do
def project do
[
app: :viex,
version: "0.3.0",
version: "0.3.1",
elixir: "~> 1.4",
description: "Elixir package to validate European VAT numbers with the VIES service.",
build_embedded: Mix.env() == :prod,
Expand Down

0 comments on commit 852e059

Please sign in to comment.