<commit_before>App.ApplicationAdapter = DS.RESTAdapter.extend({
  namespace: null,

  init: function(){
    this.set('namespace', this.container.lookup('application:main'));
    return this._super.apply(this, arguments);
  },

  findQuery: function(store, type, query) {
    query.limit = this.namespace.api_config.limit;
    return this.ajax(this.buildURL(type.typeKey, query), 'GET', {data: query});
  },

  ajax: function(url, type, hash){
    var promise = this._super(url, type, hash), success;

    success = function(promise, payload){
      if (payload.meta && payload.meta.status){
        if (payload.meta.status !== 200){
          return Ember.RSVP.reject('Bad status code: %@ with message "%@"'.fmt(
            payload.meta.status, payload.meta.msg));
        }
      }
      return payload;
    };

    return promise.then(
      Em.$.proxy(success, this, promise),
      Em.$.proxy(this.ajax_failure, this)
    );
  },

  ajax_failure: function(error){
    var message;

    if (Em.typeOf(error) === 'object' && (!!error.statusText || !!error.status)){
      message = '%@ %@'.fmt(error.statusText, error.status);
    } else if (!!error.message) {
      message = error.message;
    } else {
      message = error;
    }

    Em.debug('Failed with %@'.fmt(message));
  },

  ajaxOptions: function(url, type, hash){
    hash = this._super(url, type, hash);

    if (this.get('online'))
      hash.dataType = 'jsonp';

    return hash;
  },

  buildURL: function(type, query){
    'use strict';
    var url = [],
        host = this.get('api_host'),
        namespace = this.get('api_namespace'),
        blog_name = query.blog_name;
    delete query.blog_name;

    // both types of url star with the host and namespace
    url.push(host, namespace);

    if (!blog_name){
      // the currently authenticated users dashboard
      url.push('user/dashboard');

    } else {
      // whichever single blog is currently selected
      url.push(
        'blog',
        blog_name + '.tumblr.com',
        'posts', this.pathForType(type)
      );
    }

    // filter out falsy segments
    url = url.filter(function(x){ return !!x; });
    url = url.join('/');

    return url;
  },

  pathForType: function(type){
    // simply posts are accessable at the root url,
    // everything else is as per normal Ember Data
    // convention

    if (type == 'post'){
      return '';
    } else {
      return this._super(type);
    }
  }
});

if (!false){
  App.ApplicationAdapter.reopen({
    api_host: 'http://api.tumblr.com',
    api_namespace: 'v2',
    online: true
  });
} else {
  App.ApplicationAdapter.reopen({
    namespace: 'posts',
    online: false
  });
}<commit_msg>Live data is best data<commit_after>App.ApplicationAdapter = DS.RESTAdapter.extend({
  api_host: 'http://api.tumblr.com',
  api_namespace: 'v2',

  namespace: null,

  init: function(){
    this.set('namespace', this.container.lookup('application:main'));
    return this._super.apply(this, arguments);
  },

  findQuery: function(store, type, query) {
    query.limit = this.namespace.api_config.limit;
    return this.ajax(this.buildURL(type.typeKey, query), 'GET', {data: query});
  },

  ajax: function(url, type, hash){
    var promise = this._super(url, type, hash), success;

    success = function(promise, payload){
      if (payload.meta && payload.meta.status){
        if (payload.meta.status !== 200){
          return Ember.RSVP.reject('Bad status code: %@ with message "%@"'.fmt(
            payload.meta.status, payload.meta.msg));
        }
      }
      return payload;
    };

    return promise.then(
      Em.$.proxy(success, this, promise),
      Em.$.proxy(this.ajax_failure, this)
    );
  },

  ajax_failure: function(error){
    var message;

    if (Em.typeOf(error) === 'object' && (!!error.statusText || !!error.status)){
      message = '%@ %@'.fmt(error.statusText, error.status);
    } else if (!!error.message) {
      message = error.message;
    } else {
      message = error;
    }

    Em.debug('Failed with %@'.fmt(message));
  },

  ajaxOptions: function(url, type, hash){
    hash = this._super(url, type, hash);

    hash.dataType = 'jsonp';

    return hash;
  },

  buildURL: function(type, query){
    'use strict';
    var url = [],
        host = this.get('api_host'),
        namespace = this.get('api_namespace'),
        blog_name = query.blog_name;
    delete query.blog_name;

    // both types of url star with the host and namespace
    url.push(host, namespace);

    if (!blog_name){
      // the currently authenticated users dashboard
      url.push('user/dashboard');

    } else {
      // whichever single blog is currently selected
      url.push(
        'blog',
        blog_name + '.tumblr.com',
        'posts', this.pathForType(type)
      );
    }

    // filter out falsy segments
    url = url.filter(function(x){ return !!x; });
    url = url.join('/');

    return url;
  },

  pathForType: function(type){
    // simply posts are accessable at the root url,
    // everything else is as per normal Ember Data
    // convention

    if (type == 'post'){
      return '';
    } else {
      return this._super(type);
    }
  }
});
{'fraction_non_alphanumeric': 0.15529865125240847, 'fraction_numerical': 0.0015414258188824663, 'mean_word_length': 2.58, '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': '224905', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1596, 'n_words': 387}