Dowser. Elasticsearch. Helpers
(Dowser.Elasticsearch v0.1.0)
View Source
Shared plumbing for the API modules: result parsing, path building and option handling.
Summary
Functions
Parses a Dowser.Client result of a HEAD existence check: {:ok, true}
for a 2xx response, {:ok, false} for a 404, and an error otherwise.
Parses a Dowser.Client result into {:ok, body} for a 2xx response,
{:error, %Dowser.Elasticsearch.Error{}} for any other status, and passes
{:error, exception} through untouched.
Builds an endpoint path for an optional index target: suffix alone when
the target is empty, /{index} + suffix otherwise.
Merges extra into opts[:codec_opts] — supplying the context
Dowser.Elasticsearch.TypeCodec needs (e.g. :index) for an endpoint's
request/response shape, without overwriting any key the caller already set
there themselves.
Applies a default :req_format/:resp_format, unless the caller already
set it — or set :format, which is mutually exclusive with both.
Appends a query-string parameter to opts[:params], preserving any params
the caller already set.
Like path/2, but for endpoints that require an index target; raises
ArgumentError when the target is empty.
Functions
@spec parse_exists(Dowser.Client.result()) :: {:ok, boolean()} | {:error, Exception.t()}
Parses a Dowser.Client result of a HEAD existence check: {:ok, true}
for a 2xx response, {:ok, false} for a 404, and an error otherwise.
@spec parse_result(Dowser.Client.result()) :: {:ok, term()} | {:error, Exception.t()}
Parses a Dowser.Client result into {:ok, body} for a 2xx response,
{:error, %Dowser.Elasticsearch.Error{}} for any other status, and passes
{:error, exception} through untouched.
@spec path(Dowser.Elasticsearch.Index.t(), String.t()) :: binary()
Builds an endpoint path for an optional index target: suffix alone when
the target is empty, /{index} + suffix otherwise.
Merges extra into opts[:codec_opts] — supplying the context
Dowser.Elasticsearch.TypeCodec needs (e.g. :index) for an endpoint's
request/response shape, without overwriting any key the caller already set
there themselves.
Applies a default :req_format/:resp_format, unless the caller already
set it — or set :format, which is mutually exclusive with both.
Appends a query-string parameter to opts[:params], preserving any params
the caller already set.
@spec required_path(Dowser.Elasticsearch.Index.t(), String.t()) :: binary()
Like path/2, but for endpoints that require an index target; raises
ArgumentError when the target is empty.