Susanna Huhtanen ihmis.suski@gmail.com 2012 Rafael Ferreira rafael.f.f1@gmail.com 2013 Local library geoNames

In this part of the guide we'll construct the local library geoNames using asynchronous calls. Weather information in this example is fetched from geonames.org and the application is using the ICAO codes to place your weather request. To write and run all the code examples yourself, you need an editor to write code in, Terminal and GNOME 3 or higher installed into your computer. In this guide we'll go through the following parts:

Local library for getting the weather

Creating function geoNames

Methods for geoNames

geonames.js

Local library for getting the weather

For this we need a new file that will be our local library.

In the first lines we'll import and initialize the libraries we need to use in this local library. Soup handles all the requests we have to make with http.

Creating function GeoNames

Here we create the function GeoNames that will handle getting weather for us. JavaScript allows us to create functions that have little inside at first and later expand them. This will be done inside the GeoNames.prototype curly braces{}

Methods for GeoNames

The first method for GeoNames is getWeather and the second getIcon. In getWeather we make a http request with soup, handle errors and then parse the information from the request to form we can use it. In getIcon we simply compare the results we got from getWeather to the switch we have in order to get the icon matching current weather. Now that we have our local library ready, it's time to make use of it.

geonames.js

Here is the entire code for our local library. The main program file calls this asynchronously.