Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An EventMachine APN server & a Redis-backed library used in production at Zapkast to push iOS notifications

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 apnmachine.gemspec
README.textile

Apn Server & Library for Ruby

Description

I want:
- persistent connection to APN Servers (as Apple recommends)
- real-time notifications (no regular polling a la Resque)
- super easy to use in Ruby and any languages (as easy as enqueuing a serialized JSON hash in Redis)
- persist and queue messages when server is down
- horizontal scalability and out-of-the-box load-balancing
- fast daemons

So I built ApnMachine. We’re running it in production at zapkast.com and find it very reliable.

Remaining Tasks

  • Implement feedback service mechanism
  • Write real tests

ApnMachine Daemon

To start ApnMachine, tell it where is your redis server and the complete path to your PEM file.
That’s it.

  
Usage: apnmachined [options] --pem /full/path/to/pem
  --redis-host bind address (defaults to 127.0.0.1)
    address of your redis server

  --redis-port port
    the port of your redis server (defaults to)

  --apn-host host
    APN Server host (defaults to gateway.push.apple.com)
    Use 'sandbox' to connect to gateway.sandbox.push.apple.com

  --apn-port port of the APN Server
    APN server port (defaults to 2195)

  --pem pem file path
    The PEM encoded private key and certificate.
    To export a PEM ecoded file execute
    # openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts

  --pem-passphrase passphrase
    The PEM passphrase to decode key.
    Default to nil

  --help
    usage message

  --daemon or -d
    Runs process as daemon, not available on Windows
  

Sending Notifications from Ruby

To send a notification, you just need a working Redis client that responds to rpush. It doesn’t matter if you’re
in an EventMachine program or a plain vanilla Rails app.

  
  ApnMachine::Config.redis = @any_redis_client
  ApnMachine::Config.logger = Rails.logger
  

Finally:

  
  notification = ApnMachine::Notification.new
  notification.device_token = apns_token
  notification.alert = message
  notification.badge = 1
  notification.sound = 'default'
  notification.push
  

Installation

Apnserver is hosted on rubygems


  $ gem install apnmachine

Adding apnmachine to your Rails application

  
  gem 'apnmachine'
  

License

The MIT License – Copyright © 2012 Julien Nakache
Widely Inspired from groupme/em-apn and bpoweski/apnserver

Something went wrong with that request. Please try again.