Noizu.Dropbox.HTTP (Noizu Dropbox v0.1.0)

Copy Markdown View Source

Low-level HTTP helpers for Dropbox API v2.

Dropbox uses three styles of endpoints:

  • RPC — JSON body in, JSON body out (api.dropboxapi.com)
  • Content upload — binary body in, JSON metadata out; args in Dropbox-API-Arg
  • Content download — binary body out; args in Dropbox-API-Arg; metadata in Dropbox-API-Result response header

Summary

Functions

Content-download endpoint: returns %{metadata: map, body: binary, headers: list}.

Content-upload endpoint: binary body, args via Dropbox-API-Arg header.

POST application/x-www-form-urlencoded (token endpoints).

Call a notify-domain endpoint (e.g. files/list_folder/longpoll).

Call an RPC endpoint (POST JSON → JSON).

RPC with an empty JSON object body (null is also accepted by some endpoints).

Types

download_result()

@type download_result() ::
  {:ok, %{metadata: map(), body: binary(), headers: list()}}
  | {:error, Noizu.Dropbox.Error.t()}

options()

@type options() :: keyword() | map() | nil

result()

@type result() :: {:ok, term()} | {:error, Noizu.Dropbox.Error.t()}

Functions

content_download(path, arg, opts \\ [])

@spec content_download(String.t(), map(), options()) :: download_result()

Content-download endpoint: returns %{metadata: map, body: binary, headers: list}.

content_upload(path, data, arg, opts \\ [])

@spec content_upload(String.t(), binary(), map(), options()) :: result()

Content-upload endpoint: binary body, args via Dropbox-API-Arg header.

form_post(url, form, opts \\ [])

@spec form_post(String.t(), keyword() | map(), options()) :: result()

POST application/x-www-form-urlencoded (token endpoints).

notify(path, opts \\ [])

@spec notify(String.t(), options()) :: result()

Call a notify-domain endpoint (e.g. files/list_folder/longpoll).

rpc(path, opts \\ [])

@spec rpc(String.t(), options()) :: result()

Call an RPC endpoint (POST JSON → JSON).

Options

  • :client%Noizu.Dropbox.Client{} (default: Client.default())
  • :body — request map (default: %{} or nil for no body)
  • :decode:atoms (default), :strings, :raw, or a module with from_json/1
  • :auth:user (default bearer token), :app (basic app key/secret), :none
  • :headers — extra headers
  • :timeout — receive timeout override

rpc_empty(path, opts \\ [])

@spec rpc_empty(String.t(), options()) :: result()

RPC with an empty JSON object body (null is also accepted by some endpoints).