A javascript client for FonoApi - Mobile Device Description API https://github.com/shakee93/fonoapi using only javascript apis
A javascript client for FonoApi - Mobile Device Description API https://github.com/shakee93/fonoapi written without JQuery and using only modern web javascript apis:
All these apis are covered (at the time I’m writing, June 2019) by 90% approximately of all the browsers installed worldwide. On caniuse.com you can find more information about api availability on browsers. Anyway you can use a wrapper for these features.
I write a similar api because I think that modern features of javascript, like promises and the fetch api should be used by developers more frequently. So we motivate browser developers to implement these new features more quickly! Modern apis make writing code more simple and intuitive, and make it run without downloading external, sometimes heavy in terms on network bandwith, libraries like jQuery.
The library expose the object FonoApiClient wich contains all the methods to make requests.
<script src="fonoapi_client.js"></script>
<script>
FonoApiClient.setToken("XXXX") //Put your token here
var token = FonoApiClient.getToken() //Get token
</script>
Every endpoint is associated to a method of the same name. The data returned from these methods are arrays of objects containing devices information, as described here.
Search for a device with the specified brand and name.
Accepts the following arguments:
Returns: A promise that resolves to an array of devices.
//Declaration
function getDevice(device: string, brand?: string, offsetPosition?: number) => Promise<object[]>
//Examples
//Obtain all google pixel phones and print them to console.log
var promiseA = FonoApiClient.getDevice("pixel", "google").then(console.log)
//Obtain the second google pixel phone (as we have the previous request) and print it to console.log
var promiseB = FonoApiClient.getDevice("pixel", "google", 2)
.then(devices => device[0]) //Pick the first device, we have only one
.then(console.log)
Return the latest phones of one brand. Can limit the result.
Accepts the following arguments:
Returns: A promise that resolves to an array of devices.
//Declaration
function getLatest(brand: string, limit?: number) => Promise<object[]>
//Examples
//Obtain all the latest google phones usign the server limit and print them to console.log
var promiseA = FonoApiClient.getLatest("google").then(console.log)
//Obtain the 10 latest google phones (as we have the previous request) and print them to console.log
var promiseB = FonoApiClient.getLatest("google", 10).then(console.log)