nomad-cli / houston

Apple Push Notifications; No Dirigible Required
http://nomad-cli.com
MIT License
2.93k stars 229 forks source link

Using houston within a rails app #90

Closed davidtlee closed 9 years ago

davidtlee commented 9 years ago

This is quite a noob question as I'm still pretty new to rails. I'm wondering where's the right place to do the basic setup for houston? i.e. if I want to send a push notification in a controller, where is the right place to set up the APN code below:

require 'houston'
APN = Houston::Client.development
APN.certificate = File.read("/path/to/apple_push_notification.pem")

Do I do it directly in that controller file? That seems wrong... Do I do it in an initializer file? Is it ok to simply just create an arbitrary file within the initializers directory? Thanks a lot!

kaneda commented 9 years ago

You want to set it up in the environments file, with your dev cert in your development environment and prod cert in your production environment (Rails.root / config / environments).

To run use a delayed job of some sort, e.g. sidekiq.

You should read Rails best practices, but in general anything that goes off system, for which the user is not expecting an immediate response, goes into a queue of some sort.

In general, Rails best practices dictates that logic be moved from a controller to a model and/or help and/or task/job/runner.

mattt commented 9 years ago

Thanks, @kaneda.

lukasnagl commented 9 years ago

Rails 4.2 brought us Active Job. @davidtlee You might want to look into that, when you’re following the advice of @kaneda.

davidtlee commented 9 years ago

Got it, thanks @kaneda, @mattt, and @j4zz! :)