File tree Expand file tree Collapse file tree 5 files changed +24
-13
lines changed Expand file tree Collapse file tree 5 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 4040mix generate.vapid.keys
4141```
4242
43- 3 . Set environment variables for your generated keys:
43+ 3 . Set config for your generated keys:
4444
45- ``` yaml
46- environment :
47- - VAPID_PUBLIC_KEY= someVapidPublicKey
48- - VAPID_PRIVATE_KEY= someVapidPrivateKey
49- - 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"
5050```
5151
5252## Usage
5353
54- ` WebPushElixir` provides a simple `send_notification/2` function that accepts 2 arguments:
54+ ` WebPushElixir ` provides a simple ` send_notification/2 ` that takes 2 arguments:
5555
5656* ` subscription ` : the subscription information received from the client - [ example demo] ( https://midarrlabs.github.io/web-push-elixir/ )
5757* ` message ` : the message string.
Original file line number Diff line number Diff line change 1+ import Config
2+
3+ if Mix . env ( ) == :test do
4+ import_config "test.exs"
5+ end
Original file line number Diff line number Diff line change 1+ import Config
2+
3+ config :web_push_elixir ,
4+ vapid_public_key: "someVapidPublicKey" ,
5+ vapid_private_key: "someVapidPrivateKey" ,
6+ vapid_subject: "mailto:admin@email.com"
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ defmodule WebPushElixir do
8080 JOSE.JWT . from_map ( % {
8181 aud: URI . parse ( endpoint ) . scheme <> "://" <> URI . parse ( endpoint ) . host ,
8282 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 )
8484 } )
8585
8686 json_web_key =
@@ -108,8 +108,8 @@ defmodule WebPushElixir do
108108 Returns the result of `HTTPoison.post`
109109 """
110110 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 ) )
113113
114114 % { endpoint: endpoint , keys: % { p256dh: p256dh , auth: auth } } =
115115 Jason . decode! ( subscription , keys: :atoms )
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ defmodule WebPushElixirTest do
1010 vapid_subject: vapid_subject
1111 } = Mix.Tasks.Generate.Vapid.Keys . run ( [ ] )
1212
13- System . put_env ( "VAPID_PUBLIC_KEY" , vapid_public_key )
13+ Application . put_env ( :web_push_elixir , :vapid_public_key , vapid_public_key )
1414
15- System . put_env ( "VAPID_PRIVATE_KEY" , vapid_private_key )
15+ Application . put_env ( :web_push_elixir , :vapid_private_key , vapid_private_key )
1616
17- System . put_env ( "VAPID_SUBJECT" , vapid_subject )
17+ Application . put_env ( :web_push_elixir , :vapid_subject , vapid_subject )
1818
1919 { :ok , response } = WebPushElixir . send_notification ( @ subscription , "some message" )
2020
You can’t perform that action at this time.
0 commit comments