# DeviceAtlas Device Detection API Config # DeviceAtlas DeviceApi Config class provides options to customize the API behavior in terms of memory use, caching, performance and device properties. ### Settings (Config Class Attributes) ### * [Cache Settings](#cache_settings) * [Include User-Agent Properties](#include_ua_props) * [Include Language Properties](#include_lang_props) * [Return NIL When There Are No Properties](#return_nil_when_no_properties) * [Client-side Cookie Name](#cookie_name) <a name="cache_settings"></a> #### Cache Settings #### An internal cache can be used to gain performance. The number of entries can be changed. Note that if it set to zero, the cache is disabled. **Config Property** ```ruby config.max_cache_entries = <integer> ``` **Default Value:** 4096 <a name="include_ua_props"></a> #### Include User-Agent Properties #### Boolean value to enable/disable the addition of User-Agent properties to the detection. They are also known as "dynamic" properties as they can be detected on the fly by directly parsing the User-Agent. Enabling this property will worsen API detection performance. If you don't need these properties, then set it to false. User-Agent/Dynamic properties: browserName, browserVersion, browserRenderingEngine, osName, osVersion **Config Property** ```ruby config.include_ua_props = true/false ``` **Default Value:** true <a name="include_lang_props"></a> #### Include Language Properties #### Boolean value to enable/disable the addition of client's language and locale preferences to the device property set. If you don't need these properties, then set it to false. Language properties: language, languageLocale **Config Property** ```ruby config.include_lang_props = true/false ``` **Default Value:** true <a name="return_nil_when_no_properties"></a> #### Return NIL When There Are No Properties #### Boolean value to make the API either return NIL if the property set to return is empty, or an empty Hash object. **Config Property** ```ruby config.return_nil_when_no_properties = true/false ``` **Default Value:** false <a name="cookie_name"></a> #### Client-side Cookie Name #### Name of the cookie where the Client-side properties will be saved in. When using `get_properties()` method in a web application (DeviceApiWeb), the detection will automatically use the content of this cookie, if it exists. If you want the Client-side properties to be used add the DeviceAtlas client side component (JavaScript lib) to your web-site pages. When the User-Agent or HTTP headers are passed manually to `get_properties()`, the Client-side properties can be also manually passed to this method as second parameter. Note that this config is only used as an argument of `get_properties()`. If you set the cookie name to NULL, then the Client-side properties cookie will be ignored. **Config Property** ```ruby config.cookie_name = <string> ``` **Default Value:** `"DAPROPS"` ### How It Works ### Translating into code how the API settings are used, it is as simple as having an instance of the `DeviceAtlas.Device.Config` class into the `DeviceAtlas.Device.DeviceApi` object and the respective Config public methods to check the wished settings and make the API work according to them. #### Use Of the Default Settings #### When a new instance of the `DeviceAtlas.Device.DeviceApi` class is created, internally another instance of the `DeviceAtlas.Device.Config` class is generated with the default settings. ```ruby device_api = DeviceAtlas::Device::DeviceApi.new ``` #### Use Of Custom Settings #### In order to use custom settings, it is required to explicitly create a Config object, set the settings and pass it to the DeviceApi instance. ### Example Of Use Case ### For the scenario your system works, it is highly recommended to configure the API with the most convenient settings in order to enhance performance, memory footprint and, in general, provide a better user experience. _Reduce response time and memory footprint for a web application_ ``` config = DeviceAtlas::Device::Config.new config.max_cache_entries = 256 config.include_ua_props = false config.include_lang_props = false device_api = DeviceAtlas::Device::DeviceApi.new(config) ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _ https://deviceatlas.com <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li><a href="README.DeviceApi-Web.html">Device Detection for Web</a></li><li><a href="README.DeviceApi-Apps.html">Device Detection for Apps</a></li><li class="disabled"><a href="README.DeviceApi-Config.html">Device Detection API Config</a></li><li><a href="README.Upgrade.html">Device Detection API Upgrade</a></li><li><a href="./ApiDocs/DeviceAtlas/Device/DeviceApi.html">Device API Docs</a></li><li class="divider"></li><li><a href="README.CarrierApi.html">Carrier Identification API</a></li><li><a href="./ApiDocs/DeviceAtlas/Carrier/CarrierApi.html">Carrier API Docs</a></li><li class="divider"></li><li><a href="https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html" target="_blank">Client-side Component</a></li><li><a href="README.ConnectivityAnalyser.html">Connectivity Analyser</a></li></ul></div>