Giter Site home page Giter Site logo

elnikov / pushpad-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pushpad/pushpad-ruby

0.0 2.0 0.0 7 KB

Pushpad Ruby bindings: web push notifications for Chrome, Firefox and Safari

Home Page: https://pushpad.xyz

License: MIT License

Ruby 100.00%

pushpad-ruby's Introduction

Pushpad - Web Push Notifications

Add native push notifications to your web app using Pushpad.

Features:

  • notifications are delivered even when the user is not on your website
  • users don't need to install any app or plugin
  • you can target specific users or send bulk notifications

Currently push notifications work on the following browsers:

  • Chrome (Desktop and Android)
  • Firefox (44+)
  • Safari

Installation

Add this line to your application's Gemfile:

gem 'pushpad'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install pushpad

Getting started

First you need to sign up to Pushpad and create a project there.

Then set your authentication credentials:

Pushpad.auth_token = '5374d7dfeffa2eb49965624ba7596a09'
Pushpad.project_id = 123 # set it here or pass it as a param to methods later
  • auth_token can be found in the user account settings.
  • project_id can be found in the project settings. If your application uses multiple projects, you can pass the project_id as a param to methods (e.g. notification.deliver_to user, project_id: 123).

Collecting user subscriptions to push notifications

Pushpad offers two different products. Learn more

Pushpad Pro

Choose Pushpad Pro if you want to use Javascript for a seamless integration. Read the docs

If you need to generate the HMAC signature for the uid you can use this helper:

Pushpad.signature_for current_user.id

Pushpad Express

Add a link to let users subscribe to push notifications:

<a href="<%= Pushpad.path %>">Subscribe anonymous to push notifications</a>

<a href="<%= Pushpad.path_for current_user # or current_user_id %>">Subscribe current user to push notifications</a>

current_user is the user currently logged in on your website.

When a user clicks the link is sent to Pushpad, automatically asked to receive push notifications and redirected back to your website.

Sending push notifications

notification = Pushpad::Notification.new({
  body: "Hello world!", # max 90 characters
  title: "Website Name", # optional, defaults to your project name, max 30 characters
  target_url: "http://example.com" # optional, defaults to your project website
})

# deliver to a user
notification.deliver_to user # or user_id

# deliver to a group of users
notification.deliver_to users # or user_ids

# deliver to some users only if they have a given preference
# e.g. only "users" who have a interested in "events" will be reached
notification.deliver_to users, tags: ['events']

# deliver to segments
notification.broadcast tags: ['segment1', 'segment2']

# deliver to everyone
notification.broadcast

If no user with that id has subscribed to push notifications, that id is simply ignored.

The methods above return an hash:

  • "scheduled" is the number of devices to which the notification will be sent
  • "uids" (deliver_to only) are the user IDs that will be actually reached by the notification (unless they have unsubscribed since the last notification)

License

The gem is available as open source under the terms of the MIT License.

pushpad-ruby's People

Contributors

collimarco avatar norcle avatar

Watchers

 avatar  avatar

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.