55
Mobilize Your Rails Application Brendan Lim e-mail: [email protected] twitter: @brendanlim

Mobilizing Your Rails Application - LA Ruby Conference 2009

Embed Size (px)

DESCRIPTION

Mobilize Your Rails Application - Slides from talk by Brendan G. Lim at LA Ruby Conference 2009 in Tustin, CA.

Citation preview

Page 1: Mobilizing Your Rails Application - LA Ruby Conference 2009

Mobilize Your Rails Application

Brendan Lime-mail: [email protected]

twitter: @brendanlim

Page 2: Mobilizing Your Rails Application - LA Ruby Conference 2009
Page 3: Mobilizing Your Rails Application - LA Ruby Conference 2009

Why care about mobile

• There’s an estimated 2.9 billion mobile users

• Over 255 million mobile users in the U.S.

• In developing nations, a mobile phone is sometimes their only way to connect to the Internet

Page 4: Mobilizing Your Rails Application - LA Ruby Conference 2009

Some mobile stats

(in billions of course)

Page 5: Mobilizing Your Rails Application - LA Ruby Conference 2009

So, how do we take advantage of this?

Page 6: Mobilizing Your Rails Application - LA Ruby Conference 2009

Make your application accessible by the

majority of web enabledweb enabled mobile devices

Page 7: Mobilizing Your Rails Application - LA Ruby Conference 2009

Keep your users engaged through SMSSMS, , MMSMMS and E-E-

MailMail

Page 8: Mobilizing Your Rails Application - LA Ruby Conference 2009

Many Mobile Devices Can Access the Real Web

From Flickr User Carlos Magaña

Page 9: Mobilizing Your Rails Application - LA Ruby Conference 2009

One WebMaking the same information and

services available to all users regardless of the device used

Page 10: Mobilizing Your Rails Application - LA Ruby Conference 2009

• Max resolution?

• JavaScript?

• Flash?

• Connection speed?

• Processor speed?

Problems with one web

Page 11: Mobilizing Your Rails Application - LA Ruby Conference 2009

Mobile Fu Plugin• Can detect if a user is on a mobile

device

• Ability to add custom styling based on the device’s user agent

• Gives you some tools to make the concept of one web easier to achieve

Page 12: Mobilizing Your Rails Application - LA Ruby Conference 2009

How does one master mobile fu?

Page 13: Mobilizing Your Rails Application - LA Ruby Conference 2009

Not Like This ...

Page 14: Mobilizing Your Rails Application - LA Ruby Conference 2009

class ApplicationController < ActionController::Base has_mobile_fuend

Page 15: Mobilizing Your Rails Application - LA Ruby Conference 2009

demo.presentlyapp.com

iPhone Safari

Page 16: Mobilizing Your Rails Application - LA Ruby Conference 2009

respond_to do |format| format.html format.mobileendviews/layouts

application.html.erbapplication.mobile.erb

sessionsnew.html.erbnew.mobile.erb

Page 17: Mobilizing Your Rails Application - LA Ruby Conference 2009

<%= mobile_xhtml_doctype %><html> <head> ... </head> <body> ... </body></html>

../layouts/application.mobile.erb

http://mobiforge.com/designing/story/comparison-xhtml-mobile-profile-and-xhtml-basic

Page 18: Mobilizing Your Rails Application - LA Ruby Conference 2009

<?xml version="1.0" charset="UTF-8" ?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html> <head> ... </head> <body> ... </body></html>

../layouts/application.mobile.erb

http://mobiforge.com/designing/story/comparison-xhtml-mobile-profile-and-xhtml-basic

Page 19: Mobilizing Your Rails Application - LA Ruby Conference 2009

Is the user using a specific device?

is_device?(‘blackberry’)

Is the user using a mobile device?

is_mobile_device?

Is the request format currently :mobile ?

in_mobile_view?

Page 20: Mobilizing Your Rails Application - LA Ruby Conference 2009

iPhone foo_mobilewebkit.css

<%= stylesheet_link_tag 'foo' %>

Android foo_mobilewebkit.css

BlackBerry foo_blackberry.css Win Mobile foo_mobileexplorer.css

etc...

Page 21: Mobilizing Your Rails Application - LA Ruby Conference 2009
Page 22: Mobilizing Your Rails Application - LA Ruby Conference 2009

What about leveraging other

mobile technologies?

Page 23: Mobilizing Your Rails Application - LA Ruby Conference 2009

SMSShort Message Service

Page 24: Mobilizing Your Rails Application - LA Ruby Conference 2009

Keep Users Informed with SMS

• Text messages are read by about 94% of their recipients.

• Supported by almost all mobile phones out there

• Good for quick notifications

• Generally limited to 160 characters

• Relatively easy to leverage

Page 25: Mobilizing Your Rails Application - LA Ruby Conference 2009

What tools can we use to send SMS messages from

our Rails application?

Page 26: Mobilizing Your Rails Application - LA Ruby Conference 2009

Clickatell Gem

• Paid solution

• Uses Clickatell’s API

• Currently $0.043 per text message sent within the U.S.

• No need to know the recipient’s carrier

Page 27: Mobilizing Your Rails Application - LA Ruby Conference 2009

api = Clickatell::API.authenticate('your_api_id', 'your_username', 'your_password')api.send_message('5558675309', 'Hello from clickatell')

require 'clickatell'

Page 28: Mobilizing Your Rails Application - LA Ruby Conference 2009

