Skip to content

Strategy to send notifications through Pusher with Ravenx.

License

Notifications You must be signed in to change notification settings

bjufre/ravenx-pusher

Repository files navigation

RavenxPusher

Hex pm Travis CI Hex.pm

RavenxPusher is a custom strategy for ravenx so we can send notifications through pusher in an easy and nice way.

Installation

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
]

Configuration

** In order to use Pusher you'll need the following items from your apps dashboard so we can configure it properly:

  • app_id: In Pusher app_id.
  • app_key: In Pusher key.
  • secret: In Pusher secret.

Once we have them we can proceed.

As explained in the ravenx configuration section, we have different ways of configuring the adapters:

  1. 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"})
  1. 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.

  1. 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.

Dispatching

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 a List(String.t)).

License

Check LICENSE.

About

Strategy to send notifications through Pusher with Ravenx.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages