DeviceApiWeb Class
A small extension to the core DeviceApi to permit passing of a nodejs http request object. The DeviceApiWeb, the DeviceApi and the DeviceAtlas common jar files must be included. The getProperties of DeviceApiWeb, automatically detects the availability of the client-side properties and will use them for detection. If you want to have a more accurate detection (specially for apple devices) or have the client side properties included in the property sets, simply include the DeviceAtlas client-side component JavaScript library in the pages.
Constructor
Item Index
Methods
getApiVersion
()
Get the Api version
getProperties
-
userAgentOrHeaders
-
clientSideProperties
-
callback
Get properties asynchronously for user agent and/or headers with the client-side properties
The contents of this cookie must be passed to this method. The client properties will over-ride any properties discovered from the main JSON data file.
Parameters:
-
userAgentOrHeaders
ObjectUser Agent string or object of headers
-
clientSideProperties
ObjectString of client side properties, alternatively, the callback if no clientside properties are passed
-
callback
Function(Error, Properties). Callback function containing errors if any, and properties
Returns:
Properties object containing device properties if no callback given
Example:
getProperties('userAgent', 'clientside', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });
getProperties('userAgent', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });
getProperties({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, 'clientside', function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });
getProperties({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, function(err, properties) { if (properties.contains('isMobilePhone', true)) { //it is a mobile } });
getPropertiesFromRequest
-
request
-
cb
Get the Device properties for the given the nodejs http request object. The most suitable headers are extracted and used for detection and property lookup. If the client-side-component has been used and the client-side properties exists in the client-side cookie, then the client-side properties will be included in the result and the device detection for certain devices such as iPhone models will be done more accurately. You can change the API's configs using Config object Depending on the configs the properties may include user-agent dynamic properties and language/locale properties.
Parameters:
-
request
Http.Requestnodejs http request
-
cb
Function(Error, Properties)Optional. Callback function containing errors if any, and properties
Returns:
Properties object containing device properties if no callback given.
getPropertiesSync
-
userAgentOrHeaders
-
clientSideProperties
Get properties synchronously for user agent and/or headers with the client-side properties
The contents of this cookie must be passed to this method. The client properties will over-ride any properties discovered from the main JSON data file.
Parameters:
-
userAgentOrHeaders
ObjectUser Agent string or object of headers
-
clientSideProperties
Stringof client side properties
Returns:
Properties object containing device properties if no callback given
Example:
var properties = getPropertiesSync('userAgent', 'clientside'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }
var properties = getPropertiesSync('userAgent'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }
var properties = getPropertiesSync({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}, 'clientside'); if (properties.contains('isMobilePhone', true)) { //it is a mobile }
var properties = getPropertiesSync({'accept-language': '...','user-agent': '...', 'cookie': 'cookkieName=cookieValue;q=r;'}); if (properties.contains('isMobilePhone', true)) { //it is a mobile }
getPropertyNames
()
Array
Get a set of all possible property names. Note that the client-side properties are not included in this set.
Returns:
A set of all possible device property names as PropertyNameType objects. A PropertyNameType object holds a property-name and it is a data-type
loadData
-
json
Loads in data from a string
Parameters:
-
json
StringString representation of json tree
loadDataFromFile
-
jsonDataFilePath
-
cb
Loads in data from a json file. Uses nodejs 'fs' module.
- Synchronous uses 'fs.readFileSync'
- Asynchronous uses 'fs.createReadStream'
Parameters:
-
jsonDataFilePath
StringPath to json data file e.g. /usr/data/DeviceAtlas.json
-
cb
Function(error, Properties)Callback function (optional)
Throws:
Error on file read (Synchronous only)
loadDataFromStream
-
inputStream
-
cb
Loads in data from a steam. Uses nodejs 'fs' module
Parameters:
-
inputStream
Stream.Readablenodejs Input stream
-
cb
Function(Error)Callback function containing errors if any