uagent

Helps you to develop web applications for desktop or mobile user agents.

Install

$ gem install uagent

Use

require 'rubygmes'
require 'uagent'

# A parser distinguishes between disjoin user agent sets

parser = UAgent::Parser.new([:desktop, :mobile])

ua = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) " +
     "AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"

parser.call({ 'HTTP_USER_AGENT' => 'ua })    # gets :mobile

ua = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.10) " +
     "Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10"

parser.call({ 'HTTP_USER_AGENT' => 'ua })    # gets :desktop

Also you can add more keywords to get a more specific device classification.

parser = UAgent::Parser.new([:desktop, :mobile, :iphone])

ua = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) " +
     "AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"

parser.call({ 'HTTP_USER_AGENT' => 'ua })    # gets :iphone

ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-US) " +
     "AppleWebKit/530.17 (KHTML, like Gecko) Version/6.0.0.62 Mobile Safari/530.17"

parser.call({ 'HTTP_USER_AGENT' => 'ua })    # gets :mobile

Now we are working with the keywords :desktop, :mobile, :iphone and :blackberry. Look the tests for more information.

Install from code

First download the code from the repository:

$ git clone [email protected]:danielhz/uagent.git

This project uses jeweler to build the gem, so you can use this commands:

$ rake build            # to build the gem
$ rake install          # to build and install the gem in one step

Also, if you want test the gem you can use the spec task:

$ rake spec

This project uses rcov so you can check the coverage opening the HTML file in the coverage directory after running the spec.

Other Stuff

Author

Daniel Hernández, [email protected]

License

GPL V3

Warranty

This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.