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

parse_exists(arg)

@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.

parse_result(arg)

@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.

path(index, suffix)

Builds an endpoint path for an optional index target: suffix alone when the target is empty, /{index} + suffix otherwise.

put_codec_opts(opts, extra)

@spec put_codec_opts(keyword(), keyword()) :: keyword()

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.

put_default_format(opts, key, format)

@spec put_default_format(keyword(), atom(), atom()) :: keyword()

Applies a default :req_format/:resp_format, unless the caller already set it — or set :format, which is mutually exclusive with both.

put_param(opts, key, value)

@spec put_param(keyword(), atom(), term()) :: keyword()

Appends a query-string parameter to opts[:params], preserving any params the caller already set.

required_path(index, suffix)

@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.