Hephaestus.Connectors.Connector behaviour (hephaestus v0.3.1)

Copy Markdown View Source

Contract for external service connectors.

Summary

Types

An atom identifying the operation to perform on the external service.

A map of configuration values required by the connector.

The reason for a failed action execution.

A map of input parameters for the action being executed.

A map containing the data returned by a successful action execution.

Callbacks

Executes the given action against the external service.

Returns the list of actions supported by this connector.

Types

action()

@type action() :: atom()

An atom identifying the operation to perform on the external service.

Each connector defines its own set of supported actions (e.g., :get_task, :create_task).

config()

@type config() :: map()

A map of configuration values required by the connector.

Typically holds credentials and connection settings (e.g., %{api_key: "secret"}).

error_reason()

@type error_reason() :: term()

The reason for a failed action execution.

Can be any term, though atoms like :unsupported_action or descriptive strings are recommended.

params()

@type params() :: map()

A map of input parameters for the action being executed.

The expected keys depend on the specific action (e.g., %{task_id: "123"} for a :get_task action).

result()

@type result() :: map()

A map containing the data returned by a successful action execution.

Callbacks

execute(action, params, config)

@callback execute(action(), params(), config()) ::
  {:ok, result()} | {:error, error_reason()}

Executes the given action against the external service.

Receives the action to perform, a map of params specific to that action, and a config map with credentials or connection settings.

Returns {:ok, result} on success or {:error, reason} on failure.

supported_actions()

@callback supported_actions() :: [action()]

Returns the list of actions supported by this connector.