It takes in the method used for the API along with an array of arguments.įor our example, the method will be /api/images/get?, and our array will have our options (such as choosing the size of the image returned, the return format, the type of image etc.). This function initializes a cURL session with the CatAPI. get_image_items($method, $arguments = array()) Inside the class we define several methods, which we'll use to interact with the CatAPI and display useful information about the Battery Status API. Our main interaction with the CatAPI will be via the battery_api_class.php file. If you want to get straight to the code, feel free to fork a copy from the SitePoint GitHub account. If you're new to cURL, it's probably best to read up on it first. It's here that the majority of the fun stuff will be happening - as we check for API support and how we can interact with it. The page will initially get a few images from the CatAPI and display useful information about the battery state and battery API.Ĭreating the JavaScript interactivity with the battery status API. (This process will be executed via Ajax.)īuilding our basic landing page. Once the user loads the page, it will continually pull images from the API and replace our existing images.Ĭreating a new PHP class that will handle the interactions with the CatAPI.Įxtending a new class that will be used to get a single image from the CatAPI and return it back to our browser for processing. The website will display random images from The Cat API and show them to our users. Chrome added support in version 39 (October 2014), closely followed by Opera with its 25th version (October 2014) While the Battery API makes the most sense for mobile devices (and their browsers), it's still important to have support for the API across the traditional browsers, as they're often used on laptops and other portable devices (where the API is useful).įirefox, again, has the longest history of support, back to version 18 (launched in 2012). Opera followed suit in version 25 (October 2014) and finally Chrome in version 40 (April 2015). FireFox mobile has had the longest support, ranging back to early days of version 18 (January 2013). Mobile browsers are where support is most important. On a positive note, a good number of browsers now support it (as of November 2015), so now's the perfect time to get up and running with this API. Since the Battery API is not finalized, it doesn't have universal support across all browsers yet. Overall, the idea is that we can use the Battery API to provide some good defaults that save battery power, while providing more options for interacting with the website. Providing an option or setting so users could set what they want is also a good idea. We could use the state to determine how frequently our tasks should be called, in order to minimize network usage.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |