Current section
Files
Jump to
Current section
Files
lib/ifttt_webhook/server.ex
defmodule IftttWebhook.Server do
@moduledoc """
A GenServer implementation to send webhooks to IFTTT
"""
use GenServer
alias IftttWebhook.API
@spec start_link(binary) ::
{:ok, pid} |
{:error, term}
def start_link(api_key) do
GenServer.start_link(__MODULE__, api_key, name: __MODULE__)
end
@doc """
Sends event and values to the server, which uses `IftttWebhook.API`
to send it to IFTTT's Webservice
"""
def send_async(event, values) when is_list(values) do
GenServer.cast(__MODULE__, {:send, event, values})
end
# Server implementation
def init(api_key) do
{:ok, api_key}
end
def handle_cast({:send, event, values}, api_key) do
{:ok, _response} = API.send(api_key, event, values)
{:noreply, api_key}
end
end