SaltDns.Registrar.Openprovider.Client (Salt v1.0.0)

The one place that speaks HTTP to Openprovider. The adapter (SaltDns.Registrar.Openprovider) builds requests and reads answers; this module logs in, keeps the token (SaltDns.Registrar.Openprovider.Tokens), sends the request and turns every kind of failure into {:error, {kind, message}} (see SaltDns.Registrar.Adapter).

Every answer is an envelope {"code": 0, "desc": "", "data": {...}}; a non-zero code is an error even on HTTP 200, and the registrar also sends the envelope with HTTP 4xx and 5xx (insufficient funds is HTTP 500, code 920). The body is decoded with Decimal for numbers with decimals, so prices never pass through a float.

Logging. One line per call: the call name, HTTP status, duration and the registrar's code. Request and response bodies are never logged (they hold personal data and auth codes), and neither are the token or the password.

Retries. A call is sent once. The only repeat is a single new login and resend when the registrar answers 401 (an expired token); the call is not repeated for any other reason, because a buying call must not run twice.

Settings

config :salt_dns, SaltDns.Registrar.Openprovider:

  • :base_urls - %{live: url, sandbox: url}, default https://api.openprovider.eu and https://api.cte.openprovider.eu (the registrar's test system, named in its public API description);
  • :login_version (default "v1") and :api_version (default "v1beta"), the path prefixes of the login call and of every other call;
  • :refresh_after - seconds a token is used (default 40 hours);
  • :req_options - extra Req options (tests put a stub plug here).

Summary

Functions

Sends one call and returns the data of the envelope. name is the short call name used in the log. Options: :params (query), :body (JSON).

Logs in and returns the reseller id (a connection test with no other effect).

The most a call can take, in seconds: it logs in (one request) and sends the request, and when the registrar refuses the token it logs in again and sends the request again; four requests, each at most the connect and the receive timeout. SaltDns.Registrar keeps its time for taking an operation for dead longer than a whole execution of such calls.

Types

result()

@type result() :: {:ok, term()} | {:error, {atom(), String.t() | map()}}

Functions

call(provider, name, method, path, opts \\ [])

@spec call(
  SaltDns.Registrar.Provider.t(),
  String.t(),
  :get | :post | :put | :delete,
  String.t(),
  keyword()
) :: result()

Sends one call and returns the data of the envelope. name is the short call name used in the log. Options: :params (query), :body (JSON).

login(provider)

@spec login(SaltDns.Registrar.Provider.t()) ::
  {:ok, term()} | {:error, {atom(), String.t()}}

Logs in and returns the reseller id (a connection test with no other effect).

worst_case_seconds()

@spec worst_case_seconds() :: pos_integer()

The most a call can take, in seconds: it logs in (one request) and sends the request, and when the registrar refuses the token it logs in again and sends the request again; four requests, each at most the connect and the receive timeout. SaltDns.Registrar keeps its time for taking an operation for dead longer than a whole execution of such calls.