This example shows how to use the 51Degrees Cloud service to lookup the details of a device based on a given 'native model name'. Native model name is a string of characters that are returned from a query to the device's OS. There are different mechanisms to get native model names for Android devices and iOS devices
const path = require('path');
const pipelineCore = require('fiftyone.pipeline.core');
const CloudRequestEngine = require('fiftyone.pipeline.cloudrequestengine');
'/../../../hardwareProfileCloudEngine');
const ExampleUtils = require(path.join(__dirname,
'/../exampleUtils'));
const constants = require(path.join(__dirname, '/../../../constants.js'));
const DataExtension = require(
'fiftyone.devicedetection.shared').dataExtension;
const analyseNativeModel = async function (nativemodel, pipeline, output) {
const flowData = pipeline.createFlowData();
flowData.evidence.add(constants.EVIDENCE_QUERY_NATIVE_MODEL_KEY, nativemodel);
await flowData.process();
output.write('Which devices are associated with the native model name ' +
`'${nativemodel}'?\n`);
flowData.hardware.profiles.forEach(profile => {
const hardwareVendor =
DataExtension.
getValueHelper(profile,
'hardwarevendor');
const hardwareName =
DataExtension.getValueHelper(profile,
'hardwarename');
const hardwareModel =
DataExtension.getValueHelper(profile,
'hardwaremodel');
output.write(`\t${hardwareVendor} ${hardwareName} (${hardwareModel})\n`);
});
};
const run = async function (resourceKey, output) {
output.write('This example finds the details of devices from the ' +
'\'native model name\'.\n');
output.write('The native model name can be retrieved by code running ' +
'on the device (For example, a mobile app).\n');
output.write('For Android devices, see ' +
'https://developer.android.com/reference/android/os/Build#MODEL\n');
output.write('For iOS devices, see ' +
'https://gist.github.com/soapyigu/c99e1f45553070726f14c1bb0a54053b#file-machinename-swift\n');
output.write('----------------------------------------\n');
const requestEngineInstance = new CloudRequestEngine.CloudRequestEngine({
resourceKey: resourceKey
});
const PipelineBuilder = pipelineCore.PipelineBuilder;
const pipeline = new PipelineBuilder()
.add(requestEngineInstance)
.add(hardwareProfileCloudEngineInstance)
.build();
pipeline.on('error', console.error);
const nativeModelAndroid = 'SC-03L';
const nativeModeliOS = 'iPhone11,8';
await analyseNativeModel(nativeModelAndroid, pipeline, output);
await analyseNativeModel(nativeModeliOS, pipeline, output);
};
if (process.env.JEST_WORKER_ID === undefined) {
const args = process.argv.slice(2);
const resourceKey = args.length > 0 ? args[0] : process.env[
ExampleUtils.RESOURCE_KEY_ENV_VAR];
if (resourceKey) {
run(resourceKey, process.stdout);
} else {
console.error('No resource key specified on the command line or in the ' +
`the environment variable '${ExampleUtils.RESOURCE_KEY_ENV_VAR}'. ` +
'The 51Degrees cloud service is accessed using a \'ResourceKey\'. ' +
'For more information ' +
'see https://51degrees.com/documentation/_info__resource_keys.html. ' +
'Native model lookup is not available as a free service. This means that ' +
'you will first need a license key, which can be purchased from our ' +
'pricing page: https://51degrees.com/pricing. Once this is done, a resource ' +
'key with the properties required by this example can be created at ' +
'https://configure.51degrees.com/QKyYH5XT. You can now populate the ' +
'environment variable mentioned at the start of this message with the ' +
'resource key or pass it as the first argument on the command line.');
}
};
module.exports = {
run: run
};