Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make email/slack strategy and their dependencies optional. #37

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ GitHub.sublime-settings
!.vscode/tasks.json
!.vscode/launch.json

### ASDF ###
.tool-versions

### Erlang ###
.eunit
Expand Down
2 changes: 0 additions & 2 deletions .tool-versions

This file was deleted.

50 changes: 37 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,52 @@
[![Current Version](https://img.shields.io/hexpm/v/ravenx.svg)](https://hex.pm/packages/ravenx)
[![Build Status](https://travis-ci.org/acutario/ravenx.svg?branch=master)](https://travis-ci.org/acutario/ravenx)

Notification dispatch library for Elixir applications (WIP).
Notification dispatch library for Elixir applications.

## Installation

1. The package can be installed as simply as adding `ravenx` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:ravenx, "~> 1.0.0"}]
[{:ravenx, "~> 2.0.0"}]
end
```

2. Add Ravenx to your list of applications in `mix.exs`. This step is only needed if you are using a version older than Elixir 1.4.0 or you already have some applications listed under the `applications` key. In any other case applications are automatically inferred from dependencies (explained in the [Application inference](http://elixir-lang.github.io/blog/2017/01/05/elixir-v1-4-0-released/) section):
## Strategies

We currently support Slack and E-mail notifications. To enable those strategies you need to install additional dependencies and add them to the list of strategies in your config.

### Slack

```elixir
def application do
[
applications: [
...,
:ravenx
]
{:poison, "~> 2.0 or ~> 3.0"},
{:httpoison, "~> 0.12"},
```

```elixir
config :ravenx,
strategies: [
# Add the following line
slack: Ravenx.Strategy.Slack,
]
end
```

## Strategies
### Email

We currently support Slack and E-mail notifications (but there are more to come!).
```elixir
{:bamboo, "~> 0.8"},
```

Also, there is the possibility of creating 3rd party integrations that works with Ravenx, as mentioned bellow
```elixir
config :ravenx,
strategies: [
# Add the following line
email: Ravenx.Strategy.Email,
]
```

Also, there is the possibility of creating 3rd party integrations that works with Ravenx, as mentioned below:

### 3rd party strategies

Expand Down Expand Up @@ -186,3 +202,11 @@ config :ravenx,
```

and start using your strategy to deliver notifications using the atom assigned (in the example, `my_strategy`).

## Troubleshooting

### Ravenx not being started (Elixir <1.4)

In Elixir versions <1.4 you need to explicitly list `applications` to be started. This is needed
for Ravenx as well as any of the dependencies needed for the bundled strategies. For more information
read the release notes for [Elixir 1.4](http://elixir-lang.github.io/blog/2017/01/05/elixir-v1-4-0-released/).
32 changes: 18 additions & 14 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ use Mix.Config
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :ravenx, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:ravenx, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#
config :ravenx,
strategies: [
# Does need HTTPoison and Poison as dependency
#
# {:poison, "~> 2.0 or ~> 3.0"},
# {:httpoison, "~> 0.12"},
#
slack: Ravenx.Strategy.Slack,

# Does need Bamboo
#
# {:bamboo, "~> 0.8"},
#
email: Ravenx.Strategy.Email,
dummy: Ravenx.Strategy.Dummy
]

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
if File.exists?("config/#{Mix.env}.exs") do
import_config("#{Mix.env}.exs")
if File.exists?("config/#{Mix.env()}.exs") do
import_config("#{Mix.env()}.exs")
end
6 changes: 2 additions & 4 deletions lib/ravenx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ defmodule Ravenx do
"""
@spec available_strategies() :: keyword
def available_strategies do
bundled_strategies = [
slack: Ravenx.Strategy.Slack,
email: Ravenx.Strategy.Email,
default_strategies = [
dummy: Ravenx.Strategy.Dummy
]

bundled_strategies
default_strategies
|> Keyword.merge(Application.get_env(:ravenx, :strategies, []))
end

Expand Down
Loading