Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Nov 28, 2010
0 parents commit 03bbdc7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
@@ -0,0 +1,5 @@
build:
coffee -c index.coffee

test:
coffee test.coffee
33 changes: 33 additions & 0 deletions README.md
@@ -0,0 +1,33 @@
# node-wurfl-client
Simple client for WURFL's (mobile devices database) HTTP API.

## Installing

$ npm install wurfl-client

## Using

var wurfl = require('wurfl-client')

/*
Point to your WURFL installation here.
Other options:
path - default: '/Tera-Wurfl/webservice.php'
port - default: 80
*/
wurfl.host = 'wurfl.mydomain.com'

var ua = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
var fields = ['brand_name', 'model_name', 'resolution_width', 'resolution_height']

wurfl.query(ua, fields, function(err, data) {
if(err && err.length > 0) puts(inspect(err))
else puts(inspect(data))
});

Expected output:

{ brand_name: 'Google',
model_name: 'Nexus One',
resolution_width: 480,
resolution_height: 800 }
21 changes: 21 additions & 0 deletions example.js
@@ -0,0 +1,21 @@
var inspect = require('sys').inspect
var puts = console.log

var wurfl = require('wurfl-client')

/*
Point to your WURFL installation here.
Other options:
path - default: '/Tera-Wurfl/webservice.php'
port - default: 80
*/
//wurfl.host = 'wurfl.mydomain.com'

//var ua = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_3 like Mac OS X; xx-xx) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16'
var ua = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
var fields = ['brand_name', 'model_name', 'resolution_width', 'resolution_height']

wurfl.query(ua, fields, function(err, data) {
if(err && err.length > 0) puts(inspect(err))
else puts(inspect(data))
});
33 changes: 33 additions & 0 deletions index.coffee
@@ -0,0 +1,33 @@
puts = console.log
inspect = require('sys').inspect
http = require 'http'

urlencode = (str) ->
str = (str+'').toString()
encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+')

@version = '0.0.1'
@host = 'www.tera-wurfl.com'
@port = 80
@path = '/Tera-Wurfl/webservice.php'

@query = (ua, fields, callback) =>
ua = urlencode(ua)
fields = fields.join '|'

wurfl = http.createClient @port, @host
request = wurfl.request 'GET', "#{@path}?ua=#{ua}&search=#{fields}&format=json", 'host': @host
request.end()
request.on 'response', (response) ->
if response.statusCode isnt 200
callback [{'Expected response with status code HTTP 200 OK, got: ': response.statusCode}], null
else
response.setEncoding 'utf8'
data = ''
response.on 'data', (chunk) -> data += chunk
response.on 'end', ->
try
data = JSON.parse data
callback data.errors, data.capabilities
catch e
callback [{'Error parsing response as JSON': e}], null
53 changes: 53 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions package.json
@@ -0,0 +1,14 @@
{
"name": "wurfl-client",
"description": "Simple client for WURFL's (mobile devices database) HTTP API.",
"version": "0.0.1",
"author": "Maurice Machado <maurice@bitbending.com>",
"keywords": ["mobile", "device", "detection"],
"main": "index",
"directories": {
"lib": "."
},
"engines": {
"node": ">= 0.2.5"
}
}

0 comments on commit 03bbdc7

Please sign in to comment.