WardrikDaemon.Client (wardrik_daemon v0.1.0-rc.1)

Copy Markdown

Reaches a daemon over its HTTP API. The wardrik command uses it.

client = %WardrikDaemon.Client{url: "http://127.0.0.1:4747", secret: secret}
{:ok, answer} = WardrikDaemon.Client.run(client, "agents.list", %{})

Each WardrikProtocol operation is sent to its route, with secret as the bearer token.

Summary

Types

Why an operation failed: the protocol's error type, and its message.

t()

Functions

Stops reading an opened stream.

Returns the next events on an opened stream. Waits at most timeout. Returns :done once the stream ends.

Opens the operation id's events as server-sent events. Read them with next/2.

Runs the operation id with input. Returns its answer, or nil if it answers nothing.

Types

error()

@type error() :: {:error, String.t(), String.t()}

Why an operation failed: the protocol's error type, and its message.

t()

@type t() :: %WardrikDaemon.Client{
  req_options: keyword(),
  secret: String.t(),
  url: String.t()
}

Functions

close(response)

@spec close(Req.Response.t()) :: :ok

Stops reading an opened stream.

next(response, timeout)

@spec next(Req.Response.t(), timeout()) ::
  {:ok, [map()], Req.Response.t()} | :done | :timeout

Returns the next events on an opened stream. Waits at most timeout. Returns :done once the stream ends.

open(client, id, input)

@spec open(t(), String.t(), map()) :: {:ok, Req.Response.t()} | error()

Opens the operation id's events as server-sent events. Read them with next/2.

It returns once the daemon is following them, so nothing written after it returns is missed.

run(client, id, input)

@spec run(t(), String.t(), map()) :: {:ok, map() | nil} | error()

Runs the operation id with input. Returns its answer, or nil if it answers nothing.