FoPost.Automations (FoPost v0.1.0)

Copy Markdown View Source

Automations — a trigger plus the steps it runs.

{:ok, automation} =
  FoPost.Automations.create(client,
    workspace_id: workspace.id,
    name: "Cross-post the blog",
    trigger_type: "rss_feed",
    trigger_config: %{"url" => "https://example.com/feed.xml"},
    steps: [%{action_type: "publish", action_config: %{"accounts" => [account.id]}}]
  )

A step is a FoPost.AutomationStep or a map of :action_type and :action_config; snake_case keys are converted to the wire's camelCase for you.

Summary

Functions

Adds an automation.

Removes an automation.

One automation, with its steps.

Same as get/2, but raises FoPost.Error.

The automations the key can reach.

Same as list/1, but raises FoPost.Error.

One execution, with a log per step.

One page of an automation's executions. Paging: :page, :per_page.

Automation counts and the runs of the last day.

Same as stats/1, but raises FoPost.Error.

Switches an automation on or off.

Fires an api_webhook automation with a payload its steps can read.

Edits an automation. Only the keys you pass are sent, but :steps replaces the whole list when given.

Functions

create(client, opts)

@spec create(
  FoPost.Client.t(),
  keyword()
) :: {:ok, FoPost.Automation.t()} | {:error, FoPost.Error.t()}

Adds an automation.

Required: :workspace_id, :name, :trigger_type, :steps. Optional: :trigger_config, :active.

For an api_webhook trigger the response carries the signing secret once — store it.

create!(client, opts)

Same as create/2, but raises FoPost.Error.

delete(client, id)

@spec delete(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Message.t()} | {:error, FoPost.Error.t()}

Removes an automation.

delete!(client, id)

Same as delete/2, but raises FoPost.Error.

get(client, id)

@spec get(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Automation.t()} | {:error, FoPost.Error.t()}

One automation, with its steps.

get!(client, id)

Same as get/2, but raises FoPost.Error.

list(client)

@spec list(FoPost.Client.t()) ::
  {:ok, [FoPost.Automation.t()]} | {:error, FoPost.Error.t()}

The automations the key can reach.

list!(client)

Same as list/1, but raises FoPost.Error.

run(client, id, run_id)

@spec run(FoPost.Client.t(), String.t(), String.t() | integer()) ::
  {:ok, FoPost.AutomationRun.t()} | {:error, FoPost.Error.t()}

One execution, with a log per step.

run!(client, id, run_id)

Same as run/3, but raises FoPost.Error.

runs(client, id, opts \\ [])

@spec runs(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Page.t()} | {:error, FoPost.Error.t()}

One page of an automation's executions. Paging: :page, :per_page.

runs!(client, id, opts \\ [])

Same as runs/3, but raises FoPost.Error.

stats(client)

@spec stats(FoPost.Client.t()) ::
  {:ok, FoPost.AutomationStats.t()} | {:error, FoPost.Error.t()}

Automation counts and the runs of the last day.

stats!(client)

Same as stats/1, but raises FoPost.Error.

toggle(client, id)

@spec toggle(FoPost.Client.t(), String.t()) ::
  {:ok, FoPost.Automation.t()} | {:error, FoPost.Error.t()}

Switches an automation on or off.

toggle!(client, id)

Same as toggle/2, but raises FoPost.Error.

trigger(client, id, payload \\ %{})

@spec trigger(FoPost.Client.t(), String.t(), map()) ::
  {:ok, FoPost.AutomationTrigger.t()} | {:error, FoPost.Error.t()}

Fires an api_webhook automation with a payload its steps can read.

trigger!(client, id, payload \\ %{})

Same as trigger/3, but raises FoPost.Error.

update(client, id, opts)

@spec update(FoPost.Client.t(), String.t(), keyword()) ::
  {:ok, FoPost.Automation.t()} | {:error, FoPost.Error.t()}

Edits an automation. Only the keys you pass are sent, but :steps replaces the whole list when given.

update!(client, id, opts)

Same as update/3, but raises FoPost.Error.