Git Product home page Git Product logo

wurfl_client's Introduction

= WURFL Client

WURFL Client is a library to do WURFL (http://wurfl.sourceforge.net/) mobile device detection for web applications. 
Included are tools to keep the WURFL file up to date automatically and to prepare a customized lookup tables, which 
allow a fast device detection.

== Mode of Operation
The complete WURFL file is as big as ~16MB. A single device detection against it in Ruby took me 12 seconds, which is 
inaceptable even for the first request of any client. 

There are three optimizations to make the detection work faster:
1.) The WURFL file is customized to remove unused capabilities, reducing it's size considerably.
2.) Client devices are roughly detected by type (e.g. iPhone like, Nokia devices, etc.)
3.) The WURFL Client works with previously prepared lookup tables for the roughly detected device types 
in a Ruby PStore data structure, so Ruby doesn't have to parse XML files on each request. 

The lookup tables are prepared during the WURFL update task, which takes quite some time. But this allows for a 
very fast and for our appliances also accurate recognition. 

The WURFL Client can then be implemented f.i. as a thin Rack service, see Examples.


== Requirements

Ruby Version supporting String.ord -> Possibly integrate http://gist.github.com/251465 as a fix
WURFL gem (http://github.com/pwim/wurfl): Handset, UserAgentMatcher, WURFL Loader


== Installation

    sudo gem install wurfl_client


== Setup

To setup the environment, you have to execute following steps:
1.) download and extract the latest WURFL file to wurfl-latest.xml

    curl -L -o wurfl-latest.xml.gz 
    gunzip wurfl-latest.xml.gz

2.) configure wurfl_minimize.rb by writing a wurfl_minimize.yml like so:

input_file: wurfl-latest.xml
output_file: wurfl-custom.xml
capabilities: [brand_name, model_name, max_image_width, max_image_height, wta_voice_call]

NOTE: You can adapt wurfl_minimize.yml capabilities to your needs. See http://wurfl.sourceforge.net/help_doc.php for a list of available capabilities.

3.) minimize the WURFL XML file. 

    wurfl_minimize.rb 

4.) prepare the lookup tables (builds them into ./lookup directory by default). This will take some time!

		mkdir lookup
    wurfl_prepare_lookup.rb 

Now, you are ready for device detection. If you make an automated script to do this update regularly, you must not forget to clear the lookup directory first. 
The preparation script doesn't overwrite files. For minimal effect on your running webservice, you should use another lookup directory there and copy the 
new data after the update is complete. 

Here is an example automatic update script:

    #!/bin/sh
    curl -L -o wurfl-latest.xml.gz http://sourceforge.net/projects/wurfl/files/WURFL/latest/wurfl-latest.xml.gz/download
    gunzip wurfl-latest.xml.gz
    wurfl_minimize.rb 
    rm lookup/*
    wurfl_prepare_lookup.rb
    cp lookup/* /path/to/production/lookup


== Examples

The device detection is as simple as this call:

    require "wurfl_client"
    
    user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone like Mac OS X; en-us)'
    device = WurflClient::detectMobileDevice(user_agent)
    
    puts "DEVICE: #{hs["brand_name"]} #{hs["model_name"]}"
    
You can easily put the WURFL detection into a Rack (http://rack.rubyforge.org/) middleware. I chose to output the data in JSON format. 
Using following 'config.ru', you can put this online using 'rackup'. 

    require "wurfl_client"

    class RackInterface
    
      def getJSON(handset)
        result = %Q{"WURFL-Client":1}
        if handset
          handset.keys.each do |key|
            result << %Q{,"#{key}":"#{handset[key]}"}
          end
        end
        "{#{result}}"
      end
    
      def call(env)
        user_agent = env["HTTP_USER_AGENT"]
        
        hs = WurflClient.detectMobileDevice(user_agent)
    
        [200, {"Content-Type" => "text/javascript"}, ["#{getJSON(hs)}"] ]
      end
    
    end
    
    run RackInterface.new

Test by opening f.i. http://localhost:9292/. You should see the response
    {"WURFL-Client":1}

You can get results for mobile devices by using the UserAgentSwitcher Firefox extension (http://chrispederick.com/work/user-agent-switcher/).
This can be further extended by a caching mechanism to reduce the server load. Being a Rack layer, it should 
also be possible to integrate this into a rails app. If you know, how to do so, I would really appreciate your 
contribution.

== Author

* Guido Pinkas (Original Author)

== Thanks

Thanks to S. Kamerman from TERA-WURFL (http://www.tera-wurfl.com/) for his WURFL Customizer (http://www.tera-wurfl.com/wiki/index.php/WURFL_Customizer). 
I only had to port the functionality to ruby. 

== Contribution

Contribution is welcome. Please use the github tools (fork, pull request, etc) here on http://github.com/bluecat76/wurfl_client.

== License

The MIT License

Copyright (c) 2010 Binder Trittenwein Kommunikation GmbH (http://www.bindertrittenwein.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

wurfl_client's People

Stargazers

petebytes avatar Martin Wawrusch avatar Guido Pinkas avatar Steve Kamerman avatar Kevin Baker avatar syco avatar Shenouda Bertel avatar

Watchers

Guido Pinkas avatar James Cloos avatar

wurfl_client's Issues

iPhone iOS5 not detected

This useragent returns nil:
iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3

But: It works downcase.

But this useragent is detected as iPhone in lowercase.
Linux; U; Android 2.2.1; de-de; HTC_Wildfire_A3333 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.