The DeviceAtlas DeviceApi documentation
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Mobi.Mtld.DA.Device.DeviceApi Class Reference

More...

Inheritance diagram for Mobi.Mtld.DA.Device.DeviceApi:
Mobi.Mtld.DA.Device.DeviceApiWeb Mobi.Mtld.DA.Device.DeviceApiWebCore

Public Member Functions

 DeviceApi ()
 Constructs a DeviceApi instance with default configs. You can see the default configs in the class "Config". More...
 
 DeviceApi (Config config)
 Constructs a DeviceApi instance with custom configs. More...
 
void SetConfig (Config config)
 Updates DeviceApi instance with new configs.

See also
Config
Parameters
configAn instance of Config, you can change the DeviceAtlas API configs by creating an instance or Config and setting your preferences config values then passing the instance to the DeviceApi constructor.

 
virtual void LoadDataFromFile (string jsonDataFilePath)
 Load the DeviceAtlas device detection data into the API from a JSON file. The JSON data file is provided by the DeviceAtlas web-site. More...
 
virtual void LoadDataFromStream (Stream inputStream)
 Load the DeviceAtlas device detection data into the API from an input stream. More...
 
ReadOnlyCollection< PropertyNameGetPropertyNames ()
 Get a set of all possible property names. Note that the client-side properties are not included in this set More...
 
virtual string GetDataVersion ()
 Get the device data (JSON file) version. More...
 
virtual int GetDataCreationTimestamp ()
 Get the device data creation (JSON file) timestamp. More...
 
int GetDataRevision ()
 Get the device data generation revision. Deprecated use GetDataCreationTimestamp() for comparing data generation. More...
 
virtual Properties GetProperties (string userAgent)
 Get known properties for a User-Agent. More...
 
virtual Properties GetProperties (string userAgent, string clientSideProperties)
 Get known properties merged with properties from the client side component. The client side component (JS) sets a cookie with collected 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. More...
 
virtual Properties GetProperties (NameValueCollection headers)
 Get known properties for a set of HTTP headers. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. More...
 
virtual Properties GetProperties (NameValueCollection headers, string clientSideProperties)
 Get known properties for a set of HTTP headers merged with properties from the client side component. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. The client side component (JS) sets a cookie with collected 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. More...
 
virtual Properties GetProperties (IDictionary< string, string > headers)
 Get known properties for a set of HTTP headers. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. More...
 
virtual Properties GetProperties (IDictionary< string, string > headers, string clientSideProperties)
 Get known properties for a set of HTTP headers merged with properties from the client side component. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. The client side component (JS) sets a cookie with collected 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. More...
 

Static Public Member Functions

static string GetApiVersion ()
 Get DeviceApi version. More...
 

Public Attributes

const string API_VERSION = "DEVICE_API_VERSION"
 Api version More...
 

Detailed Description

The DeviceAtlas device detection API provides a way to detect devices based on the HTTP headers. Using the headers, the API returns device properties such as screen width, screen height, is mobile, vendor, model etc. If you want to use the DeviceAtlas API in a web application then it is strongly recommended to use DeviceApiWeb instead of this library.

The DeviceApiWeb is preferred when you want to get the properties from a real-time detection on user's device in a web application.

The DeviceApi is preferred when you want to get the properties outside a web application or from an off-line user-agent list or header set.


GetProperties(IDictionary<string, string> headers, string clientSide).

To get the most accurate results: 1- Pass the whole HTTP headers. 2- Use the DeviceAtlas client-side-component and pass the result.

When you have limited data you can also use this alternatives:

GetProperties(NameValueCollection headers).

GetProperties(IDictionary<string, string> headers).

GetProperties(string userAgent, string clientSide).

GetProperties(string userAgent).

