ExNtfy.Client (ex_ntfy v0.1.0)

Copy Markdown View Source

Req-based HTTP client for the ntfy API.

new/1 builds a configured Req.Request from ExNtfy.Config options; request/2 executes it and normalizes failures into ExNtfy.Error. Feature modules (publish, poll, subscribe) build request options and call request/2 — callers are not expected to use Req directly.

Summary

Functions

Builds a configured Req.Request.

Executes a request and normalizes the outcome.

Functions

new(opts \\ [])

@spec new([ExNtfy.Config.option()]) :: Req.Request.t()

Builds a configured Req.Request.

Options are resolved through ExNtfy.Config.resolve/2 (per-call opts > application config > defaults). :req_options is merged last via Req.merge/2, so anything in it — including plug: for tests — wins over the computed defaults.

request(req_or_opts, req_opts \\ [])

@spec request(
  Req.Request.t() | [ExNtfy.Config.option()],
  keyword()
) :: {:ok, Req.Response.t()} | {:error, ExNtfy.Error.t()}

Executes a request and normalizes the outcome.

Accepts either a Req.Request from new/1 or a keyword list of client options (built into a request on the fly). req_opts are per-request Req options such as :method, :url, :body, :params.

Returns {:ok, response} for 2xx responses; any other status becomes {:error, %ExNtfy.Error{}} via ExNtfy.Error.from_response/2, and transport failures become {:error, %ExNtfy.Error{reason: exception}}.