GithubHelp home page GithubHelp logo

tiffani / urbanairship_on_rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yonnage/urbanairship_on_rails

4.0 1.0 1.0 663 KB

create convenient wrapper for sending and managing apple push notificaitons through urbanairship

License: MIT License

Ruby 100.00%

urbanairship_on_rails's Introduction

===================
URBAN AIRSHIP ON RAILS
===================

Borrowed Liberally from APN on Rails Gem but designed to interface with urbanairship for simplicity, ease of use, and speedy deployment of push notifications
uses identical data schema to APN.. perhaps allowing future upgrade to APN

=======
DEPENDENCIES
=======
requires JSON gem
AASM

Note: If you use the aasm gem, you may need to install the gem before you 'config.gem "aasm"' in your environment.rb or include it in your Gemfile.

=======
HOW TO INSTALL
=======
ruby script/plugin install git://github.com/yonnage/urbanairship_on_rails

=======
HOW TO GENERATE MIGRATIONS
=======
ruby script/generate apn_migrations
rake db:migrate

=======
HOW TO CONFIGURE
=======

  =====
  Create an initializer named urbanairship.rb with the following content
  require File.dirname(__FILE__) + '/../../vendor/plugins/urbanairship_on_rails/lib/urbanairship_on_rails/libs/config'
  UA::Config::app_key      = 'YOUR_APP_KEY'
  UA::Config::app_secret   = 'YOUR_APP_SECRET'
  UA::Config::push_secret  = 'YOUR_PUSH_SECRET'  ### CURRENTLY KNOWN AS "Application Master Secret" on Urban Airship
  UA::Config::push_host    = 'go.urbanairship.com'
  UA::Config::push_port    = '443'

  =====
  Set up a daily cron job to set inactive devices to "inactive"
    rake apn:feedback or
    script/runner APN:Feedback.create().run

  Set up a cron job to push and manage notifications
    rake apn:push or
    script/runner APN::Notification.process_pending

  Set up a cron job to push and manage broadcast notifications
    rake apn:broadcast_push or
    script/runner APN::BroadcastNotification.process_pending


=== Examples of Use

  == Create and register a device:
    
    # Create device:
    ## Requires a unique token. Token format should be: 5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz
    
    device = APN::Device.find_or_create_by_token(:token => token)


    #Register the device with Urban Airship
    
    device.register

    # Your device is now registered and ready to receive notifications.


    # Your mobile application should try to register itself each time the application is launched, which is why it's important
    # to do "find_or_create_by_token"
  
  
  == Create and send a single simple Notification:
    
    # Basic Options for Notifications:
    # alert - The message the device will receive.
    # badge - The number of badges (red circle with number) on the device.
    # sound - This is the sound heard on the device.  "default" is the standard device notification sound.
    # device - The device to send the notification to.
    
    n = APN::Notification.create(:alert => "Hello, World", :badge => 1, :sound => "default", :device => device)
    
    # Now send the notification to the device:

    n.push
  

  == Create and send a single Notification with more options:
  
    # Adding more options to a notification.
    # sound - You can also use specific sounds for the alert which are already included as part of the mobile app.
    # badge - Urban Airship supports auto increment / decrement of badges.  Pass "+1" or "-1".
    # custom_properties - Extra information you need to pass to the device.
    
    n = APN::Notification.create(:alert => "Hello, World", :badge => "+1", :device => device, :sound => "alert1.wav", :custom_properties => {:name => "Bobby", :person_id => 7})


    # Now send the notification to the device

    n.push
    

  == Send all pending notifications:
    
    # Instead of sending each notification as it is created, you can send them all at once.
        
    APN::Notification.process_pending
    

    # Or setup a cron rake task:
    
    rake apn:push
    
    
  == Broadcast Notifications
  
    # Send the same notification to all devices.
    # Use this to avoid making multiple connections if you are sending the same message to all devices.
  
    APN::BroadcastNotification.create(:alert => "Hello, World", :badge => 1, :sound => "default")


    # Push the BroadcastNotification

    APN::BroadcastNotification.process_pending
  

    == Broadcast Notifications with Device exclusions.
  
    # You can exclude devices from receiving a broadcast notification.
  
    n = APN::BroadcastNotification.create(:alert => "Hello, World", :badge => 1, :sound => "default")
  
  
    # Exclude any devices that should not receive the above notification.
  
    n.excluded_devices.create(:broadcast_notification => n, :device => APN::Device.find(1))
    n.excluded_devices.create(:broadcast_notification => n, :device => APN::Device.find(2))
    n.excluded_devices.create(:broadcast_notification => n, :device => APN::Device.find(3))


    # Push the Broadcast Notification:
    
    n.push
    
    # -- OR -- Push all pending Broadcast Notifications:
    
    APN::BroadcastNotification.process_pending
    

  == Feedback for Devices
  
    # When a device no longer accepts notifications from your application because of reasons such as the application being removed,
    # Urban Airship will stop trying to send notifications to those devices.  You should run the "feedback" task daily to find and
    # mark all inactive devices as such.
    
    rake apn:feedback


=======
API CALLS and current support level
=======

REGISTRATION
  
  APN::Device.register              => HTTP PUT to /api/device_tokens/<device_token>
  APN::Device.read                  => HTTP GET to /api/device_tokens/<device_token>
  APN::Device.unregister            => HTTP DELETE to /api/device_tokens/<device_token>

PUSH
  APN::Notifcation.push             => HTTP POST to /api/push/

BATCH PUSH
  NOT YET SUPPORTED

BROADCAST
  APN::BroadcastNotifcation.push    => HTTP POST to /api/push/broadcast/

FEEDBACK SERVICE
  APN::Feedback.create().run        => HTTP GET to /api/device_tokens/feedback/?since=<timestamp> 

STATISTICS
  NOT YET SUPPORTED


Copyright (c) 2009 [Russell Sherman([email protected])], released under the MIT license

urbanairship_on_rails's People

Contributors

yonnage avatar rickerbh avatar

Stargazers

Karl Kaebnick avatar DanielKao avatar Ran Tavory avatar Tiffani Ashley Bell avatar

Watchers

Tiffani Ashley Bell avatar

Forkers

rantav

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.