Created
April 29, 2016 13:19
-
-
Save knowthen/cfc9c898179fe80bc5023f958341fb2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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