Page 1 of 1

Capabilities type metadata

Posted: Sat Oct 31, 2015 11:33 am
by trickydee
Capabilities/Virtual capabilities are generally declared as Map[String, String] but typically this is actually more similar to Map[String, Any] or a heterogeneous map. Is there anything available in the API (either Scala or Java APIs) to provide some type mapping between the capability and it's type, perhaps a matcher of type String -> Any where the returned is the concrete type of the capability (be it bool, Enumeration, String, Double...)?
This is needed for example when generating JSON out of this map as without this type info all values would be strings.

Regards
William Hill

Re: Capabilities type metadata

Posted: Mon Nov 02, 2015 4:27 pm
by Elliotfehr
Hello,

The Java API does provide certain methods in order to retrieve the capability in its proper type that can be retrieved from a Device object. For example, the `device.getCapabilityAsBool()` method will return the capability as a boolean value and the `device.getCapabilityAsInt()` method will return an integer. We will be adding these methods to the Scala API in our next release in order to retrieve the capability in its proper type.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Tue Nov 03, 2015 5:27 pm
by trickydee
Hi Elliot,
Of course, you're referring to the Device interface, however converting is the easy part. What I'm after is a facade which returns the capability type given it's name, otherwise I'd have to make and maintain a map of this metadata and this might get out of date if new capabilities get added.

Currently I'm playing with a pattern matching approach like this:

Code: Select all

def reshape(capabilityName: String, capabilityValue: String): Option[Any] = capabilityName match {
    case "ajax_preferred_geoloc_api"
         | "xhtmlmp_preferred_mime_type" => return Some(capabilityValue)
         | ...
    case "unique"
         | "is_sencha_touch_ok" => return Some(Try(capabilityValue.toBoolean).getOrElse(false))
         | ...
    case "nokia_edition"
         | "voices" => return Some(Try(capabilityValue.toInt).getOrElse(null))
         | ...
    case _ => return Some(capabilityValue)
Additionally being able to deal with the entire set would be desirable as well.
Elliotfehr wrote:Hello,

The Java API does provide certain methods in order to retrieve the capability in its proper type that can be retrieved from a Device object. For example, the `device.getCapabilityAsBool()` method will return the capability as a boolean value and the `device.getCapabilityAsInt()` method will return an integer. We will be adding these methods to the Scala API in our next release in order to retrieve the capability in its proper type.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Wed Nov 04, 2015 8:55 am
by Elliotfehr
Hello,

This capability currently does not exist in the WURFL API, however I will certainly let you know if this is going to change. We do provide and JSON endpoing that provides a full list of WURFL capabilities along with their desired type along with all possible capability values that can be returned, which is available at: http://scientiamobile.com/download/capabilities.json.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Wed Nov 04, 2015 9:33 am
by trickydee
Thanks Elliot,
We'll use this for now and refactor later on if such a feature is added. Nice thing with the JSON documenting the API, I've actually created a scraper over you documentation page to extract this data but is much cleaner, thanks! :)
Elliotfehr wrote:Hello,

This capability currently does not exist in the WURFL API, however I will certainly let you know if this is going to change. We do provide and JSON endpoing that provides a full list of WURFL capabilities along with their desired type along with all possible capability values that can be returned, which is available at: http://scientiamobile.com/download/capabilities.json.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Wed Nov 04, 2015 5:47 pm
by trickydee
Do you have an equivalent json file for the virtual capabilities?
Elliotfehr wrote:Hello,

This capability currently does not exist in the WURFL API, however I will certainly let you know if this is going to change. We do provide and JSON endpoing that provides a full list of WURFL capabilities along with their desired type along with all possible capability values that can be returned, which is available at: http://scientiamobile.com/download/capabilities.json.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Thu Nov 05, 2015 9:23 am
by Elliotfehr
This JSON file is meant to provide the return values for all capabilities that are contained in the WURFL.xml. Since virtual capabilities are computed their return values can vary much more whereas the physical capabilities can be determined by parsing the WURFL.xml file.

However, you do bring up a valid point and I will look into adding our virtual capabilities to this list in for the purpose of determining the return type, however I am unable to provide any promises at this moment.

Thank you,

Elliot

Re: Capabilities type metadata

Posted: Fri Nov 06, 2015 7:21 pm
by trickydee
Thanks Elliot!
Elliotfehr wrote:This JSON file is meant to provide the return values for all capabilities that are contained in the WURFL.xml. Since virtual capabilities are computed their return values can vary much more whereas the physical capabilities can be determined by parsing the WURFL.xml file.

However, you do bring up a valid point and I will look into adding our virtual capabilities to this list in for the purpose of determining the return type, however I am unable to provide any promises at this moment.

Thank you,

Elliot