This document provides steps for creating a mobile push notification service using Ruby on Rails. It discusses creating models for users, devices, and permitted apps. It also covers setting up routes and versioning the API. Authentication is implemented using HTTP authentication and tokens. Background jobs are added using Sidekiq to handle sending notifications. Code examples are provided for iOS and Android workers to interface with APNs and GCM respectively to send push notifications from the Rails backend.
7. Behold, a versioned API
So, /api/users/ will default to version 1 of our API.
Is this a good idea? Theres a LOT of discussion about versioning APIs...
http://apiux.com/2013/05/14/api-versioning/
https://mathieu.fenniak.net/aint-nobody-got-time-for-that-api-versioning/
http://railscasts.com/episodes/350-rest-api-versioning
Do what feels comfortable / correct. Im not too keen on having a default API route which may change behind-the-scenes, and
inadvertently break applications that use the API.
Monday, January 13, 14
12. Cool, we have a Users Resource which is accessible via the
routes weve created on /api/users... what does that have to
do with sending push-noti鍖cations to phones?
Monday, January 13, 14
13. How do Push Noti鍖cations work? (iOS)
Phase 1
Good documentation of the process can be found on Adobes site for Adobe AIR (seriously)
http://www.adobe.com/devnet/air/articles/ios-push-noti鍖cations.html
Monday, January 13, 14
Phase 2
14. Next, install a background processing
system of your choice
https://www.ruby-toolbox.com/categories/Background_Jobs
Monday, January 13, 14
17. Final example
A 鍖nal example with some additional features is available [1]
Primary Gems used:
Much credit is due to Ryan Bates for the API skeleton [2] and authentication
implementation [3], and wellwithme.com for their original Android/iOS push
noti鍖cations tutorial. [4]
Sidekiq
Sidetiq
Grocer
Friendly ID
GCM
Active Model Serializers
[1] https://bitbucket.org/momer/example-mobile-pns/src
[2] http://railscasts.com/episodes/350-rest-api-versioning
[3] http://railscasts.com/episodes/352-securing-an-api
[4] http://blog.wellwith.me/how-to-send-ios-and-android-noti鍖cations-from-your-rails-backend
Monday, January 13, 14