Susanna Huhtanen ihmis.suski@gmail.com 2012 Fran Dieguez frandieguez@gnome.org 2012-2013. Biblioteca de geoNames local

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

Biblioteca global para obter o tempo

Para isto precisamos un novo ficheiro que será a nosa biblioteca local.

Nas primeiras liñas precisamos importar e inicializar as bibliotecas que precisamos usar nesta biblioteca local. Soup xestiona todas as solicitudes que facemos con http.

Crear a función GeoNames

Aquí podemos crear a función GeoNames que xestionará a recollida do tempo por nós. JavaScript permítenos crear as funcións que terán pouco dentro delas ao principio pero que crecerán máis tarde. Isto farase dentro das chaves {} de GeoNames.prototype

Métodos para 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

Aquí está o código completo para a nosa biblioteca global. O ficheiro do programa principal chamará a isto de forma asíncrona.