Magpie 🐦

Hex.pmHexdocsCICoverage StatusLicense: MIT

Elixir client for the Dropbox API v2, built on Req.

Like the bird, Magpie collects and stashes your things — in your Dropbox.

Installation

def deps do
[
{:magpie, "~> 0.5"}
]
end

No configuration is required. Endpoint URLs and extra Req options can be set with config :magpie, ... — see the Magpie module docs.

Quick start

# A refresh token keeps the client working indefinitely — Magpie mints
# access tokens as needed (see the OAuth guide)
client =
Magpie.Client.new(
refresh_token: System.fetch_env!("DROPBOX_REFRESH_TOKEN"),
app_key: System.fetch_env!("DROPBOX_APP_KEY"),
app_secret: System.fetch_env!("DROPBOX_APP_SECRET")
)
# For a quick script, a static access token works too (Dropbox expires it in ~4h)
client = Magpie.Client.new("DROPBOX_ACCESS_TOKEN")
alias Magpie.Storage
{:ok, %Magpie.FileMetadata{size: size}} =
Storage.put(client, "/Backup/report.pdf", {:file, "priv/report.pdf"})
{:ok, contents} = Storage.get(client, "/Backup/report.pdf")
{:ok, url} = Storage.url(client, "/Backup/report.pdf")
# Large downloads stream directly to disk instead of living in BEAM memory
{:ok, "tmp/report.pdf"} =
Storage.download(client, "/Backup/report.pdf", "tmp/report.pdf", mkdir_p: true)

Every call returns {:ok, result} on success or {:error, %Magpie.Error{}} on API errors — with the HTTP status, Dropbox's error_summary and the full error body. Files, folders and deleted entries come back as Magpie.FileMetadata, Magpie.FolderMetadata and Magpie.DeletedMetadata structs:

for %Magpie.FileMetadata{name: name, size: size, server_modified: at} <- entries do
"#{name}: #{size} bytes, modified #{DateTime.to_date(at)}"
end

Features

Documentation

The API reference lives on HexDocs, along with the guides:

Development

The test suite runs entirely offline against Req.Test stubs:

mix test # run the suite
mix coveralls # run with coverage report

Origin

Magpie started as a fork of sger/elixir_dropbox, which is no longer maintained. It has since been rewritten on top of Req/Jason with a new offline test suite. Credit and thanks to the original Elixir Dropbox contributors.

License

MIT — see LICENSE.