class Client

Copyright
Author

Class to create multiple instances to connect to the Cloud service.

Constants

API_VERSION
CLOUD_PATH

Cloud service.

DA_HEADER_PREFIX

Headers.

ESSENTIAL_HEADERS

A list of headers from the end user to pass to DeviceAtlas Cloud. These help with detection, especially if a third party browser or a proxy changes the original user-agent.

ESSENTIAL_USER_AGENT_HEADERS

A list of headers which may contain the original user agent. These headers are sent to cloud server beside ESSENTIAL_HEADERS.

EXTRA_HEADERS

A list of additional headers to send to DeviceAtlas. These are not sent by default. These headers can be used for carrier detection and geoip.

FAILOVER_CONTINUE

Action to be taken after an end-point responds: If the error controller returns this the fail-over mechanism must try the next end-point

FAILOVER_NOT_REQUIRED

Action to be taken after an end-point responds: If an-endpoint response was fine

FAILOVER_STOP

Action to be taken after an end-point responds: If the error controller returns this the fail-over mechanism must stop trying the next end-point

KEY_ERROR
KEY_PROPERTIES
KEY_SOURCE
KEY_USERAGENT

Keys of the array returned by #get_device_data()

SOURCE_CACHE

Device data source

SOURCE_CLOUD
SOURCE_NONE

Attributes

called_servers[R]
cookies[RW]
fatal_errors[R]
headers[RW]
last_used_cloud_url[R]
ranking_status[R]
self_auto_ranking[R]
settings[R]

Public Class Methods

new(headers = nil, cookies = nil) click to toggle source

Store the request details: headers and cookie content.

headers

Hash of headers from the request.

cookies

Hash of cookies from the request.

Public Instance Methods

get_cache_base_path() click to toggle source

Get the directory path in which the DeviceAtlas CloudApi puts cache files in (device data cache and server fail-over list).

return

String with the cache directory

get_cloud_url() click to toggle source

Get the URL of the latest DeviceAtlas cloud end-point that returned device properties successfully.

There are three cases where this function will return nil: 1) If device properties come from cache. 2) If licence is wrong, expired or exceeded quota. 3) None end-point were reached or could return device properties.

return

String with the used end-point URL.

get_device_data(param = false) click to toggle source

Get device data from DeviceAtlas Cloud. Once data has been returned from DeviceAtlas Cloud it can be cached locally to speed up subsequent requests. If device data provided by the DeviceAtlas JavaScript library exists in a cookie then cloud data will be merged with the cookie data.

param

Browser headers or boolean value to use a fake UserAgent to test

the API.

return

Hash of properties, source, user-agent and error message if any

happens.

get_servers() click to toggle source

Get the end-point list.

return

Array of hashes with end-point info.

get_servers_latencies(num_requests = @settings.auto_server_ranking_num_requests) click to toggle source

Get a list of cloud end-points and their service latencies.

num_requests

Number of times to send requests to an end-point per test

return

Array of end-point info {{avg:, latencies:, host:, port:},}

rank_servers(servers = nil) click to toggle source

Sort servers by availability and latency to save them in cache.

servers

If servers are provided, they are used to be ranked.

return

Boolean value. True if servers could be ranked. Else, False.

servers() click to toggle source

Get the current server list.

return

Array of hashes with server details.

servers=(server_hash) click to toggle source

Set the server list based on a hash of server details.

server_hash

Array of hashes with server information.