diff --git a/lib/ex_bank_id/auth.ex b/lib/ex_bank_id/auth.ex index 9425970..551fe2c 100644 --- a/lib/ex_bank_id/auth.ex +++ b/lib/ex_bank_id/auth.ex @@ -1,26 +1,27 @@ defmodule ExBankID.Auth do - @options [ - url: [ - type: :string, - default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") - ], - cert_file: [ - type: :string, - default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") - ], - personal_number: [ - type: :string - # TODO: Add validator - ], - http_client: [ - type: :atom, - default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + defp options() do + [ + url: [ + type: :string, + default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") + ], + cert_file: [ + type: :string, + default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") + ], + personal_number: [ + type: :string + # TODO: Add validator + ], + http_client: [ + type: :atom, + default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + ] ] - ] - @doc "Supported options:\n#{NimbleOptions.docs(@options)}" + end def auth(ip_address, opts) when is_binary(ip_address) and is_list(opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %ExBankID.Auth.Payload{} <- ExBankID.Auth.Payload.new(ip_address, opts) do ExBankID.HttpRequest.send_request(payload, opts) end diff --git a/lib/ex_bank_id/cancel.ex b/lib/ex_bank_id/cancel.ex index 2c6073c..0be1b31 100644 --- a/lib/ex_bank_id/cancel.ex +++ b/lib/ex_bank_id/cancel.ex @@ -1,26 +1,27 @@ defmodule ExBankID.Cancel do alias ExBankID.Cancel.Payload - @options [ - url: [ - type: :string, - default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") - ], - cert_file: [ - type: :string, - default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") - ], - http_client: [ - type: :atom, - default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + defp options() do + [ + url: [ + type: :string, + default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") + ], + cert_file: [ + type: :string, + default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") + ], + http_client: [ + type: :atom, + default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + ] ] - ] - @doc "Supported options:\n#{NimbleOptions.docs(@options)}" + end def cancel(token, opts \\ []) def cancel(token, opts) when is_binary(token) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) @@ -28,7 +29,7 @@ defmodule ExBankID.Cancel do end def cancel(token = %ExBankID.Auth.Response{}, opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) @@ -36,7 +37,7 @@ defmodule ExBankID.Cancel do end def cancel(token = %ExBankID.Sign.Response{}, opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) diff --git a/lib/ex_bank_id/collect.ex b/lib/ex_bank_id/collect.ex index 323bbb0..51317a0 100644 --- a/lib/ex_bank_id/collect.ex +++ b/lib/ex_bank_id/collect.ex @@ -1,26 +1,27 @@ defmodule ExBankID.Collect do alias ExBankID.Collect.Payload - @options [ - url: [ - type: :string, - default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") - ], - cert_file: [ - type: :string, - default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") - ], - http_client: [ - type: :atom, - default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + defp options() do + [ + url: [ + type: :string, + default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") + ], + cert_file: [ + type: :string, + default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") + ], + http_client: [ + type: :atom, + default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + ] ] - ] - @doc "Supported options:\n#{NimbleOptions.docs(@options)}" + end def collect(token, opts \\ []) def collect(token, opts) when is_binary(token) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) @@ -28,7 +29,7 @@ defmodule ExBankID.Collect do end def collect(token = %ExBankID.Auth.Response{}, opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) @@ -36,7 +37,7 @@ defmodule ExBankID.Collect do end def collect(token = %ExBankID.Sign.Response{}, opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Payload{} <- Payload.new(token) do ExBankID.HttpRequest.send_request(payload, opts) diff --git a/lib/ex_bank_id/sign.ex b/lib/ex_bank_id/sign.ex index 2ea0025..080a15b 100644 --- a/lib/ex_bank_id/sign.ex +++ b/lib/ex_bank_id/sign.ex @@ -1,32 +1,33 @@ defmodule ExBankID.Sign do alias ExBankID.Sign - @options [ - url: [ - type: :string, - default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") - ], - cert_file: [ - type: :string, - default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") - ], - personal_number: [ - type: :string - # TODO: Add validator - ], - user_non_visible_data: [ - type: :string - ], - http_client: [ - type: :atom, - default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + defp options() do + [ + url: [ + type: :string, + default: Application.get_env(:ex_bank_id, :url, "https://appapi2.test.bankid.com/rp/v5.1/") + ], + cert_file: [ + type: :string, + default: Application.get_env(:ex_bank_id, :cert_file, __DIR__ <> "/../../assets/test.pem") + ], + personal_number: [ + type: :string + # TODO: Add validator + ], + user_non_visible_data: [ + type: :string + ], + http_client: [ + type: :atom, + default: Application.get_env(:ex_bank_id, :http_client, ExBankID.Http.Default) + ] ] - ] - @doc "Supported options:\n#{NimbleOptions.docs(@options)}" + end def sign(ip_address, user_visible_data, opts \\ []) when is_binary(ip_address) and is_binary(user_visible_data) and is_list(opts) do - with {:ok, opts} <- NimbleOptions.validate(opts, @options), + with {:ok, opts} <- NimbleOptions.validate(opts, options()), payload = %Sign.Payload{} <- Sign.Payload.new(ip_address, user_visible_data, opts) do ExBankID.HttpRequest.send_request(payload, opts) end