Belt v0.2.0 Belt.Provider behaviour

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

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 and Belt.store_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

Types

configuration()
configuration() :: %{provider: :atom}

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

delete_option()
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.

file_identifier()
file_identifier() :: String.t | %{identifier: String.t}

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

file_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
info_option()
info_option ::
  {:hashes, [:crypto.hash_algorithms]} |
  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()
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()
store_option ::
  {:hashes, [:crypto.hash_algorithms]} |
  {:key, String.t | :auto} |
  {:overwrite, boolean | :rename} |
  {:scope, String.t} |
  Belt.request_option |
  {:atom, term}

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

url_option()
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.

Callbacks

default(options)
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)
delete(configuration, identifier, list) ::
  :ok |
  {:error, term}

Deletes a file using the provided configuration and identifier.

delete_all(configuration, list)
delete_all(configuration, list) :: :ok | {:error, term}

Deletes all file accessible through a configuration.

delete_scope(configuration, arg1, list)
delete_scope(configuration, String.t, list) ::
  :ok |
  {:error, term}

Deletes all files within a scope of a configuration.

get_info(configuration, identifier, list)
get_info(configuration, identifier, [info_option]) :: {:ok, Belt.FileInfo.t}

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

get_url(configuration, identifier, list)
get_url(configuration, identifier, [url_option]) ::
  {:ok, Belt.FileInfo.t} |
  :unavailable |
  {:error, term}

Retrieves url for given file.

list_files(configuration, list)
list_files(configuration, [list_files_option]) ::
  {:ok, [identifier]} |
  {:error, term}

Lists all files for a given provider.

new(options)
new(options :: list) :: {:ok, configuration} | {:error, term}

Creates a new configuration struct.

store(configuration, file_source, list)
store(configuration, file_source :: file_source, [store_option]) ::
  {:ok, Belt.FileInfo.t} |
  {:error, term}

Stores a file using the provided configuration.