WURFL OnSite Scala API: User Guide ================================== The Scala API is built as a wrapper around the WURFL Java API to expose methods to be available from within a Scala application. Below are the requirements that are needed in order to start including WURFL into your Scala project. Requirements ------------ * Java 8 JDK or above * Scala library 2.12.x/2.13.x/3.x * WURFL Java jar 1.11.0.0 or greater (it is highly recommended to use the same version of Scala and Java jar files) Installation ------------ To enable WURFL on your application, you must register for a free account on scientiamobile.com and **download the latest release from your [File Manager](https://filex.scientiamobile.com/user/index#products/onsite).** Once you have downloaded the latest release, you will simply need to add the WURFL Java JAR and the `wurfl-scala.jar` to your build path. Current distribution contains four JAR files, one for each supported Scala version. Pick the one that fits your needs. > **Note:** The WURFL API is closely tied to the `wurfl.xml` file. New versions of the `wurfl.xml` are compatible with old versions of the API by nature, but the reverse is **not** true. Old versions of the `wurfl.xml` are **not** guaranteed to be compatible with new versions of the API. ###Caching It is possible to configure the API with a caching strategy in order to increase performance. Once you have instantiated your WURFL object, you must set the cache provider that you would like to use. The available caching strategy is `LRUMapCacheProvider`. **LRUMapCacheProvider:** ```scala // Create a WURFL object val wurflScala = new Wurfl(new GeneralWURFLEngine("classpath:/resources/wurfl.zip")) // Set cache provider wurflScala.setCacheProvider(new LRUMapCacheProvider) ``` Capability Filtering -------------------- ### Reduce memory usage and increase performance by specifying a subset of the 500+ WURFL capabilities. You can set the desired capabilities using the `setFilter()` method: ```scala // Create a WURFL object val wurflScala = new Wurfl(new GeneralWURFLEngine("classpath:/resources/wurfl.zip")) // Set Capability Filter wurflScala.setFilter( "device_os", "brand_name", "model_name" ) ``` > **Note:** beginning with API 1.8.0.0, it is no longer necessary to specify all mandatory capabilities in a filter. Virtual Capabilities -------------------- Virtual capabilities are an important feature of the WURFL API that obtain values related to the requesting agent out of the HTTP request as a whole (as opposed to limiting itself to capabilities that are found in WURFL). In order to compute its final returned value, a virtual capability may look at regular (non-virtual) capabilities as well as parameters derived from the HTTP request at run-time. Virtual capabilities are useful to model aspects of the HTTP Client that are not easily captured through the finite number of profiles in WURFL. ```scala val wurflScala = new Wurfl(new GeneralWURFLEngine("classpath:/resources/wurfl.zip")) var device = wurflScala.deviceForRequest("Mozilla/5.0 (Linux; U; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30") // Access a virtual capability var smartphone = device.virtualCapability("is_smartphone") ```
Variable Name | Type | Description |
---|---|---|
**is_app** | boolean | Tells you if the Requesting HTTP Client is an App or not. |
**is_smartphone** | boolean | This is a virtual capability that will tell you if a device is a Smartphone for some arbitrary (and subject to change) definition of Smartphone by ScientiaMobile. The virtual capability returns true or false. Patch files can use the `is_smartphone` control capability to override the value returned by the virtual capability. Control capability `is_smartphone` can take value `default`, `force_true` and `force_false`. private |
**is_mobile** | boolean | This is just an ALIAS for `is_wireless_device`. There's no control capability associated to this virtual capability. private |
**is_full_desktop** | boolean | This is just an ALIAS for `ux_full_desktop`. There's no control capability associated to this virtual capability. private |
**is_windows_phone** | boolean | Check if device runs any version of Windows Phone OS. This virtual capability relies on the `device_os` (`product_info` group) capability. private |
**is_ios** | boolean | Check if device runs any version of iOS. This virtual capability relies on the `device_os` (`product_info` group) capability. private |
**is_android** | boolean | Check if device runs any version of Android OS. This virtual capability relies on the `device_os` (`product_info` group) capability. private |
**is_touchscreen** | boolean | This virtual capability tells you whether a device has a touch screen. There is no control capability. Mostly an alias for `pointing_method` == `touchscreen` (`product_info` group) capability. private |
**is_largescreen** | boolean | True if the device has a horizontal and vertical screen resolution greater than 480 pixels. Relies on the `resolution_width` and `resolution_height` (`display` group) capabilities. private |
**is_wml_preferred** | boolean | True if the device is better served with WML. Capability relies on `preferred_markup` (`markup` group). private |
**is_xhtmlmp_preferred** | boolean | True if the device is better served with XHTML MP (Mobile Profile). Capability relies on `preferred_markup` (markup group). private |
**is_html_preferred** | boolean | True if the device is better served with HTML. Capability relies on `preferred_markup` (markup group). private |
**advertised_device_os** | string | This virtual capability will infer the name of the Device OS based on user-agent string analysis (and possibly the analysis of other HTTP headers and WURFL capabilities). private |
**advertised_device_os_version** | string | This virtual capability will infer the version of the Device OS based on user-agent string analysis (and possibly the analysis of other HTTP headers and WURFL capabilities). private |
**advertised_browser** | string | This virtual capability will infer the name of the browser based on user-agent string analysis (and possibly the analysis of other HTTP headers and WURFL capabilities). private |
**advertised_browser_version** | string | This virtual capability will infer the version of the browser based on user-agent string analysis (and possibly the analysis of other HTTP headers and WURFL capabilities). private |
**form_factor** | enumerable | This virtual capability will return one of the following values that identify a client's form factor: `Desktop`, `Tablet`, `Smartphone`, `Feature Phone`, `Smart-TV`, `Robot`, `Other non-Mobile`, `Other Mobile` private |
**complete_device_name** | string | Concatenates brand name, model name and marketing name (where available) of a device into a single string. private |
**is_phone** | boolean | This is a virtual capability that will tell you if a device is a mobile phone . The virtual capability returns true or false. Patch files can use the `is_phone` control capability to override the value returned by the virtual capability. Control capability `is_phone` can take value `default`, `force_true` and `force_false`. private |
**is_app_webview** | boolean | This virtual capability returns true if a HTTP request is from an app based webview. private |
**device_name** | string | Concatenates brand name and marketing name of a device into a single string. If marketing name is not available, model name is used instead. private |
**advertised_app_name** | string | This virtual capability will return the name of the application that generated the User-Agent or the HTTP request. private |
**is_robot** | boolean |