API Docs for: 2.1.0
Show:

DeviceApiWeb Class

Extends DeviceApi

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

DeviceApiWeb

(
  • configuration
)

Parameters:

Methods

getApiVersion

()

Inherited from DeviceApi:

Get the Api version

getProperties

(
  • userAgentOrHeaders
  • clientSideProperties
  • callback
)
Properties

Inherited from DeviceApi:

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 Object

    User Agent string or object of headers

  • clientSideProperties Object

    String 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:

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
)
Properties

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.Request

    nodejs http request

  • cb Function(Error, Properties)

    Optional. Callback function containing errors if any, and properties

Returns:

Properties:

Properties object containing device properties if no callback given.

getPropertiesSync

(
  • userAgentOrHeaders
  • clientSideProperties
)
Properties

Inherited from DeviceApi:

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 Object

    User Agent string or object of headers

  • clientSideProperties String

    of client side properties

Returns:

Properties:

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

Inherited from DeviceApi:

Get a set of all possible property names. Note that the client-side properties are not included in this set.

Returns:

Array:

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
)

Inherited from DeviceApi:

Loads in data from a string

Parameters:

  • json String

    String 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 String

    Path to json data file e.g. /usr/data/DeviceAtlas.json

  • cb Function(error, Properties)

    Callback function (optional)

Throws:

DataFileError:

Error on file read (Synchronous only)

loadDataFromStream

(
  • inputStream
  • cb
)

Loads in data from a steam. Uses nodejs 'fs' module

Parameters:

  • inputStream Stream.Readable

    nodejs Input stream

  • cb Function(Error)

    Callback function containing errors if any