Skip to content

Instantly share code, notes, and snippets.

@codewithtyler
Created August 9, 2016 00:56
Show Gist options
  • Select an option

  • Save codewithtyler/f35c3b8989b84754aa67e7753a33f96a to your computer and use it in GitHub Desktop.

Select an option

Save codewithtyler/f35c3b8989b84754aa67e7753a33f96a to your computer and use it in GitHub Desktop.
A few ideas I jotted down of how we could integrate API keys into the weather.js project
Weather.init({
key: "12345abcde6789fghij"
});
Weather.getCurrent("Kansas City", function(current) {
console.log(
["currently:",current.temperature(),"and",current.conditions()].join(" ")
);
});
Weather.getForecast("Kansas City", function(forecast) {
console.log("Forecast High in Kelvin: " + forecast.high());
console.log("Forecast High in Fahrenheit" + Weather.kelvinToFahrenheit(forecast.high()));
console.log("Forecast High in Celsius" + Weather.kelvinToCelsius(forecast.high()));
});
@noazark
Copy link
Copy Markdown

noazark commented Aug 12, 2016

Alright! Sorry for the delay. What about this:

let client = new Weather({
  key: "12345abcde6789fghij"
});

client.getCurrent("Kansas City", function(current) {
  console.log(`currently:${current.temperature()} and ${current.conditions()}`);
});

client.getForecast("Kansas City", function(forecast) {
  console.log(`Forecast High in Kelvin: ${forecast.high()}`);
  console.log(`Forecast High in Fahrenheit ${Weather.kelvinToFahrenheit(forecast.high())}`);
  console.log(`Forecast High in Celsius ${Weather.kelvinToCelsius(forecast.high())}`);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment