Server Libraries

Arrow right Prerequisites

Sign up for a ZeroPush account. Find the auth_token on the settings page.

Cloud Server Side Concerns

When integrating with ZeroPush, your server must be able to perform the following actions:

  • Save the device token and associate it with a user in your database.
  • Make a request to ZeroPush when you want to send a notification.

Both actions are standard HTTP POST requests, so they can be implemented in any language.

Ruby Ruby/Rails

For Ruby applications, the zero_push gem provides a convenient wrapper around the ZeroPush API.

Usage

Add the following to your Gemfile

gem 'zero_push', '~> 1.3.0'

Install the gem with bundler

$> bundle install

If you are using Rails, you can run the generator

$> rails g zero_push:install

The generator will create an initializer in config/initializers/zero_push.rb with the following content:

if Rails.env.production?
  ZeroPush.auth_token = "production token"
else
  ZeroPush.auth_token = "development token"
end

If you are using some other Rack based web server, you should set the auth_token similarly.

if ENV['RACK_ENV'] == "production"
  ZeroPush.auth_token = "production token"
else
  ZeroPush.auth_token = "development token"
end

Sending a push notification:

notification = {
  device_tokens: [device_token_one, device_token_two],
  alert: "Something really awesome just happened!",
  sound: "default",
  badge: 1
}

ZeroPush.notify(notification)

Source

The source code for the gem can be found on our GitHub page https://github.com/SymmetricInfinity/zero_push

Django Django

For Django applications django-zeropush provides a convenient wrapper around the ZeroPush API, as well as providing registration endpoints for device token management.

Usage

Please see the django-zeropush README for information about adding it to your application.

Sending a push notification to a single device:

import zeropush

# Get a user. Can also be a custom user model in django 1.5+
the_user = User.objects.filter(username="johndoe")

zeropush.notify_user(the_user, alert="Here's some notification text", sound="default", badge_number=1)

Php PHP

For PHP applications see: ZeroPush-PHP

Sample Usage:

require('zero_push.php');

$client = new ZeroPush('your-auth-token');
$response = $client->broadcast(array('alert' => 'Hello, World'));

Speech bubble left eJabberd

For sending push notifications directly from eJabberd, mod_zeropush provides a convenient module to send push notifications to offline users.

When using mod_zeropush make sure to use the broadcast channels to assign device tokens to specific jabber ids.

Installation

Refer to the readme for instructions how to install mod_zeropush for ejabberd 2.1.x and 13.10

updated on Sun Feb 2 17:30:04 2014