WURFLCloudClient
Summary
WURFL Cloud client module
Item Index
Methods
- configure static
- detectDevice static
- middleware static
- register static
Methods
configure
Syntax
configure
-
configuration
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
Syntax
detectDevice
-
ua
-
[headers]
-
callback
Summary
Detect a device by user agent
Parameters:
-
ua
StringUser Agent string
-
[headers]
Object optionalExtra HTTP headers
-
callback
FunctionCallback 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
Syntax
middleware
-
[configuration]
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:
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
Syntax
register
-
plugin
-
options
-
next
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
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
Syntax
config
Object
Summary
The config object