Magpie (Magpie v0.1.0)

Copy Markdown View Source

Core HTTP layer for the Dropbox API v2.

Builds authenticated Req requests and normalizes responses. RPC-style endpoints go through post/3, while content endpoints (file bytes) go through upload_request/5 and download_request/5.

The Dropbox endpoints can be overridden (rarely needed) via:

config :magpie,
  base_url: "https://api.dropboxapi.com/2",
  upload_url: "https://content.dropboxapi.com/2/"

Extra options merged into every request (e.g. plug: {Req.Test, Magpie} for testing) can be set with config :magpie, req_options: [...].

Summary

Functions

Base URL for RPC endpoints.

Send an RPC request to a Dropbox endpoint, JSON-encoding body when given.

Same as post/3 but against an explicit base URL (used by content endpoints that speak JSON, such as /files/get_thumbnail_batch).

Upload data (iodata or enumerable) as the raw request body. Used by content endpoints that take bytes directly instead of a local file.

Upload the file at local path file as the raw request body. The file is streamed, so large files are not loaded into memory at once.

Base URL for content (upload/download) endpoints.

Types

response()

@type response() :: {:ok, term()} | {:error, Magpie.Error.t()}

response_download()

@type response_download() ::
  {:ok, %{body: binary(), headers: list() | map()}} | {:error, Magpie.Error.t()}

Functions

base_url()

Base URL for RPC endpoints.

download_request(client, base_url, url, data, headers)

download_response(response)

@spec download_response(Req.Response.t()) :: response_download()

new_req(client, opts \\ [])

post(client, url, body \\ "")

@spec post(struct(), binary(), term()) :: response()

Send an RPC request to a Dropbox endpoint, JSON-encoding body when given.

post_request(req, url, body \\ "", headers \\ [])

post_url(client, base_url, url, body \\ "")

@spec post_url(struct(), binary(), binary(), term()) :: response()

Same as post/3 but against an explicit base URL (used by content endpoints that speak JSON, such as /files/get_thumbnail_batch).

process_response(response)

@spec process_response(Req.Response.t()) :: response()

upload_data_request(client, base_url, url, data, headers)

Upload data (iodata or enumerable) as the raw request body. Used by content endpoints that take bytes directly instead of a local file.

upload_request(client, base_url, url, file, headers)

Upload the file at local path file as the raw request body. The file is streamed, so large files are not loaded into memory at once.

upload_url()

Base URL for content (upload/download) endpoints.