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 ofPlug.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
Configuration type used by provider callbacks. Contains provider-specific configuration data.
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.
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 ofPlug.Upload
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.
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.
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.
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
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.
delete(configuration(), identifier(), list()) :: :ok | {:error, term()}
Deletes a file using the provided configuration and identifier.
delete_all(configuration(), list()) :: :ok | {:error, term()}
Deletes all file accessible through a configuration.
delete_scope(configuration(), String.t(), list()) :: :ok | {:error, term()}
Deletes all files within a scope of a configuration.
get_info(configuration(), identifier(), [info_option()]) :: {:ok, Belt.FileInfo.t()}
Retrieves %Belt.FileInfo{}
struct for given file.
get_url(configuration(), identifier(), [url_option()]) :: {:ok, Belt.FileInfo.t()} | :unavailable | {:error, term()}
Retrieves url for given file.
list_files(configuration(), [list_files_option()]) :: {:ok, [identifier()]} | {:error, term()}
Lists all files for a given provider.
new(options :: list()) :: {:ok, configuration()} | {:error, term()}
Creates a new configuration struct.
store(configuration(), file_source :: file_source(), [store_option()]) :: {:ok, Belt.FileInfo.t()} | {:error, term()}
Stores a file using the provided configuration.
store_data(configuration(), iodata(), [store_option()]) :: {:ok, Belt.FileInfo.t()} | {:error, term()}
Stores an in-memory iodata using the provided configuration.
test_connection(configuration(), [Belt.request_option()]) :: :ok | {:error, term()}
Tests if a connection can be established with the given provider.