Grapple v1.0.1 Grapple
This is the main module for Grapple. It defines the functions and macros that are available for adding, removing, and viewing topics and hooks, and broadcasting hooks.
Summary
Functions
Adds a new topic. Topic must be an atom. Returns a Grapple.Server.Topic
struct which has a name
and a sup
(Supervisor pid)
Sends HTTP requests for all hooks subscribed to the given topic
Like broadcast/1, but will send all hooks for a topic with the given body
instead of what was originally defined as the body
on the Hook
Clears all topics
Returns a list of all hooks subscribed to a topic
Returns a list of responses for each hook on the given topic
Lists all topics
Removes a subscribed hook given a topic and the hook pid
Removes a topic
Callback implementation for Application.start/2
Subscribes a hook to a topic. The first argument must be an atom
representing an existing topic and the second must be a valid Hook
struct
Macros
Allows modules to use
Grapple.Hook in them
Allows users to define hookable functions that automatically publish to subscribers whenever they are invoked
Functions
Adds a new topic. Topic must be an atom. Returns a Grapple.Server.Topic
struct which has a name
and a sup
(Supervisor pid).
## Examples:
iex> {:ok, topic = %Grapple.Server.Topic{}} = Grapple.add_topic(:pokemon)
iex> topic.name
:pokemon
Sends HTTP requests for all hooks subscribed to the given topic.
Returns :ok
.
## Examples:
iex> {:ok, _pokemon} = Grapple.add_topic(:pokemon)
iex> {:ok, _pid} = Grapple.subscribe(:pokemon, %Grapple.Hook{url: "my-api"})
iex> Grapple.broadcast(:pokemon)
:ok
Like broadcast/1, but will send all hooks for a topic with the given body
instead of what was originally defined as the body
on the Hook
.
Returns a list of all hooks subscribed to a topic.
## Examples:
iex> {:ok, _pokemon} = Grapple.add_topic(:pokemon)
iex> {:ok, _pid} = Grapple.subscribe(:pokemon, %Grapple.Hook{url: "my-api"})
iex> [{_pid, hook}] = Grapple.get_hooks(:pokemon)
iex> hook
%Grapple.Hook{body: %{}, headers: [], life: nil, method: "GET", owner: nil,
query: %{}, ref: nil, url: "my-api"}
Returns a list of responses for each hook on the given topic.
## Examples
iex> {:ok, _pokemon} = Grapple.add_topic(:pokemon)
iex> {:ok, _pid} = Grapple.subscribe(:pokemon, %Grapple.Hook{url: "my-api"})
iex> [{_pid, responses}] = Grapple.get_responses(:pokemon)
iex> responses
[]
Lists all topics.
## Examples:
iex> {:ok, pokemon} = Grapple.add_topic(:pokemon)
iex> {:ok, gyms} = Grapple.add_topic(:gyms)
iex> [gyms, pokemon] == Grapple.get_topics
true
Callback implementation for Application.start/2
.
Subscribes a hook to a topic. The first argument must be an atom
representing an existing topic and the second must be a valid Hook
struct.
Returns the pid
of the Hook process that was created.
## Examples:
iex> {:ok, _pokemon} = Grapple.add_topic(:pokemon)
iex> {:ok, pid} = Grapple.subscribe(:pokemon, %Grapple.Hook{url: "my-api"})
iex> is_pid(pid)
true