View Source AMI.Action (AMI v0.1.0)

Link to this section Summary

Types

t()

AMI Action type is a map of headers and values. Values are lists because AMI protocol allows to have multiple headers with the same name.

Functions

Add new field to the Action

Create login AMI Action with given parameters.

Create new AMI Action and automatically add ActionID

Create new AMI Action with headers list. If needed to add custom ActionID and skip auto-generated ActionID it can be done here.

Convert AMI Action to string

Link to this section Types

@type t() :: map()

AMI Action type is a map of headers and values. Values are lists because AMI protocol allows to have multiple headers with the same name.

example

Example

  iex> {:ok, action} = AMI.Action.new("QueueStatus")
  iex> {:ok, action} = AMI.Action.add_field(action, "Queue", "Sales")
  {:ok,
    %{
      "Action" => ["QueueStatus"],
      "ActionID" => ["o3webr9ub391qq9hzdrqatztk"],
      "Queue" => ["Sales"]
    }}

Automatically adds ActionID field if not yet exists. If it is required to have custom ActionID then use new/2 function.

Link to this section Functions

Link to this function

add_field(action, name, value)

View Source
@spec add_field(action :: t(), name :: String.t(), value :: String.t()) :: {:ok, t()}

Add new field to the Action

@spec login(user :: String.t(), passwd :: String.t()) :: String.t()

Create login AMI Action with given parameters.

user and passwd will be inserted in login Action and the Action will be returned as string

@spec new(action :: String.t()) :: {:ok, t()} | {:invalid}

Create new AMI Action and automatically add ActionID

Create new AMI Action with headers list. If needed to add custom ActionID and skip auto-generated ActionID it can be done here.

For example:

  iex> AMI.Action.new("QueueStatus", [
    {"ActionID", "FOO-bar1"},
    {"Queue", "Sales"}
  ])
  {:ok,
   %{
    "Action" => ["QueueStatus"],
    "ActionID" => ["FOO-bar1"],
    "Queue" => ["Sales"]
  }}
@spec to_string(action :: t()) :: String.t()

Convert AMI Action to string