LICENCE_KEY
LICENCE_KEY = 'ENTER-YOUR-LICENCE-KEY'
Set to your DeviceAtlas licence key
DeviceAtlas Cloud API. This client library can be used to easily get device data from the DeviceAtlas Cloud service. To reduce cloud calls and improve performance the API locally caches the data returned from the cloud service.
This API caches data on the disk.
If the cache path is not writable the APin the I
will not proceed even if the device cache is turned off.
It is recommended to set DEBUG = true during implementation so if the cache
path is not writable the errors will not be ignored.
The client is queried by passing either nothing (the request's headers will
be used) or by manually passing a collection of HTTP headers or a user-agent
string. The device properties will then be returned.
Usage (see the provided examples):
try { $data = DeviceAtlasCloudClient::getDeviceData(); } catch (Exception $x) { // handle exceptions ... }
// legacy: (class constant DEBUG = false) // the errors have to be checked manually from the returned array $data = DeviceAtlasCloudClient::getDeviceData();
The returned data is as:
$data[Client::KEY_ERROR] will exist if errors happened while fetching data $data[Client::KEY_PROPERTIES] an array of device properties $data[Client::KEY_USERAGENT] the user-agent string that was used to get the properties $data[Client::KEY_SOURCE] shows where the data came from and is one of: DeviceAtlasCloudClient::SOURCE_FILE_CACHE DeviceAtlasCloudClient::SOURCE_CLOUD DeviceAtlasCloudClient::SOURCE_NONE
// get properties for a user-agent try { $data = DeviceAtlasCloudClient::getDeviceData("user-agent-string ..."); } catch (Exception $x) { // handle exceptions ... }
// get properties for a set of headers $headers = array( "User-Agent" => "Mozilla/5.0 (SymbianOS/9.2; ...", "X-Profile" => "http://nds.nokia.com/uaprof/NN95_8GB-1r100.xml", "Accept" => "text/html,text/css,multipart/mixed,application...", "Accept-Language" => "en-us,en;q=0.5", ); try { $data = DeviceAtlasCloudClient::getDeviceData($headers); } catch (Exception $x) { // handle exceptions ... }
Notes:
1 When in test mode and using cookie cache, changing the user-agent will
not update the cookie cache and you have to manually remove the cookie.
Because in real life the the cookie is on the system it represents.
2 It is recommended to always use file cache. Using cookie cache will cache device info on the user's browser. You can have both caches on, then if device data is found in the cookie it will be used otherwise if data is cached in the files the file cache will be used.
getDeviceData( $param = false) : array
$param |
{ DeviceAtlasCloudClient::KEY_USERAGENT: "UA" | null, DeviceAtlasCloudClient::KEY_SOURCE: "data source", DeviceAtlasCloudClient::KEY_PROPERTIES: {"propertyName": "PropertyVal",} | null, DeviceAtlasCloudClient::KEY_ERROR: err-msg-string | null, }
getServers() : array
Get DeviceAtlas cloud end-point list in the same order used by the API.
If auto-ranking is on then the ranked end-point list is returned otherwise the manual or the default fail-over list is returned. If auto-ranking is on and the end-point list cache is invalid or out of date then the end-points will be ranked and cached first.
DeviceAtlas cloud End-pont list {host: server-address, port: server-port}