Current section
Files
Jump to
Current section
Files
lib/conn/conn.ex
defmodule Agala.Conn do
@moduledoc """
The Agala connection.
This module defines a `Agala.Conn` struct. This struct contains
both request and response data.
## Request fields
These fields contain request information:
* `request` - request data structure. It's internal structure depends
on provider type.
"""
defstruct [:request, :response, :halted, :request_bot_params, :responser_name]
@type t :: %Agala.Conn{
request: Map.t,
response: Map.t,
halted: boolean,
request_bot_params: Agala.BotParams.t,
responser_name: String.t | Atom
}
@behaviour Access
@doc false
def fetch(bot_params, key) do
Map.fetch(bot_params, key)
end
@doc false
def get(structure, key, default \\ nil) do
Map.get(structure, key, default)
end
@doc false
def get_and_update(term, key, list) do
Map.get_and_update(term, key, list)
end
@doc false
def pop(term, key) do
{get(term, key), term}
end
@doc """
Halts the Agala.Chain pipeline by preventing further plugs downstream from being
invoked. See the docs for `Agala.Chain.Builder` for more information on halting a
plug pipeline.
"""
@spec halt(t) :: t
def halt(%Agala.Conn{} = conn) do
%{conn | halted: true}
end
def send_to(%Agala.Conn{} = conn, name) do
conn
|> Map.put(:responser_name, name)
end
end