The Backend Side of the Mobile

584 views

Published on

A short talk about coding a strong backend using Ruby. Things like build an API Rest-like or send push notifications are covered on this presentation.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
584
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

The Backend Side of the Mobile

  1. 1. The Backend Side of the MobileRodrigo AyalaDesarrolladorRubymartes, 4 de junio de 13
  2. 2. @RodrigoAyalamartes, 4 de junio de 13
  3. 3. Most Ruby Devs don’t wantto leave Rubymartes, 4 de junio de 13
  4. 4. RubyMotionAn Objective-Cimplementation of RubyPropietary MacRuby forkUSD$199.99http://www.rubymotion.com/martes, 4 de junio de 13
  5. 5. RubotoJRuby on AndroidOpen SourceUSD$0 - Free as a beerhttps://github.com/ruboto/rubotomartes, 4 de junio de 13
  6. 6. Mobile HTTPAPI with RubyRuby Web FrameworkOpen SourceUSD$0 - Free as a beerhttp://rubyonrails.org/http://www.sinatrarb.com/martes, 4 de junio de 13
  7. 7. Mobile HTTPAPI with Rubymartes, 4 de junio de 13
  8. 8. API Componentsfor Mobile Appsmartes, 4 de junio de 13
  9. 9. APIUser authentication with tokenPush Notificationsmartes, 4 de junio de 13
  10. 10. APIhttps://github.com/intridea/grapeMicro framework to developREST-like APIRuns on Rack or mounted onwebapp frameworks (Rails,Sinatra, etc.)martes, 4 de junio de 13
  11. 11. module Twitterclass API < Grape::APIversion v1format :jsonprefix apiendendmartes, 4 de junio de 13
  12. 12. helpers dodef current_user@current_user ||= User.authorize!(env)enddef authenticate!error!(401 Unauthorized, 401) unless current_userendendmartes, 4 de junio de 13
  13. 13. resource :statuses dodesc "Return a personal timeline."get :home_timeline doauthenticate!current_user.statuses.limit(20)enddesc "Create a status."params dorequires :status, type: String, desc: "Your status."endpost :tweet doauthenticate!Status.create!({user: current_user,text: params[:status]})endendmartes, 4 de junio de 13
  14. 14. http://myhost.com/api/v1/statuses/home_timeline.jsonmartes, 4 de junio de 13
  15. 15. martes, 4 de junio de 13
  16. 16. {"statuses": [{"id": 1,"secret_value": "dont disclose","content": "hi"}]}martes, 4 de junio de 13
  17. 17. {"statuses": [{"id": 1,"secret_value": "dont disclose","content": "hi"}]}martes, 4 de junio de 13
  18. 18. APIhttps://github.com/LTe/grape-rablAllow to use Rabl templateswith GrapeRabl is a template system togenerate JSON, XMLGrape::Rablmartes, 4 de junio de 13
  19. 19. module Twitterclass API < Grape::APIversion v1format :jsonprefix apiformatter :json, Grape::Formatter::Rablresource :statuses dodesc "Return a personal timeline."get :home_timeline , :rabl => "user" doauthenticate!@statuses = current_user.statuses.limit(20)endendendendGrape::Rablmartes, 4 de junio de 13
  20. 20. # status.rablobject @statuses => :statusesattributes :contentGrape::Rablmartes, 4 de junio de 13
  21. 21. Grape::Rabl{"statuses": [{"id": 1,"secret_value": "dont disclose","content": "hi"}]}martes, 4 de junio de 13
  22. 22. {"statuses": [{"content": "hi"}]}Grape::Rablmartes, 4 de junio de 13
  23. 23. martes, 4 de junio de 13
  24. 24. User authentication with Tokenhttps://github.com/plataformatec/deviseFlexible authentication forRailsmartes, 4 de junio de 13
  25. 25. Token Authenticablemartes, 4 de junio de 13
  26. 26. Devise - Token Authenticabledef authenticatedif warden.authenticated?@current_user = current_userreturn trueelsif params[:auth_token] and @current_user =User.find_by_authentication_token(params[:auth_token])return trueelseerror!(401 Unauthorized, 401)endendmartes, 4 de junio de 13
  27. 27. martes, 4 de junio de 13
  28. 28. Push NotificationsAllow to send Apple PushNotifications (iOS)https://github.com/jpoz/apnsAPNSmartes, 4 de junio de 13
  29. 29. APNS - Push Notifications$ openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcertsmartes, 4 de junio de 13
  30. 30. APNS - Push NotificationsAPNS.host = gateway.push.apple.com# gateway.sandbox.push.apple.com is defaultAPNS.pem = /path/to/pem/file# this is the file you just created# Dir.pwd+”/cert.pem” if you have the certificate on the rootAPNS.port = 2195# this is also the default. Shouldnt ever have to set this, butjust in case Apple goes crazy, you can.martes, 4 de junio de 13
  31. 31. APNS - Push Notificationsdevice_token = 123abc456defAPNS.send_notification(device_token, Hello iPhone! )APNS.send_notification(device_token, :alert => Hello iPhone!,:badge => 1, :sound => default)martes, 4 de junio de 13
  32. 32. APNS - Push Notificationsmartes, 4 de junio de 13
  33. 33. Push NotificationsAllow to send pushnotifications to Androidphones via Google CloudMessagingGCMhttps://github.com/spacialdb/gcmmartes, 4 de junio de 13
  34. 34. APNS - Push Notificationsgcm = GCM.new("GCM_PRIVATE_KEY")options = {:data=> {:ticker=> "mini title",:title => "title",:message => "full message",:custom => custom}}gcm.send_notification([device_token], options)martes, 4 de junio de 13
  35. 35. APNS - Push Notificationsmartes, 4 de junio de 13
  36. 36. martes, 4 de junio de 13
  37. 37. Gracias!martes, 4 de junio de 13

×