Git Product home page Git Product logo

webpush-clojure's Introduction

Clojars Project

webpush-clojure

Wrapping Webpush-java. Only provide a convenient clojure api.

NOT PRODUCTION READY Webpush-java is production ready but this clojure wrapper has not been tested yet. It will be in a few days/weeks.

Supports:

  • payloads,
  • VAPID,
  • asynchrounous sending.

Do not support:

Usage

Data

Your backend receive subscriptions shaped like this:

{:endpoint "https://random-push-service.com/some-kind-of-unique-id-1234/v2/"
 :keys     {:p256dh "BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM="
            :auth   "tBHItJI5svbpez7KI4CCXg=="}}

How to send a notification:

(require '[webpush.core :refer [subscription push-service notification send!]])

(let [;; Create a subscription
      sub (subscription <endpoint> <p256dh> <auth>)
      ;; Create a push-service instance by passing your `public-key`,
      ;; `private-key` (as strings), and the webpush `subject` (most of the time
      ;; your email)
      svc (service <public-key> <private-key> <subject>)]
  (send! svc (notification sub "Hello World!")))

;; The webpush protocol force payloads encryption using public/private keypairs.
;; On the JVM it uses some algorithms provided by BouncyCastle. If you get any
;; error relative to crypto, you can enable them by calling:
(webpush.core/add-security-provider!)

Generating keypairs

(webpush.utils/generate-keys)
;; => {:public "BEWi1tvrrkZhe_FJjhGbVvLDmXrQMhMr27aJ9UGJdCSAdRp8tVciDbNqBMLlmb2ZctcZvfY2tEvQIlSRo7QqVkw=",
;;     :private "AMbTUIvdMwwboLSxWMNoRS6XaJuXmX1reHrkNBdiJBwq"}

CLI

Webpush-java allow users to generate keys or send a notification as a shell command (using gradle). If you have any use case where shell commands might be a better fit then a REPL please open an issue.

Contributing

This library should stay so small that all contributions should go to Webpush-java IMHO, but all PRs are welcome.

TODO

  • Add cli commands
    • add generate-key
    • add send-notification
  • add missing constructor arities (when it make sense in Clojure)
  • add documentation
  • add better examples

webpush-clojure's People

Contributors

gerdint avatar ggeoffrey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gerdint

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.