Skip to content

Instantly share code, notes, and snippets.

@knowthen
Created April 29, 2016 13:19
Show Gist options
  • Save knowthen/cfc9c898179fe80bc5023f958341fb2f to your computer and use it in GitHub Desktop.
Save knowthen/cfc9c898179fe80bc5023f958341fb2f to your computer and use it in GitHub Desktop.
var Promise = require('bluebird');
var request = require('request');
/**
* Find the temperature at a location
* @param {String} zipcode
* @param {function} callBack
* @return {Promise}
*/
var findPopulationByZipCode = function(zipcode, callBack){
var temp;
var def = Promise.defer();
var url = 'http://www.mocky.io/v2/546645359040dd0a01196e83'
var options = {
url: url,
json: true
};
request(options, function(err, response, body){
if(err){
if(callBack){
callBack(err);
}
def.reject(err);
}
else{
if(body && body.population){
temp = body.population;
}
if(callBack){
callBack(null, temp);
}
def.resolve(temp);
}
});
return def.promise;
}
module.exports = {
findPopulationByZipCode: findPopulationByZipCode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment