Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 03bbdc7
Showing
6 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build: | ||
coffee -c index.coffee | ||
|
||
test: | ||
coffee test.coffee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |