Giter Club home page Giter Club logo

oxyrox / pushmeup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nicoskaralis/pushmeup

0.0 1.0 0.0 245 KB

This gem is a wrapper to send push notifications to devices. Currently it only sends to Android or iOS devices, but more platforms will be added soon. With APNS (Apple Push Notifications Service) you can send push notifications to Apple devices. With GCM (Google Cloud Messaging) you can send push notifications to Android devices.

Home Page: http://nicoskaralis.github.com/pushmeup

License: MIT License

pushmeup's Introduction

Pushmeup

a gem for various push notification services.

Goals

Pushmeup is an attempt to create an push notifications center that could send push to devices like:

  • Android
  • iOS
  • Mac OS X
  • Windows Phone
  • And many others

Currently we have only support for iOS and Android but we are planning code for more plataforms.

Installation

$ gem install pushmeup

or add to your Gemfile

gem 'pushmeup'

and install it with

$ bundle install

APNS (Apple iOS)

Configure

  1. In Keychain access export your certificate and your private key as a p12.

![Keychain Access](https://raw.github.com/NicosKaralis/pushmeup/master/Keychain Access.jpg)

  1. Run the following command to convert the p12 to a pem file

     $ openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
    
  2. After you have created your pem file. Set the host, port and certificate file location on the APNS class. You just need to set this once:

     APNS.host = 'gateway.push.apple.com' 
     # gateway.sandbox.push.apple.com is default
     
     APNS.port = 2195 
     # this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can.
    
     APNS.pem  = '/path/to/pem/file'
     # this is the file you just created
    
     APNS.pass = ''
     # Just in case your pem need a password
    

Usage

Sending a single notification:

    device_token = '123abc456def'
    APNS.send_notification(device_token, 'Hello iPhone!' )
    APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')

Sending multiple notifications

    device_token = '123abc456def'
    n1 = APNS::Notification.new(device_token, 'Hello iPhone!' )
    n2 = APNS::Notification.new(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
    APNS.send_notifications([n1, n2])

Sending more information along

    APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default', 
                                        :other => {:sent => 'with apns gem', :custom_param => "value"})

this will result in a payload like this:

    {"aps":{"alert":"Hello iPhone!","badge":1,"sound":"default"},"sent":"with apns gem", "custom_param":"value"}

Getting your iOS device token

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Register with apple that this app will use push notification
    ...
    
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
    
    ...
    
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Show the device token obtained from apple to the log
    NSLog("deviceToken: %", deviceToken);
}

GCM (Google Cloud Messaging)

Configure

	GCM.host = 'https://android.googleapis.com/gcm/send'
	# https://android.googleapis.com/gcm/send is default

	GCM.format = :json
	# :json is default and only available at the moment

	GCM.key = "123abc456def"
	# this is the apiKey obtained from here https://code.google.com/apis/console/

Usage

Sending a single notification:

	destination = ["device1", "device2", "device3"]
	# can be an string or an array of strings containing the regIds of the devices you want to send

	data = {:key => "value", :key2 => ["array", "value"]}
	# must be an hash with all values you want inside you notification

	GCM.send_notification( destination )
	# Empty notification

	GCM.send_notification( destination, data )
	# Notification with custom information

	GCM.send_notification( destination, data, :collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false )
	# Notification with custom information and parameters

for more information on parameters check documentation: GCM | Android Developers

Sending multiple notifications:

	destination1 = "device1"
	destination2 = ["device2"]
	destination3 = ["device1", "device2", "device3"]
	# can be an string or an array of strings containing the regIds of the devices you want to send

	data1 = {:key => "value", :key2 => ["array", "value"]}
	# must be an hash with all values you want inside you notification
	
	options1 = {:collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false}
	# options for the notification
	
	n1 = GCM::Notification.new(destination1, data1, options1)
	n2 = GCM::Notification.new(destination2, data2)
	n3 = GCM::Notification.new(destination3, data3, options2)

	GCM.send_notifications( [n1, n2, n3] )
	# In this case, every notification has his own parameters

for more information on parameters check documentation: GCM | Android Developers

Getting your Android device token (regId)

Check this link GCM: Getting Started

(Optional) You can add multiple keys for GCM

You can use multiple keys to send notifications, to do it just do this changes in the code

Configure

	GCM.key = { :key1 => "123abc456def", :key2 => "456def123abc" }
	# the ``:key1`` and the ``:key2`` can be any object, they can be the projectID, the date, the version, doesn't matter.
	# The only restrain is: they need to be valid keys for a hash.

Usage

	# For single notification
	GCM.send_notification( destination, :identity => :key1 )
	# Empty notification

	GCM.send_notification( destination, data, :identity => :key1 )
	# Notification with custom information

	GCM.send_notification( destination, data, :collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false, :identity => :key1 )
	# Notification with custom information and parameters

	# For multiple notifications
	options1 = {}
	options2 = {..., :identity => :key2}
	n1 = GCM::Notification.new(destination1, data1, options1.merge({:identity => :key2}))
	n2 = GCM::Notification.new(destination2, data2, :identity => :key1)
	n3 = GCM::Notification.new(destination3, data3, options2)

	GCM.send_notifications( [n1, n2, n3] )
	# In this case, every notification has his own parameters, options and key

Status

Build Status Build Status Code Climate

Dependency Status Dependency Status

Contributing

We would be very pleased if you want to help us!

Currently we need a lot of testing so if you are good at writing tests please help us

License

Pushmeup is released under the MIT license:

http://www.opensource.org/licenses/MIT

pushmeup's People

Contributors

lloydmeta avatar nicoskaralis avatar printercu avatar

Watchers

 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.