Example usage:

    IDictionary<string, string> headers = new Dictionary<string, string>() {
       {"HEADER NAME", "HEADER VALUE"}
    };
    DeviceApi DeviceApi = new DeviceApi();
    try
    {
        DeviceApi.LoadDataFromFile("/path/to/datafile.json");
        Properties props = DeviceApi.GetProperties(headers);
        // .... use the properties ....
        if (props.Contains("isMobilePhone", true))
        {
            // it is a mobile phone
        }
        if (props.ContainsKey("model"))
        {
            string deviceModel = props["model"].AsString();
        }
        if (props.ContainsKey("yearReleased")) */
//      {
/**         int deviceModel = props["yearReleased"].AsInteger();
        }
    }
    catch (...
    
Author
DeviceAtlas Limited

Constructor & Destructor Documentation

◆ DeviceApi() [1/2]

Mobi.Mtld.DA.Device.DeviceApi.DeviceApi ( )
inline

Constructs a DeviceApi instance with default configs. You can see the default configs in the class "Config".

See also
Config

◆ DeviceApi() [2/2]

Mobi.Mtld.DA.Device.DeviceApi.DeviceApi ( Config  config)
inline

Constructs a DeviceApi instance with custom configs.

See also
Config
Parameters
configAn instance of Config, you can change the DeviceAtlas API configs by creating an instance or Config and setting your preferences config values then passing the instance to the DeviceApi constructor.

Member Function Documentation

◆ GetApiVersion()

static string Mobi.Mtld.DA.Device.DeviceApi.GetApiVersion ( )
inlinestatic

Get DeviceApi version.

Returns
DeviceApi version

◆ GetDataCreationTimestamp()

virtual int Mobi.Mtld.DA.Device.DeviceApi.GetDataCreationTimestamp ( )
inlinevirtual

Get the device data creation (JSON file) timestamp.

Returns
The data creation timestamp

◆ GetDataRevision()

int Mobi.Mtld.DA.Device.DeviceApi.GetDataRevision ( )
inline

Get the device data generation revision. Deprecated use GetDataCreationTimestamp() for comparing data generation.

Returns
Data generation revision

◆ GetDataVersion()

virtual string Mobi.Mtld.DA.Device.DeviceApi.GetDataVersion ( )
inlinevirtual

Get the device data (JSON file) version.

Returns
The data version

◆ GetProperties() [1/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( string  userAgent)
inlinevirtual

Get known properties for a User-Agent.

Parameters
userAgentThe User-Agent string
Returns
A set of properties (Property objects) wrapped in a Properties object

◆ GetProperties() [2/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( string  userAgent,
string  clientSideProperties 
)
inlinevirtual

Get known properties merged with properties from the client side component. The client side component (JS) sets a cookie with collected 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
userAgentThe User-Agent string
clientSidePropertiesThe contents of the cookie containing the client side properties
Returns
A set of properties (Property objects) wrapped in a Properties object
Exceptions
ClientPropertiesException

◆ GetProperties() [3/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( NameValueCollection  headers)
inlinevirtual

Get known properties for a set of HTTP headers. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers.

Parameters
headersClient's request HTTP headers
Returns
A set of properties (Property objects) wrapped in a Properties object

◆ GetProperties() [4/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( NameValueCollection  headers,
string  clientSideProperties 
)
inlinevirtual

Get known properties for a set of HTTP headers merged with properties from the client side component. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. The client side component (JS) sets a cookie with collected 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
headersClient's request HTTP headers
clientSidePropertiesThe contents of the cookie containing the client side properties
Returns
A set of properties (Property objects) wrapped in a Properties object
Exceptions
ClientPropertiesException

◆ GetProperties() [5/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( IDictionary< string, string >  headers)
inlinevirtual

Get known properties for a set of HTTP headers. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers.

Parameters
headersClient's request HTTP headers
Returns
A set of properties (Property objects) wrapped in a Properties object

◆ GetProperties() [6/6]

virtual Properties Mobi.Mtld.DA.Device.DeviceApi.GetProperties ( IDictionary< string, string >  headers,
string  clientSideProperties 
)
inlinevirtual

Get known properties for a set of HTTP headers merged with properties from the client side component. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. The client side component (JS) sets a cookie with collected 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
headersClient's request HTTP headers
clientSidePropertiesThe contents of the cookie containing the client side properties
Returns
A set of properties (Property objects) wrapped in a Properties object
Exceptions
ClientPropertiesException

◆ GetPropertyNames()

ReadOnlyCollection<PropertyName> Mobi.Mtld.DA.Device.DeviceApi.GetPropertyNames ( )
inline

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

Returns
A set of available device property names as PropertyName objects. A PropertyName object holds a property-name and it's data-type

◆ LoadDataFromFile()

virtual void Mobi.Mtld.DA.Device.DeviceApi.LoadDataFromFile ( string  jsonDataFilePath)
inlinevirtual

Load the DeviceAtlas device detection data into the API from a JSON file. The JSON data file is provided by the DeviceAtlas web-site.

Parameters
jsonDataFilePathPath to the JSON file
Exceptions
IOException
DataFileException
DataReadException
JsonException

◆ LoadDataFromStream()

virtual void Mobi.Mtld.DA.Device.DeviceApi.LoadDataFromStream ( Stream  inputStream)
inlinevirtual

Load the DeviceAtlas device detection data into the API from an input stream.

Parameters
inputStreamInput stream
Exceptions
IOException
DataReadException
JsonException

Member Data Documentation

◆ API_VERSION

const string Mobi.Mtld.DA.Device.DeviceApi.API_VERSION = "DEVICE_API_VERSION"

Api version


The documentation for this class was generated from the following file: