<commit_before>/*global ajax*/
import ajax from 'appkit/utils/ajax';
import apiKeys from 'appkit/utils/api-keys';
import fakeWeatherData from 'appkit/utils/fake-weather-data';

var FAKEWEATHERSERVER = true;

function getWeatherData() {
  if (FAKEWEATHERSERVER) { return fakeWeatherData; }

  return new Ember.RSVP.Promise(function (resolve, reject) {
    Ember.$.ajax({
      url : 'http://api.wunderground.com/api/' + apiKeys.wunderground + '/geolookup/conditions/q/WA/Seattle.json',
      dataType : "jsonp",
      success : function(parsed_json) {
        resolve(parsed_json);
      }
    });
  });
}

ajax.defineFixture('/weather', {
  response: 'some weather data',
  jqXHR: {},
  textStatus: 'success'
});

ajax.defineFixture('/image', {
  response: 'some image data',
  jqXHR: {},
  textStatus: 'success'
});


export default Ember.Route.extend({
  model: function () {
    var promises = {
      weatherData: getWeatherData(),
      imageData: ajax('/image')
    };

    return Ember.RSVP.hash(promises);
  }
});<commit_msg>make ajax run loop aware; abstract out settings object<commit_after>/*global ajax*/
import ajax from 'appkit/utils/ajax';
import apiKeys from 'appkit/utils/api-keys';
import fakeWeatherData from 'appkit/utils/fake-weather-data';

var FAKEWEATHERSERVER = true;
var currentWeatherUrl = 'http://api.wunderground.com/api/' +
                        apiKeys.wunderground +
                        '/geolookup/conditions/q/WA/Seattle.json';

function getCurrentWeatherData() {
  // TODO: use local storage to keep a incrementing counter, every 15 reloads,
  // get real data, aka, set this to false, for a sanity check
  // OR
  // stub out use sinon
  // OR
  // ...
  if (FAKEWEATHERSERVER) { return fakeWeatherData; }

  return new Ember.RSVP.Promise(function (resolve, reject) {

    var settings = {
      url : currentWeatherUrl,
      dataType : "jsonp",
      success: function(parsed_json) {
        Ember.run(null, resolve(parsed_json));
      },
      error: function (error_thrown) {
        Ember.run(null, reject(error_thrown));
      }
    };

    Ember.$.ajax(settings);
  });
}

// function getForecastData() {
//   if (FAKEWEATHERSERVER) { return fakeWeatherData; }

//   return new Ember.RSVP.Promise(function (resolve, reject) {
//     Ember.$.ajax({
//       url : 'http://api.wunderground.com/api/' + apiKeys.wunderground + '/geolookup/conditions/q/WA/Seattle.json',
//       dataType : "jsonp",
//       success : function(parsed_json) {
//         resolve(parsed_json);
//       }
//     });
//   });
// }

ajax.defineFixture('/weather', {
  response: 'some weather data',
  jqXHR: {},
  textStatus: 'success'
});

ajax.defineFixture('/image', {
  response: 'some image data',
  jqXHR: {},
  textStatus: 'success'
});


export default Ember.Route.extend({
  model: function () {
    var promises = {
      weatherData: getCurrentWeatherData(),
      // weatherForcastData: getForecastData(),
      imageData: ajax('/image')
    };

    return Ember.RSVP.hash(promises);
  }
});
{'fraction_non_alphanumeric': 0.15059445178335534, 'fraction_numerical': 0.0006605019815059445, 'mean_word_length': 2.9802890932982917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7087019', 'n_tokens_mistral': 1013, 'n_tokens_neox': 994, 'n_words': 206}