Magpie.Files.ListFolder (Magpie v0.7.2)

Copy Markdown View Source

Folder listing and change-cursor endpoints (/files/list_folder*).

Listing pages keep their "cursor" and "has_more" keys, but every entry is decoded into a Magpie.FileMetadata, Magpie.FolderMetadata or Magpie.DeletedMetadata struct — see Magpie.Metadata.

Summary

Functions

A way to quickly get a cursor for the folder's state.

Starts returning the contents of a folder. opts accepts the other /files/list_folder argument fields, e.g. "recursive", "limit", "include_deleted" and "include_restorable_info".

Once a cursor has been retrieved from list_folder, use this to paginate through all files and retrieve updates to the folder, following the same rules as documented for list_folder.

Return revisions of a file, each a Magpie.FileMetadata. opts accepts the other /files/list_revisions argument fields, e.g. "mode", "before_rev" and "include_restorable_info".

A longpoll endpoint to wait for changes on an account.

Returns a lazy Stream over all entries of a folder, fetching pages through list_folder/2 + list_folder_continue/2 on demand — no cursor handling needed. Raises Magpie.Error if a page request fails.

Functions

get_latest_cursor(client, path)

@spec get_latest_cursor(Magpie.Client.t(), binary()) :: Magpie.response()

A way to quickly get a cursor for the folder's state.

Example

Magpie.Files.ListFolder.get_latest_cursor(client, "/path")

More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-get_latest_cursor

list_folder(client, path, opts \\ %{})

@spec list_folder(Magpie.Client.t(), binary(), map()) :: Magpie.response()

Starts returning the contents of a folder. opts accepts the other /files/list_folder argument fields, e.g. "recursive", "limit", "include_deleted" and "include_restorable_info".

Example

{:ok, %{"entries" => [%Magpie.FolderMetadata{} | _], "cursor" => cursor, "has_more" => true}} =
  Magpie.Files.ListFolder.list_folder(client, "/path")

More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

list_folder_continue(client, cursor)

@spec list_folder_continue(Magpie.Client.t(), binary()) :: Magpie.response()

Once a cursor has been retrieved from list_folder, use this to paginate through all files and retrieve updates to the folder, following the same rules as documented for list_folder.

Example

Magpie.Files.ListFolder.list_folder_continue(client, cursor)

More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue

list_revisions(client, path, limit \\ 10, opts \\ %{})

@spec list_revisions(Magpie.Client.t(), binary(), number(), map()) ::
  Magpie.response()

Return revisions of a file, each a Magpie.FileMetadata. opts accepts the other /files/list_revisions argument fields, e.g. "mode", "before_rev" and "include_restorable_info".

Example

{:ok, %{"entries" => [%Magpie.FileMetadata{rev: rev} | _], "is_deleted" => false}} =
  Magpie.Files.ListFolder.list_revisions(client, "/report.pdf")

More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-list_revisions

longpoll(client, cursor, timeout \\ 30)

@spec longpoll(Magpie.Client.t(), binary(), pos_integer()) :: Magpie.response()

A longpoll endpoint to wait for changes on an account.

Blocks for at most timeout seconds (30 to 480), plus up to 90 seconds of jitter Dropbox adds to spread out clients. The request waits that long for the response, whatever receive_timeout the client configures.

This endpoint lives on its own host (Magpie.notify_url/0) and takes no access token — Dropbox rejects the call when one is sent.

Example

Magpie.Files.ListFolder.longpoll(client, cursor)

More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-longpoll

stream(client, path, opts \\ %{})

Returns a lazy Stream over all entries of a folder, fetching pages through list_folder/2 + list_folder_continue/2 on demand — no cursor handling needed. Raises Magpie.Error if a page request fails.

Example

client
|> Magpie.Files.ListFolder.stream("/Photos")
|> Stream.filter(&match?(%Magpie.FileMetadata{}, &1))
|> Enum.map(& &1.name)