Top Banner
Create Your Own: Mobile Push-Notification Service Monday, January 13, 14
17

Example Mobile Push Notification Service in Rails

May 06, 2015

Download

Technology

Mo Omer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Example Mobile Push Notification Service in Rails

Create Your Own:Mobile Push-Notification Service

Monday, January 13, 14

Page 2: Example Mobile Push Notification Service in Rails

Starting Point

• To expedite the tutorial process, I’ve already created three models:

• User

• Device

• Permitted Apps

Monday, January 13, 14

Page 3: Example Mobile Push Notification Service in Rails

app/models/user.rb

app/models/device.rb

Monday, January 13, 14

Page 4: Example Mobile Push Notification Service in Rails

app/models/permitted_app.rb

Permitted App Migration

Monday, January 13, 14

Page 5: Example Mobile Push Notification Service in Rails

User and Device Migrations

Monday, January 13, 14

Page 6: Example Mobile Push Notification Service in Rails

Step 2(ish): Routesconfig/routes.rb

lib/app_constraints.rb

Monday, January 13, 14

Page 7: Example Mobile Push Notification Service in Rails

Behold, a versioned API

So, /api/users/ will default to version 1 of our API.

Is this a good idea? There’s 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. I’m 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

Page 8: Example Mobile Push Notification Service in Rails

Controllers and Authentication

Monday, January 13, 14

Page 11: Example Mobile Push Notification Service in Rails

Authentication in Action

Monday, January 13, 14

Page 12: Example Mobile Push Notification Service in Rails

Cool, we have a Users Resource which is accessible via the routes we’ve created on /api/users... what does that have to

do with sending push-notifications to phones?

Monday, January 13, 14

Page 13: Example Mobile Push Notification Service in Rails

How do Push Notifications work? (iOS)

Good documentation of the process can be found on Adobe’s site for Adobe AIR (seriously)http://www.adobe.com/devnet/air/articles/ios-push-notifications.html

Phase 1 Phase 2

Monday, January 13, 14

Page 14: Example Mobile Push Notification Service in Rails

Next, install a background processing system of your choice

https://www.ruby-toolbox.com/categories/Background_Jobs

Monday, January 13, 14

Page 15: Example Mobile Push Notification Service in Rails

iOS worker for Sidekiq

Monday, January 13, 14

Page 16: Example Mobile Push Notification Service in Rails

Android worker for Sidekiq

Monday, January 13, 14

Page 17: Example Mobile Push Notification Service in Rails

Final example• A final example with some additional features is available [1]

• 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 notifications tutorial. [4]

[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-notifications-from-your-rails-backend

• Primary Gems used:

• Sidekiq

• Sidetiq

• Grocer

• GCM

• Active Model Serializers

• Friendly ID

Monday, January 13, 14