Belt v0.5.1 Belt.Provider behaviour View Source

Defines a Belt Provider.

Providers allow Belt to interface with storage destinations.

This module’s __using__ macro automatically sets up supervision and GenStage handling for a provider. Alternatively, a provider may just adopt the Behaviour defined by Belt.Provider and provide a custom implementation of these components.

Usage

defmodule Belt.Provider.MyProvider do
  use Belt.Provider

  def new(options) do
    #…
  end
  #…
end

Link to this section Summary

Types

Configuration type used by provider callbacks. Contains provider-specific configuration data

Options supported by aĺl providers for Belt.delete/3. Additional options might be supported by certain providers and are documented there

Identifier that can be used together with a configuration to retrieve or manipulate a stored file

Possible file sources for Belt.Provider.store/3. Currently supported types:

  • Path.t - a path to a file on the local filesystem
  • %{path: Path.t, filename: String.t} - a Map following the format of Plug.Upload

Options supported by aĺl providers for Belt.get_info/3. Additional options might be supported by certain providers and are documented there

Options supported by aĺl providers for Belt.list_files/2. Additional options might be supported by certain providers and are documented there

Options supported by all providers for Belt.store/3, Belt.store_async/3, Belt.store_data/3 and Belt.store_data_async/3. Additional options might be supported by certain providers and are documented there

Options supported by aĺl providers for Belt.get_url/3. Additional options might be supported by certain providers and are documented there

Callbacks

Creates a new configuration struct with default credentials. Providers can implement this to pull defaults from the application configuration and/or environment variables at runtime

Deletes a file using the provided configuration and identifier

Deletes all file accessible through a configuration

Deletes all files within a scope of a configuration

Retrieves %Belt.FileInfo{} struct for given file

Retrieves url for given file

Lists all files for a given provider

Creates a new configuration struct

Stores a file using the provided configuration

Stores an in-memory iodata using the provided configuration

Tests if a connection can be established with the given provider

Link to this section Types

Link to this type configuration() View Source
configuration() :: %{provider: :atom}

Configuration type used by provider callbacks. Contains provider-specific configuration data.

Link to this type delete_option() View Source
delete_option() :: Belt.request_option() | {atom() | term()}

Options supported by aĺl providers for Belt.delete/3. Additional options might be supported by certain providers and are documented there.

Link to this type file_identifier() View Source
file_identifier() :: String.t() | %{identifier: String.t()}

Identifier that can be used together with a configuration to retrieve or manipulate a stored file.

Link to this type file_source() View Source
file_source() :: Path.t() | %{path: Path.t(), filename: String.t()}

Possible file sources for Belt.Provider.store/3. Currently supported types:

  • Path.t - a path to a file on the local filesystem
  • %{path: Path.t, filename: String.t} - a Map following the format of Plug.Upload
Link to this type info_option() View Source
info_option() ::
  {:hashes, [Belt.Hasher.hash_algorithm()]}
  | Belt.request_option()
  | {atom() | term()}

Options supported by aĺl providers for Belt.get_info/3. Additional options might be supported by certain providers and are documented there.

Link to this type list_files_option() View Source
list_files_option() :: Belt.request_option() | {atom() | term()}

Options supported by aĺl providers for Belt.list_files/2. Additional options might be supported by certain providers and are documented there.

Link to this type store_option() View Source
store_option() ::
  {:hashes, [Belt.Hasher.hash_algorithm()]}
  | {:key, String.t() | :auto}
  | {:overwrite, boolean() | :rename}
  | {:scope, String.t()}
  | Belt.request_option()
  | {:atom, term()}

Options supported by all providers for Belt.store/3, Belt.store_async/3, Belt.store_data/3 and Belt.store_data_async/3. Additional options might be supported by certain providers and are documented there.

Link to this type url_option() View Source
url_option() :: Belt.request_option() | {atom() | term()}

Options supported by aĺl providers for Belt.get_url/3. Additional options might be supported by certain providers and are documented there.

Link to this section Callbacks

Link to this callback default(options) View Source
default(options :: list()) :: {:ok, configuration()} | {:error, term()}

Creates a new configuration struct with default credentials. Providers can implement this to pull defaults from the application configuration and/or environment variables at runtime.

Additionally provided options will override the defaults.

Link to this callback delete(configuration, identifier, list) View Source
delete(configuration(), identifier(), list()) :: :ok | {:error, term()}

Deletes a file using the provided configuration and identifier.

Link to this callback delete_all(configuration, list) View Source
delete_all(configuration(), list()) :: :ok | {:error, term()}

Deletes all file accessible through a configuration.

Link to this callback delete_scope(configuration, arg1, list) View Source
delete_scope(configuration(), String.t(), list()) :: :ok | {:error, term()}

Deletes all files within a scope of a configuration.

Link to this callback get_info(configuration, identifier, list) View Source
get_info(configuration(), identifier(), [info_option()]) ::
  {:ok, Belt.FileInfo.t()}

Retrieves %Belt.FileInfo{} struct for given file.

Link to this callback get_url(configuration, identifier, list) View Source
get_url(configuration(), identifier(), [url_option()]) ::
  {:ok, Belt.FileInfo.t()} | :unavailable | {:error, term()}

Retrieves url for given file.

Link to this callback list_files(configuration, list) View Source
list_files(configuration(), [list_files_option()]) ::
  {:ok, [identifier()]} | {:error, term()}

Lists all files for a given provider.

Link to this callback new(options) View Source
new(options :: list()) :: {:ok, configuration()} | {:error, term()}

Creates a new configuration struct.

Link to this callback store(configuration, file_source, list) View Source
store(configuration(), file_source :: file_source(), [store_option()]) ::
  {:ok, Belt.FileInfo.t()} | {:error, term()}

Stores a file using the provided configuration.

Link to this callback store_data(configuration, iodata, list) View Source
store_data(configuration(), iodata(), [store_option()]) ::
  {:ok, Belt.FileInfo.t()} | {:error, term()}

Stores an in-memory iodata using the provided configuration.

Link to this callback test_connection(configuration, list) View Source
test_connection(configuration(), [Belt.request_option()]) ::
  :ok | {:error, term()}

Tests if a connection can be established with the given provider.