diff --git a/weather-app/app.js b/weather-app/app.js index 7b1322e..19c39da 100644 --- a/weather-app/app.js +++ b/weather-app/app.js @@ -6,17 +6,17 @@ const address = process.argv[2] if (!address) { console.log('Please provide an address') } else { - geocode(address, (error, data) => { + geocode(address, (error, {latitude, longitude, location}) => { if (error) { return console.log(error) } - forecast(data.latitude, data.longitude, (error, forecastData) => { + forecast(latitude, longitude, (error, forecastData) => { if (error) { return console.log(error) } - console.log(data.location) + console.log(location) console.log(forecastData) }) }) diff --git a/weather-app/utils/forecast.js b/weather-app/utils/forecast.js index e1d5f1e..f6fe52d 100644 --- a/weather-app/utils/forecast.js +++ b/weather-app/utils/forecast.js @@ -3,13 +3,13 @@ const request = require('request') const forecast = (latitude, longitude, callback) => { const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si' - request({ url: url, json: true }, (error, response) => { + request({ url, json: true }, (error, {body}) => { if (error) { callback('Unable to connect to weather service!', undefined) - } else if (response.body.error) { + } else if (body.error) { callback('Unable to find location', undefined) } else { - callback(undefined, response.body.daily.data[0].summary + ' It is currently ' + response.body.currently.temperature + ' degrees out. There is a ' + response.body.currently.precipProbability + '% chance of rain.') + callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. There is a ' + body.currently.precipProbability + '% chance of rain.') } }) } diff --git a/weather-app/utils/geocode.js b/weather-app/utils/geocode.js index 0a92543..c906174 100644 --- a/weather-app/utils/geocode.js +++ b/weather-app/utils/geocode.js @@ -3,16 +3,16 @@ const request = require('request') const geocode = (address, callback) => { const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURIComponent(address) + '.json?access_token=pk.eyJ1IjoiamF5d2xsIiwiYSI6ImYyZjkyMGNlOTgyNGQ5ZWM5ZDExN2FjNGYwMDZmNTQ4In0.y3lv5ddmGhVNSL7wfMpB0g&limit=1' - request({ url: url, json: true }, (error, response) => { + request({ url, json: true }, (error, {body}) => { if (error) { callback('Unable to connect to location services!', undefined) - } else if (response.body.features.length === 0) { + } else if (body.features.length === 0) { callback('Unable to find location. Try another search.', undefined) } else { callback(undefined, { - latitude: response.body.features[0].center[1], - longitude: response.body.features[0].center[0], - location: response.body.features[0].place_name + latitude: body.features[0].center[1], + longitude: body.features[0].center[0], + location: body.features[0].place_name }) } })