Skip to content

Instantly share code, notes, and snippets.

@lukes
Last active August 29, 2015 14:07
Show Gist options
  • Save lukes/f214b75ca691f6f60fed to your computer and use it in GitHub Desktop.
Save lukes/f214b75ca691f6f60fed to your computer and use it in GitHub Desktop.
Ember OpenWeatherMapAdapter
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
headers: {
"x-api-key": "[Your OpenWeatherMap API Key]"
},
findQuery: function(store, type, query) {
var URI = "http://api.openweathermap.org/data/2.5/forecast/daily?lat=%@&lon=%@&lang=%@&mode=json&units=metric".fmt(query.latitude, query.longitude, query.lang);
return Ember.$.get(URI).then(function(response) {
var forecasts = response.list.map(function(item) {
return {
id: response.city.id + '' + item.dt, // id is city code + date
date: item.dt,
min: item.temp.min,
max: item.temp.max,
weather: item.weather[0].main.toLowerCase(),
city: response.city.name
};
});
return {forecasts: forecasts};
});
}
});
import DS from "ember-data";
import OpenWeatherAdapter from "../adapters/open-weather-map";
// See http://openweathermap.org/api for more properties
export default DS.Model.extend({
min: DS.attr(),
max: DS.attr(),
date: DS.attr(),
city: DS.attr(),
weather: DS.attr()
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('forecast', {
latitude: this.get('geolocation.latitude'),
longitude: this.get('geolocation.longitude'),
lang: 'en'
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment