touchads / node-wurfl-api

Node wurfl api lookup
32 stars 18 forks source link

latest wurfl returns almost no data #6

Closed tobsn closed 12 years ago

tobsn commented 12 years ago

Code:

var wurfl = require( 'wurfl' );
var options = { file: __dirname + '/wurfl.xml', groups: [ 'display' ] };
wurfl.loadSync( options ); // wurfl xml file is finished loading into a memory-efficient structure 
wurfl.load( function() {
    var deviceInfo = wurfl.get( 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3' );
    console.log( deviceInfo );
});

Result:

{ id: 'apple_iphone_ver1_suba543',
  user_agent: 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3',
  fall_back: 'apple_iphone_ver1',
  product_info: {},
  wml_ui: {},
  chtml_ui: {},
  xhtml_ui: {},
  ajax: {},
  markup: {},
  cache: {},
  display: {},
  image_format: {},
  bugs: {},
  wta: {},
  security: {},
  bearer: {},
  storage: {},
  object_download: {},
  drm: {},
  streaming: {},
  wap_push: {},
  j2me: {},
  mms: {},
  sms: {},
  sound_format: {},
  flash_lite: {},
  css: {},
  transcoding: {},
  rss: {},
  pdf: {},
  playback: {},
  html_ui: {},
  smarttv: {},
  chips: {} }

same happens with the example XDA string - a fallback and an id is returned and that's where it stops. I think the solution would be to follow up up the fallback or id.

just cloned the git to be sure to have latest and checked against latest wurfl.xml and supplied wurfl.xml and both not return more data than pasted above.

jacwright commented 12 years ago

The "memory-efficient structure" of this library uses the JavaScript prototype chain to look up the data as it is inherited down through a chain of phone entries. Because of this you will not see the full tree using console.log(deviceInfo). You are still able to get at the data (e.g. console.log(deviceInfo.display.physical_screen_height == 74 in the lookup for the user agent you provided above).

If you want to see the properties in a given object you may do a for-i-in.

var wurfl = require( 'wurfl' );
var options = { file: __dirname + '/wurfl.xml', groups: [ 'display' ] };
wurfl.loadSync( options ); // wurfl xml file is finished loading into a memory-efficient structure 
var deviceInfo = wurfl.get( 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3' );

for (var i in deviceInfo.display) {
    console.log(i, '=', deviceInfo.display[i]);
}

A couple of other things to note.

  1. you are loading two wurl files, one synchronously and the other asynchronously. The second time you are not specifying any options, so it is using the default (old) wurfl.xml file. Synchronous: wurfl.loadSync( options ); Asynchronous: wurfl.load( function() {... You are doing both, so loading and parsing two files, the second old one is overwriting the one in your directory.
  2. because you specified groups: [ 'display' ] you will only have the display object populated. If you want everything then leave out the groups option entirely. I'm not sure if you meant this or not.