Apple Push Notifications Toolkit for Ruby 42

Posted by Ben Poweski Thu, 17 Sep 2009 10:56:00 GMT

Lately I’ve been working on an iPhone application that utilizes Push Notifications extensively. While Apple provides great documentation there is still a fair amount of work left up to the developer to send push notification in ordinance to their usage policy.

Since I’m using Rails for the backend I needed a way to maintain a single open SSL connection to prevent setup and tear down for every notification sent. To accomplish this I created an Event Machine based server deamon that that proxies all requests send by Rails application over a local, non SSL socket.

The proxy queues and sends each notification to the Apple notification servers. Additionally I’ve created a command line script to send notifications for testing purposes. My project Apn Server is hosted on Github.

You can add it to your Rails application via

config.gem "bpoweski-apnserver", :lib => 'apnserver', 
  :source => "http://gems.github.com"

You can use either a direct connection to Apple or one through the apnserverd proxy included in the gem. To configure directly to Apple’s server (and also setting up and tearing down a new connection each time). Add the following to your environment.rb.

  ApnServer::Config.pem = '/path/to/pem'
  ApnServer::Config.host = 'gateway.push.apple.com'
  ApnServer::Config.port = 2195

To use the non SSL apnserverd proxy simply drop the PEM configuration option

  ApnServer::Config.host = 'localhost'
  ApnServer::Config.port = 22195

To send a notification from Ruby

  notification = ApnServer::Notification.new
  notification.device_token = Base64.decode64(apns_token)
  notification.alert = message
  notification.badge = 1
  notification.sound = 'default'
  notification.push

You can also send notifications via the line with

  $ apnsend --server gateway.push.apple.com --port 2195 \
     --pem key.pem \
     --b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= \
     --sound default \
     --alert Hello
  1. ShAaNiG 7 months later:

    Looks like some good work. Working with Apple iPhone Apps is a whole new challenge - and one I’m not brave enough to undertake yet, but I’m trying to get together some of the building blocks. I’ll add this to the list.

    Wholesale Brand Name Clothing

  2. samanta 7 months later:
  3. ShAaNiG 7 months later:

    wow…..thanks this website gives the best information of Ruby. A very useful site for the software engineers who like to play around Ruby.

    Wholesalers

  4. angela Helm 8 months later:

    $ apnsend –server gateway.push.apple.com –port 2195 \

     --pem key.pem \
     --b64-token j92f12jh8lqcAwcOVeSIrsBxibaJ0xyCi8/AkmzNlk8= \
     --sound default \
     --alert Hello
    

    Great idea!!!

  5. day care 12 months later:

    How worst these Apple products are as i have recently bought their i-pad but it was worsto to find that i need to use another 30$ to spend to get things working finner!

    I hope you know what i am talking about!

  6. Uzqnqunl about 1 year later:

    Capital expenses, including the costs of oil field leases and drilling equipment, are taxed at an effective rate of nine percent, which is a much lower rate than the 25% rate for general business taxes and lower than the taxes of virtually any other industry, according to a 2005 study by the non-partisan Congressional Budget Office. , campusworkcenter.com, [url=”http://ikvsotjk.gibavyf.co.cc/campusworkcenter.com.html”]campusworkcenter.com[/url], http://ikvsotjk.gibavyf.co.cc/campusworkcenter.com.html campusworkcenter.com, pwativ,

  7. Samuel about 1 year later:

    Hi,it is really useful for me which help me solve some issue.Awesome work,thanks!

  8. Low Cost Web Design about 1 year later:

    I just read through the entire article of yours and it was quite good. This is a great article thanks for sharing this information. I will visit your blog regularly for some latest post.

  9. Wkbqgzhl about 1 year later:

    They often could not detect the file format that was being sent to the printer and thus could not automatically and correctly convert the data stream. , thehalfbloodprince.com, [url=”http://qa8.cultureblood.com/thehalfbloodprince.com.html”]thehalfbloodprince.com[/url], http://qa8.cultureblood.com/thehalfbloodprince.com.html thehalfbloodprince.com, >:-(((,

  10. krzyzowki over 1 year later:

    This is the greatest topic I have read today

  11. darmowe pozycjonowanie over 1 year later:

    Thanks for this great post. Did you do it all on your own? This must’ve taken a lot of time

  12. programy over 1 year later:

    Great blog post, I have been waiting for that

  13. frenky over 1 year later:
  14. kimberlyturner110 over 1 year later:

    Hey really a great blog.Very good searching.This is a great topic.It is really helpful for me solve some issues.neon custom signsgood work i have waiting for your next article.continue your nice work keep it up.

  15. elinorgibson78 over 1 year later:

    Thanks for great topic.I have read today.Thanks for shearing this information.A very useful site for me I will visit your blog regularly at the some new post.Mattress.

  16. Eteiwjnx over 1 year later:
  17. mariyawood@yahoo.co.uk almost 2 years later:

    Thanks for great blog. I read your blog you solve some issues nice site and very good searching.I will visit your post regularly and check this new post and updates.http://www.classicbedsteads.co.uk/about-us.php.

  18. Ouytwvgb almost 2 years later:
  19. Yditeiqz almost 2 years later:
  20. Gyiznbuz almost 2 years later:
  21. Sniajcyd almost 2 years later:
  22. Mqacdunb almost 2 years later:
  23. Wrbdwzsb almost 2 years later:
  24. Utlqgrdx almost 2 years later:
  25. Lhxekpjl almost 2 years later:
  26. Mnsxktoy almost 2 years later:
  27. Qjdfhsgt almost 2 years later:
  28. Mmencuva almost 2 years later:
  29. Gyxabsfg almost 2 years later:
  30. Pcvxhpop almost 2 years later:
  31. Scxlhdxb almost 2 years later:
  32. Cesesyhx almost 2 years later:
  33. Qliylohn almost 2 years later:
  34. Ngaxctps almost 2 years later:
  35. Rridtnbr almost 2 years later:
  36. Umodsrxt almost 2 years later:
  37. Nmilgmpw almost 2 years later:
  38. Bnbngiit almost 2 years later:

    I’ve only just arrived young tits masturbation zxvda

  39. Vixtqpss almost 2 years later:

    Who do you work for? 100ree young nymphet hehf

  40. Ammqryjz about 2 years later:

    What sort of music do you listen to? Astral Nymphets :-OOO

  41. Vdffejrn about 2 years later:

    I’m not working at the moment Pthc Child Porn 7395

  42. Yvxdhjkj about 2 years later:

    I can’t stand football Nn Teen 79919