SMS Fu Plugin• Doesn’t cost the sender anything

• Leverages ActionMailer to send a text message

• You need to know the recipient’s carrier

• Not as many supported carriers as Clickatell

Page 29: Mobilizing Your Rails Application - LA Ruby Conference 2009

Wait, it’s free? So how does it work?

Page 31: Mobilizing Your Rails Application - LA Ruby Conference 2009

deliver_sms(‘5558675309’,‘verizon’, ‘hello!’)

class AwesomeController < ApplicationController has_sms_fuend

Page 32: Mobilizing Your Rails Application - LA Ruby Conference 2009

Some SMS Fu CarriersAlltell, Ameritech, AT&T, Bell South Mobility, BlueSkyFrog, Boost Mobile, Cellular South, Kajeet, Metro PCS,

Powertel, PSC Wireless, Qwest, Southern Link, Spring, Rodgers, Suncom, T-Mobile, Virgin Mobile,

Verizon Wireless, E-Plus, O2, Orange, Telconica, Vodafone ...

Page 33: Mobilizing Your Rails Application - LA Ruby Conference 2009

What if I want to add a new carrier called

Ruby Mobile?

Page 34: Mobilizing Your Rails Application - LA Ruby Conference 2009

carriers: ... ruby_mobile: name: Ruby Mobile value: @txt.rubymobile.com

Add the following to .../config/sms_fu.yml

deliver_sms(‘5558675309’,’ruby_mobile’, ‘hello!’)

Page 35: Mobilizing Your Rails Application - LA Ruby Conference 2009

Remind Your Users That They May Get Charged

from flickr user ‘bowbrick’

Page 36: Mobilizing Your Rails Application - LA Ruby Conference 2009

MMSMultimedia Message

Service

Page 37: Mobilizing Your Rails Application - LA Ruby Conference 2009

MMS

• Can send photo, video, audio or other attachments

• Most commonly used for photos

• Attachment size limitation generally dependent on device

• Multipart MIME

Page 38: Mobilizing Your Rails Application - LA Ruby Conference 2009

The Problem with Receiving MMS

Crap

Crap

Crap

Cat

Page 39: Mobilizing Your Rails Application - LA Ruby Conference 2009

Well, how can I receive SMS or MMS

from my Rails app?

Page 40: Mobilizing Your Rails Application - LA Ruby Conference 2009

Short CodesSpecial numbers that are, you

guessed it, short, that can be used to receive SMS or MMS messages

from mobile phones.

Page 41: Mobilizing Your Rails Application - LA Ruby Conference 2009

Short Codes

• Also referred to as short numbers

• MMS support added in this year

• Crazy Expensive

• Monthly fees up to $1000/mo

• Setup fees close to $5000

• Many companies share short codes

Page 42: Mobilizing Your Rails Application - LA Ruby Conference 2009

Receiving SMS or MMS as an e-mail is another solution and its free and relatively

simple

Page 43: Mobilizing Your Rails Application - LA Ruby Conference 2009

MMS2R Gem

• Removes carrier advertising

• Eliminates carrier default text

• Decodes and extracts intended files from the multipart MIME e-mail

• Most major carriers are supported

Page 44: Mobilizing Your Rails Application - LA Ruby Conference 2009

Retrieve only the intended attachment

mms.default_media

Retrieve all media files from the MMS

mms.media

Retrieve only the intended message

mms.body

Create a new MMS2R object from a TMail object

mms = MMS2R::Media.new(email)

Page 45: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 46: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 47: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 48: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body,

:user => user, :title => mms.subject)# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 49: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 50: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 51: Mobilizing Your Rails Application - LA Ruby Conference 2009

require ‘mms2r’

class MailReceiver < ActionMailer::Basedef receive(email) begin

# load the TMail object into an MMS2R::Media objectmms = MMS2R::Media.new(email)

# grab a user on record by the e-mail it was sent fromuser = User.find_by_email(mms.from)

# store the body of the mms into a new BlogPostblog_post = BlogPost.create(:body => mms.body, :user => user,

:title => mms.subject)

# grab the attachment from the mms messagemedia = mms.default_media

# store the attachment from mms into a BlogPhotoBlogPhoto.create(:uploaded_data => media, :blog_post => blog_post) if

media.content_type.include?(‘image’)

ensure

# cleans up temporary files used for text and attachmentsmms.purge

endendend

Page 52: Mobilizing Your Rails Application - LA Ruby Conference 2009

Adding new templates for carriers is easy

---ignore:  image/gif:   - top.gif  - bottom.gif  - middle_img.gif  text/html:    - /<html>\s+<head>\s+<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=iso-8859-1\">\s+<title>MMS Email<\/title>/imtransform:   text/plain:   - - /Note:\s{1,2}.*?\s+message:\s{1,2}(.+)$/m    - "\1"

conf/mms.myhelio.com.yml

Page 53: Mobilizing Your Rails Application - LA Ruby Conference 2009

Mobilizing your Rails app is simple and

easy

Page 54: Mobilizing Your Rails Application - LA Ruby Conference 2009

Mobile Fuhttp://github.com/brendanlim/mobile-fu/

Clickatellhttp://clickatell.rubyforge.org/

SMS Fuhttp://github.com/brendanlim/sms-fu/

MMS2Rhttp://github.com/monde/mms2r/

Page 55: Mobilizing Your Rails Application - LA Ruby Conference 2009

Questions!