WURFL Cloud Client

API Docs for: 2.1.1
Show:

WURFLCloudClient

Defined in: lib/index.js:112

Summary

WURFL Cloud client module

Item Index

Methods

Properties

Methods

configure

Defined in lib/index.js:151

Syntax

configure

(
  • configuration
)
static

Summary

Configure the module

An API key can be either sent as apiKey in username:password format or as individual username and password properties.

Parameters:

  • configuration Object

Example:

client.configure({
    host: 'custom-wurfl-cloud-host.com',
    apiKey: 'foobar:1234567890'
});

client.configure({
    username: 'foobar',
    password: '1234567890'
});

detectDevice

Defined in lib/index.js:185

Syntax

detectDevice

(
  • ua
  • [headers]
  • callback
)
static

Summary

Detect a device by user agent

Parameters:

  • ua String

    User Agent string

  • [headers] Object optional

    Extra HTTP headers

  • callback Function

    Callback gets called with (err, result)

Example:

client.detectDevice(userAgent, function(err, result) {
    // result is part of the response from WURFL cloud
});

client.detectDevice(userAgent, {
    'X-Extra-Header': 'Wow!'
}, function(err, result) {
    // result is part of the response from WURFL cloud
});

middleware

Defined in lib/index.js:228

Syntax

middleware

(
  • [configuration]
)
Function static

Summary

Middleware for connect/express-based applications.

It populates a capabilities on the request parameter, containing the capabilities object from the WURFL Cloud response.

Parameters:

  • [configuration] Object optional

Returns:

Function:

The middleware function that takes in the arguments (req, res, next)

Example:

var app = express();
app.use(client.middleware({
    apiKey: '...'
}));
app.get('/', function(req) {
    // req.capabilities is populated now
});

register

Defined in lib/index.js:268

Syntax

register

(
  • plugin
  • options
  • next
)
static

Summary

Hapi 7+ plugin

It populates a capabilities on the request parameter, containing the capabilities object from the WURFL Cloud response.

If the config TTL option is set, it uses the caching interface exposed by Hapi to plugins via plugin.cache.

Parameters:

  • plugin Hapi
  • options Object
  • next Function

Example:

var Hapi = require('hapi');
var server = new Hapi.Server();
server.pack.register({
    plugin: require('wurfl-cloud-client'),
    options: {
        apiKey: '...'
    }
});
server.route({
    method: 'GET',
    path: '/',
    handler: function(request, reply) {
        // request.capabilities is populated now
    }
});

Properties

cache

Defined in lib/index.js:127

Syntax

cache

Object

Summary

The cache interface used to save detections results.

The implementation of the cache layer is left up to the application using this module.

All it needs to expose in this interface is two methods: get and set.

The cache key will be set to device:UA where UA is the User-Agent string with all instances of the : character replaced by _, to play nice with Redis keys.

The TTL for storing these cached values can be defined in the configuration, default is 30 days.

Example:

client.cache = {
    get: function(key, callback) {},
    set: function(key, value, ttl) {}
};

config

Defined in lib/index.js:119

Syntax

config

Object

Summary

The config object