class Mobi::Mtld::Da::Device::DeviceApi

Copyright
Author

The DeviceAtlas Device Detection API provides a way to detect devices based on the HTTP headers. Using the headers, the API returns device information such as screen width, screen height, is mobile, vendor, model etc.

DeviceApi.properties(user_agent_or_headers, client_side_properties)

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

Example usage:

device_api = Mobi::Mtld::Da::Device::DeviceApi.new
device_api.load_data_from_file "/path/to/datafile.json"

# get all properties from the headers
properties = device_api.properties headers

# .... use the properties ....

if properties.contains?("isMobilePhone", true)
  # it is a mobile phone
end

if properties.has_key?("model")
  device_model = properties.get("model").to_s
end

Public Class Methods

new(config = nil) click to toggle source

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

config

Instance of Config. You can change the DeviceAtlas API

configs by creating an instance of Config and setting your custom config values then passing the instance to the DeviceApi constructor.

Public Instance Methods

get_api_version() click to toggle source

Get DeviceApi version.

get_data_creation_timestamp() click to toggle source

Get the device data (JSON file) creation timestamp.

get_data_revision() click to toggle source

Get the device data (JSON file) revision.

get_data_version() click to toggle source

Get the device data (JSON file) version.

get_properties(user_agent_or_headers, client_side_properties = nil) click to toggle source

Get known properties from a User-Agent or HTTP headers optionally merged with properties from the client side component. The client side component (JS) sets a cookie with collected properties. The client properties will over-ride any properties discovered from the main JSON data file.

user_agent_or_headers

User-Agent string or array of HTTP headers.

client_side_properties

String of client side properties with the format

the client side component provides.

return

Array of Property objects.

get_property_names() click to toggle source

Get a set of available device property names. return: Array of PropertyName objects.

load_data_from_file(json_data_file_path) click to toggle source

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

json_data_file_path

Path to the JSON data file.

load_data_from_string(json_data_string) click to toggle source

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

json_data_string

JSON data string.