RavenxPusher is a custom strategy for ravenx
so we can send notifications
through pusher in an easy and nice way.
To install this package, you need to add ravenx_pusher
to your list of dependencies in mix.exs
:
def deps do
[{:ravenx_pusher, "~> 0.2.2"}]
end
And second you need to add it to the list of Ravenx
strategies in the config in order for it to work:
config :ravenx, :strategies, [
pusher: Ravenx.Strategy.Pusher
]
** In order to use Pusher
you'll need the following items from your apps dashboard so we can configure it properly:
app_id
: In Pusherapp_id
.app_key
: In Pusherkey
.secret
: In Pushersecret
.
Once we have them we can proceed.
As explained in the ravenx
configuration section, we have different ways of configuring the adapters:
- Passing the options in the dispatch call:
iex> Ravenx.dispatch(:pusher, %{event: "my-event", data: "Data to send", channels: "my-channel"}, %{host: "localhost", port: 8080, app_id: "myAppId", app_key: "myAppKey", secret: "myAppSecret"})
- Specifying a configuration module in your application config:
config :ravenx,
config: YourApp.RavenxConfig
And creating that module:
defmodule YourApp.RavenxConfig do
def pusher(_payload) do
%{
app_id: "...",
app_key: "...",
secret: "...",
host: "...",
port: ... # 8080 for example
}
end
end
Note: the module should contain a function called as the strategy yopu are configuring, receiving the payload and returning a configuration Keyword list.
- Specifying the configuration directly on your application config file:
config :ravenx, :pusher,
app_id: "...",
app_key: "...",
secret: "...",
host: "...",
port: ... # 8080 for example
If you want to know more about configuration options or ravenx
itself go to their README.
To dispatch any notification through Pusher
you need to pass a map (as the second parameter) to Ravenx.dispatch(:pusher, to_dispatch, opts \\ %{})
with the following keys:
- data: The data to send.
- event: The name of the event.
- channels: The channels where the notification will go through (this can be either a
String
or aList(String.t)
).
Check LICENSE.