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

More...

Inheritance diagram for Com.DeviceAtlas.Device.DeviceApi:
Com.DeviceAtlas.Device.DeviceApiWeb Com.DeviceAtlas.Device.DeviceApiWeb

Public Member Functions

 DeviceApi ()
 Constructs a DeviceApi instance with default config. You can see the default configs in the class "Config". More...
 
 DeviceApi (Config config)
 Constructs a DeviceApi instance with custom config. More...
 
virtual void DownloadAndLoadDataFile (DataFileConfig dataFileConfig)
 Downloads and loads the DeviceAtlas device detection data into the API. The data file is downloaded from the DeviceAtlas web-site. More...
 
virtual void DownloadAndLoadDataFile (string dataFileDownloadUrl)
 Downloads and loads the DeviceAtlas device detection data into the API from a JSON file. The JSON data file is downloaded from the DeviceAtlas web-site. More...
 
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 website. More...
 
virtual void LoadDataFromStream (Stream inputStream)
 Load the DeviceAtlas device detection data into the API from a 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...
 
string GetDeviceAtlasApiVersion ()
 Get DeviceApi version. More...
 
string GetDataVersion ()
 The version of the data file. More...
 
virtual int GetDataCreationTimestamp ()
 Get the device data creation (JSON file) timestamp. More...
 
string GetDataCreationIso8601 ()
 The creation date/time of the loaded data file in ISO 8601 format. More...
 
virtual Properties GetProperties (string identifier)
 Get known properties for an identifier More...
 
Properties GetProperties (string identifier, string clientSideString)
 Get the properties of an identifier 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...
 
Properties GetProperties (NameValueCollection headers, string clientSideString)
 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...
 
Properties GetProperties (IDictionary< string, string > headers)
 
Properties GetProperties (IDictionary< string, string > headers, string clientSideString)
 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 = "3.1.7"
 

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]

Com.DeviceAtlas.Device.DeviceApi.DeviceApi ( )
inline

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

See also
Config

◆ DeviceApi() [2/2]

Com.DeviceAtlas.Device.DeviceApi.DeviceApi ( Config  config)
inline

Constructs a DeviceApi instance with custom config.

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

Member Function Documentation

◆ DownloadAndLoadDataFile() [1/2]

virtual void Com.DeviceAtlas.Device.DeviceApi.DownloadAndLoadDataFile ( DataFileConfig  dataFileConfig)
inlinevirtual

Downloads and loads the DeviceAtlas device detection data into the API. The data file is downloaded from the DeviceAtlas web-site.

Parameters
dataFileConfigData file download and load configuration
Exceptions
DataLoadingException

◆ DownloadAndLoadDataFile() [2/2]

virtual void Com.DeviceAtlas.Device.DeviceApi.DownloadAndLoadDataFile ( string  dataFileDownloadUrl)
inlinevirtual

Downloads and loads the DeviceAtlas device detection data into the API from a JSON file. The JSON data file is downloaded from the DeviceAtlas web-site.

Parameters
dataFileDownloadUrlThe URL to download the data file from.
Exceptions
DataLoadingException

◆ GetApiVersion()

static string Com.DeviceAtlas.Device.DeviceApi.GetApiVersion ( )
inlinestatic

Get DeviceApi version.

Returns
DeviceApi version

◆ GetDataCreationIso8601()

string Com.DeviceAtlas.Device.DeviceApi.GetDataCreationIso8601 ( )
inline

The creation date/time of the loaded data file in ISO 8601 format.

Returns
The creation date/time of the loaded data file in ISO 8601 format.

◆ GetDataCreationTimestamp()

virtual int Com.DeviceAtlas.Device.DeviceApi.GetDataCreationTimestamp ( )
inlinevirtual

Get the device data creation (JSON file) timestamp.

Returns
The data creation timestamp

◆ GetDataVersion()

string Com.DeviceAtlas.Device.DeviceApi.GetDataVersion ( )
inline

The version of the data file.

Returns
The device data file version.

◆ GetDeviceAtlasApiVersion()

string Com.DeviceAtlas.Device.DeviceApi.GetDeviceAtlasApiVersion ( )
inline

Get DeviceApi version.

Returns
DeviceApi version

◆ GetProperties() [1/5]

virtual Properties Com.DeviceAtlas.Device.DeviceApi.GetProperties ( string  identifier)
inlinevirtual

Get known properties for an identifier

Parameters
identifierThe identifier string to identify
Returns
A set of properties (Property objects) wrapped in a Properties object

◆ GetProperties() [2/5]

Properties Com.DeviceAtlas.Device.DeviceApi.GetProperties ( string  identifier,
string  clientSideString 
)
inline

Get the properties of an identifier 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
identifierThe User-Agent string
clientSideStringThe 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/5]

Properties Com.DeviceAtlas.Device.DeviceApi.GetProperties ( NameValueCollection  headers,
string  clientSideString 
)
inline

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
clientSideStringThe contents of the cookie containing the client side properties
Returns
A set of properties (Property objects) wrapped in a Properties object
Exceptions
ClientPropertiesException

◆ GetProperties() [4/5]

Properties Com.DeviceAtlas.Device.DeviceApi.GetProperties ( IDictionary< string, string >  headers)
inline

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() [5/5]

Properties Com.DeviceAtlas.Device.DeviceApi.GetProperties ( IDictionary< string, string >  headers,
string  clientSideString 
)
inline

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
clientSideStringThe 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> Com.DeviceAtlas.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 Com.DeviceAtlas.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 website.

Parameters
jsonDataFilePathPath to the JSON file
Exceptions
DataLoadingException

◆ LoadDataFromStream()

virtual void Com.DeviceAtlas.Device.DeviceApi.LoadDataFromStream ( Stream  inputStream)
inlinevirtual

Load the DeviceAtlas device detection data into the API from a stream.

Parameters
inputStreamInput stream
Exceptions
DataLoadingException

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