Skip to content

cbot/push0r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

push0r

Gem Version

push0r is a ruby library that makes it easy to send push notifications to iOS, OSX and Android users.

Installation

Gemfile for Rails 3, Rails 4, Sinatra, and Merb:

gem 'Push0r', '~> 0.5.3'

Manual installation:

gem install Push0r

Usage

# create a new queue
queue = Push0r::Queue.new

# create the GcmService to push to Android devices and register it with our queue.
gcm_service = Push0r::GcmService.new("__gcm_api_token__")
queue.register_service(gcm_service)

# create ApnsService instances to push to iOS and OSX devices and register them with our queue.
apns_service_production = Push0r::ApnsService.new(File.read("aps_production.pem"), Push0r::ApnsEnvironment::PRODUCTION)
apns_service_sandbox = Push0r::ApnsService.new(File.read("aps_development.pem"), Push0r::ApnsEnvironment::SANDBOX)
queue.register_service(apns_service_production)
queue.register_service(apns_service_sandbox)

# create a GcmPushMessage and attach a dummy payload
gcm_message = Push0r::GcmPushMessage.new("__registration_id__")
gcm_message.attach({"data" => {"d" => "1"}})

# create a ApnsPushMessage to be sent via the Sandbox apns service and attach a dummy payload
apns_message = Push0r::ApnsPushMessage.new("__device_token__", Push0r::ApnsEnvironment::SANDBOX)
apns_message.attach({"data" => {"v" => "1"}}

# add both messages to the queue
queue.add(gcm_message)
queue.add(apns_message)

# flush the queue to actually transmit the messages
queue.flush

Documentation

Push0r API documentation can be found here.

Error handling

Queue#flush returns an instance of FlushResult which can be queried for failed_messages. This returns an array of FailedMessage instances which in turn offer various attributes like the error code for the failed notification.

Bugs

Please report bugs on GitHub.

About

Ruby library that makes it easy to send push notification to iOS, OSX and Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages