CalDAVEx.HTTP (CalDAVEx v0.2.1)

Copy Markdown View Source

Low-level HTTP transport for CalDAV requests.

Wraps Req to issue GET, PUT, DELETE, and the WebDAV/CalDAV extension methods (PROPFIND, PROPPATCH, MKCALENDAR, REPORT), injects standard headers (User-Agent, Content-Type, Accept) and the Authorization header produced by CalDAVEx.Auth, applies the client's configured timeout_ms, and normalizes results into either {:ok, %{status, body, headers}} or {:error, %CalDAVEx.Error{}}.

Summary

Types

HTTP / WebDAV / CalDAV method.

Successful response payload.

Functions

Issues a single HTTP request against a CalDAV server.

Types

method()

@type method() :: atom() | String.t()

HTTP / WebDAV / CalDAV method.

The convenience atoms :propfind, :proppatch, :mkcalendar, and :report are translated to their uppercase string equivalents before being passed to Req. Standard HTTP method atoms (:get, :put, :delete, ...) and raw string methods (e.g. "PATCH") are passed through verbatim.

response()

@type response() :: %{
  status: non_neg_integer(),
  body: term(),
  headers: %{optional(binary()) => [binary()]}
}

Successful response payload.

Functions

request(client, method, url, headers \\ [], body \\ nil)

@spec request(
  CalDAVEx.Client.t(),
  method(),
  String.t(),
  [{String.t(), String.t()}],
  iodata() | nil
) :: {:ok, response()} | {:error, CalDAVEx.Error.t()}

Issues a single HTTP request against a CalDAV server.

Parameters

  • client - a %CalDAVEx.Client{}
  • method - one of :get, :put, :delete, :propfind, :proppatch, :mkcalendar, :report, or any value accepted by Req
  • url - the absolute request URL
  • headers - additional request headers as {name, value} tuples
  • body - request body, or nil for methods that have no body

Returns

  • {:ok, %{status: non_neg_integer, body: term, headers: map}} for 2xx responses
  • {:error, %CalDAVEx.Error{type: :http}} for non-2xx responses
  • {:error, %CalDAVEx.Error{type: :transport}} for connection/transport failures