changed README.md
 
@@ -1,13 +1,26 @@
1
+
1
2
# Web Push Elixir
2
3
3
- Simple web push library for Elixir.
4
+ Simple web push library for Elixir
5
+
6
+ <a href="https://github.com/midarrlabs/web-push-elixir/actions/workflows/test.yml">
7
+ <img src="https://github.com/midarrlabs/web-push-elixir/actions/workflows/test.yml/badge.svg" alt="Test Status">
8
+ </a>
9
+ <a href="https://codecov.io/gh/midarrlabs/web-push-elixir">
10
+ <img src="https://codecov.io/gh/midarrlabs/web-push-elixir/branch/main/graph/badge.svg?token=8PJVJG09RK&style=flat-square" alt="Code Coverage">
11
+ </a>
12
+ <a href="https://hex.pm/packages/web_push_elixir">
13
+ <img alt="Hex Version" src="https://img.shields.io/hexpm/v/web_push_elixir.svg">
14
+ </a>
15
+ <a href="https://hexdocs.pm/web_push_elixir">
16
+ <img alt="Hex Docs" src="http://img.shields.io/badge/api-docs-blue.svg?style=flat">
17
+ </a>
4
18
5
- ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/midarrlabs/web-push-elixir/test.yml)
6
- [![codecov](https://codecov.io/gh/midarrlabs/web-push-elixir/graph/badge.svg?token=Y9FG6IFTIN)](https://codecov.io/gh/midarrlabs/web-push-elixir)
7
19
8
20
## Prerequisities
9
21
10
- * Elixir 1.15, OTP 24 / 25 / 26
22
+ * Elixir 1.15
23
+ * OTP 24 / 25 / 26
11
24
12
25
## Installation
13
26
 
@@ -16,7 +29,7 @@ Simple web push library for Elixir.
16
29
```elixir
17
30
def deps do
18
31
[
19
- {:web_push_elixir, "~> 0.1.0"}
32
+ {:web_push_elixir, "~> 0.2.0"}
20
33
]
21
34
end
22
35
```
 
@@ -27,21 +40,21 @@ end
27
40
mix generate.vapid.keys
28
41
```
29
42
30
- 3. Set your environment variables for your keys:
43
+ 3. Set config for your generated keys:
31
44
32
- ```yaml
33
- environment:
34
- - VAPID_PUBLIC_KEY=someVapidPublicKey
35
- - VAPID_PRIVATE_KEY=someVapidPrivateKey
36
- - VAPID_SUBJECT=mailto:admin@email.com
45
+ ```elixir
46
+ config :web_push_elixir,
47
+ vapid_public_key: "someVapidPublicKey",
48
+ vapid_private_key: "someVapidPrivateKey",
49
+ vapid_subject: "mailto:admin@email.com"
37
50
```
38
51
39
52
## Usage
40
53
41
- `WebPushElixir` provides a simple public API `send_notification/2` that accepts 2 arguments:
54
+ `WebPushElixir` provides a simple `send_notification/2` that takes 2 arguments:
42
55
43
- * `subscription`: is the subscription information received from the client.
44
- * `message`: is a message string.
56
+ * `subscription`: the subscription information received from the client - [example demo](https://midarrlabs.github.io/web-push-elixir/)
57
+ * `message`: the message string.
45
58
46
59
```elixir
47
60
subscription = '{"endpoint":"https://some-push-service","keys":{"p256dh":"BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM=","auth":"tBHItJI5svbpez7KI4CCXg=="}}'
 
@@ -50,7 +63,17 @@ message = "Some message"
50
63
WebPushElixir.send_notification(subscription, message)
51
64
```
52
65
53
- For more information on how to subscribe a client, permission UX and more - have a look at [https://web.dev/notifications/](https://web.dev/notifications/)
66
+ For more information on how to subscribe a client, permission UX and more - take a look at [https://web.dev/notifications/](https://web.dev/notifications/)
67
+
68
+ ## Run tests
69
+
70
+ ```commandline
71
+ mix test
72
+ ```
73
+
74
+ ## License
75
+
76
+ Web Push Elixir is open-sourced software licensed under the [MIT license](LICENSE).
54
77
55
78
56
79
## Credits
changed hex_metadata.config
 
@@ -1,7 +1,7 @@
1
1
{<<"links">>,
2
2
[{<<"GitHub">>,<<"https://github.com/midarrlabs/web-push-elixir">>}]}.
3
3
{<<"name">>,<<"web_push_elixir">>}.
4
- {<<"version">>,<<"0.2.0">>}.
4
+ {<<"version">>,<<"0.4.0">>}.
5
5
{<<"description">>,<<"Simple web push for Elixir">>}.
6
6
{<<"elixir">>,<<"~> 1.15">>}.
7
7
{<<"app">>,<<"web_push_elixir">>}.
changed lib/web_push_elixir.ex
 
@@ -80,7 +80,7 @@ defmodule WebPushElixir do
80
80
JOSE.JWT.from_map(%{
81
81
aud: URI.parse(endpoint).scheme <> "://" <> URI.parse(endpoint).host,
82
82
exp: DateTime.to_unix(DateTime.utc_now()) + 12 * 3600,
83
- sub: System.get_env("VAPID_SUBJECT")
83
+ sub: Application.get_env(:web_push_elixir, :vapid_subject)
84
84
})
85
85
86
86
json_web_key =
 
@@ -100,16 +100,16 @@ defmodule WebPushElixir do
100
100
101
101
## Arguments
102
102
103
- * `subscription` is the subscription information received from the client. Accepted example: `'{"endpoint":"https://some-push-service","keys":{"p256dh":"BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM=","auth":"tBHItJI5svbpez7KI4CCXg=="}}'`
104
- * `message` is a message string.
103
+ * `subscription` the subscription information received from the client. Accepted example: `'{"endpoint":"https://some-push-service","keys":{"p256dh":"BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM=","auth":"tBHItJI5svbpez7KI4CCXg=="}}'`
104
+ * `message` the message string.
105
105
106
106
## Return value
107
107
108
108
Returns the result of `HTTPoison.post`
109
109
"""
110
110
def send_notification(subscription, message) do
111
- vapid_public_key = url_decode(System.get_env("VAPID_PUBLIC_KEY"))
112
- vapid_private_key = url_decode(System.get_env("VAPID_PRIVATE_KEY"))
111
+ vapid_public_key = url_decode(Application.get_env(:web_push_elixir, :vapid_public_key))
112
+ vapid_private_key = url_decode(Application.get_env(:web_push_elixir, :vapid_private_key))
113
113
114
114
%{endpoint: endpoint, keys: %{p256dh: p256dh, auth: auth}} =
115
115
Jason.decode!(subscription, keys: :atoms)
changed mix.exs
 
@@ -4,7 +4,7 @@ defmodule WebPushElixir.MixProject do
4
4
def project do
5
5
[
6
6
app: :web_push_elixir,
7
- version: "0.2.0",
7
+ version: "0.4.0",
8
8
elixir: "~> 1.15",
9
9
start_permanent: Mix.env() == :prod,
10
10
deps: deps(),