Bobbin.Service (bobbin v0.5.1)

Copy Markdown View Source

What the nodes that reach other services have in common, for integrations written in Elixir.

Each action of a service is its own node, so it shows only the fields it needs. They all use a stored credential, and they answer through the success and error outputs, so a flow can handle a service being down.

The host (Heddle) fills templates and keeps credentials, see Bobbin.Host.

Example

defmodule Acme.Nodes.GetItem do
  use Bobbin.Node

  @service %{title: "Acme", category: :acme, credential: "acme", icon: "hero-cube"}

  @impl true
  def definition do
    Bobbin.Service.definition(@service, "Get Item", "Reads an item.", [
      %{type: :text, name: :id, label: "Item ID", default: ""}
    ])
  end

  @impl true
  def handler(context, _input) do
    Bobbin.Service.run(context, "acme", fn credential ->
      Acme.get(credential, Bobbin.Service.field(context, "id"))
    end)
  end
end

Summary

Functions

Returns what a file field holds.

Returns the values of the credential the node picked, as its flow's workspace sees it. refresh: true renews an OAuth token. See Bobbin.Host.credential/4.

Builds the definition of one action of a service.

Reads a field that holds JSON, or a single placeholder pointing at a value.

Reads a field that holds an image or audio: what another node returned, or a URL.

Reads a field that holds a positive number, or returns default.

Calls fun with the credential and answers through the node's outputs.

Makes a generated file safe to keep in a run's context, in the shape file fields read.

Makes content safe to keep in a run's context, which is saved as JSON.

Makes what a driver returned safe to keep in a run's context, which is saved as JSON.

Functions

content(context, name)

Returns what a file field holds.

A field that is a single placeholder can point at what a Download node returned, which keeps binary files intact from one service to the other.

credential(context, kind, opts \\ [])

Returns the values of the credential the node picked, as its flow's workspace sees it. refresh: true renews an OAuth token. See Bobbin.Host.credential/4.

credential_field(kind)

definition(service, action, description, fields)

Builds the definition of one action of a service.

failure(context, message)

field(context, name)

json(context, name, check \\ fn _value -> :ok end)

Reads a field that holds JSON, or a single placeholder pointing at a value.

Returns {:ok, value} or {:error, message}. See Bobbin.Template.json/3.

media(context, name)

Reads a field that holds an image or audio: what another node returned, or a URL.

Returns {:ok, {bytes, media_type}} or {:error, message}.

number(context, name, default)

Reads a field that holds a positive number, or returns default.

outputs()

req_options(options)

run(context, kind, fun)

Calls fun with the credential and answers through the node's outputs.

fun returns {:ok, result} or {:error, message}.

success(context, result)

tls_options(host)

to_file(data, media_type)

Makes a generated file safe to keep in a run's context, in the shape file fields read.

to_text(content)

Makes content safe to keep in a run's context, which is saved as JSON.

to_value(value)

Makes what a driver returned safe to keep in a run's context, which is saved as JSON.

Decimals become strings, because a float would lose cents.