node-clima
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -35,2 +35,5 @@ var request = require('request'); | ||
} | ||
else { | ||
throw new Error('Format is required.'); | ||
} | ||
if (obj.units) { | ||
@@ -48,5 +51,6 @@ if (metricUnits.indexOf(obj.units) > -1) { | ||
clima.prototype.url = 'http://api.openweathermap.org/data/2.5/weather'; | ||
clima.prototype.format = 'json'; | ||
clima.prototype.units = 'Kelvin'; | ||
clima.prototype.format = ''; | ||
// You can call by city name or city name and country code. | ||
@@ -114,2 +118,5 @@ // API responds with a list of results that match a searching word. | ||
// check format for call | ||
if(this.format === 'xml') obj.qs['mode'] = 'xml'; | ||
// check units for call | ||
if (this.units === 'Celsius') { | ||
@@ -131,4 +138,4 @@ obj.qs['units'] = 'metric'; | ||
} | ||
// console.log(response.statusCode); | ||
if ((response.statusCode === 200) || (response.statusCode === 304)) { | ||
// console.log(body); | ||
callback(err, body); | ||
@@ -135,0 +142,0 @@ } |
{ | ||
"name": "node-clima", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Simple wrapper for OpenWeatherMap API", | ||
@@ -35,3 +35,4 @@ "author": "Roberto Serrano Diaz-Grande", | ||
"http", | ||
"OpenWeatherMap" | ||
"OpenWeatherMap", | ||
"clima" | ||
], | ||
@@ -38,0 +39,0 @@ "keywords": [ |
@@ -10,19 +10,28 @@ var clima = require('../lib/node-clima.js'); | ||
module.exports = { | ||
'Opciones pasadas al constructor invalidas.': function(test) { | ||
'Invalid options passed to constructor.': function(test) { | ||
test.expect(1); | ||
test.throws(function(){ | ||
c = new clima(); | ||
}, Error, 'Opciones pasadas al constructor invalidas, no lanzo error'); | ||
}, Error, 'Invalid options passed to constructor, did not throw error.'); | ||
test.done(); | ||
}, | ||
'Tipo de datos format pasados al constructor invalido': function(test) { | ||
'Format is required': function(test) { | ||
test.expect(1); | ||
test.throws(function(){ | ||
c = new clima({ | ||
}); | ||
}, Error, 'Format is required, did not throw error'); | ||
test.done(); | ||
}, | ||
'Invalid format': function(test) { | ||
test.expect(1); | ||
test.throws(function() { | ||
var c = new clima({ | ||
format: ['212', '212'] | ||
format: 'asd' | ||
}) | ||
}, Error, 'Tipo de datos format invalido'); | ||
}, Error, 'Invalid format, did not throw error.'); | ||
test.done(); | ||
}, | ||
'Tipo de datos units pasados al constructor invalido': function(test) { | ||
'Invalid units': function(test) { | ||
test.expect(1); | ||
@@ -33,3 +42,3 @@ test.throws(function() { | ||
}) | ||
}, Error, 'Tipo de datos format invalido'); | ||
}, Error, 'Invalid units, did not throw error.'); | ||
test.done(); | ||
@@ -36,0 +45,0 @@ }, |
8786
249