<commit_before>var request = require('request')
  , qs = require('querystring');

function Tumblr(credentials) {
    this.credentials = credentials;
}

module.exports = Tumblr;

// Blogs

Tumblr.prototype.blogInfo = function(blogName, callback) {
    blogRequest('/info', blogName, {}, callback, this.credentials);
};

Tumblr.prototype.avatar = function(options, callback) {
};

Tumblr.prototype.followers = function(blogName, options, callback) {
    blogRequest('/followers', blogName, options, callback, this.credentials);
};

Tumblr.prototype.posts = function(blogName, options, callback) {
    blogRequest('/posts', blogName, options, callback, this.credentials);
};

Tumblr.prototype.queue = function(blogName, options, callback) {
    blogRequest('/posts/queue', blogName, options, callback, this.credentials);
};

Tumblr.prototype.drafts = function(blogName, options, callback) {
    blogRequest('/posts/draft', blogName, options, callback, this.credentials);
};

Tumblr.prototype.submissions = function(blogName, options, callback) {
    blogRequest('/posts/submission', blogName, options, callback, this.credentials);
};

// Posts

Tumblr.prototype.edit = function(options) {};
Tumblr.prototype.reblog = function(options) {};
Tumblr.prototype.delete = function(options) {};
Tumblr.prototype.photo = function(options) {};
Tumblr.prototype.quote = function(options) {};
Tumblr.prototype.text = function(options) {};
Tumblr.prototype.link = function(options) {};
Tumblr.prototype.chat = function(options) {};
Tumblr.prototype.audio = function(options) {};
Tumblr.prototype.video = function(options) {};

// User

Tumblr.prototype.userInfo = function(callback) {
    get('/user/info', {}, callback, this.credentials);
};

Tumblr.prototype.dashboard = function(options, callback) {
    get('/user/dashboard', {}, callback, this.credentials);
};

Tumblr.prototype.likes = function(options, callback) {
    get('/user/likes', {}, callback, this.credentials);
};

Tumblr.prototype.following = function(options, callback) {
    get('/user/following', {}, callback, this.credentials);
};

Tumblr.prototype.follow = function(options, callback) {};
Tumblr.prototype.unfollow = function(options, callback) {};
Tumblr.prototype.like = function(options, callback) {};
Tumblr.prototype.unlike = function(options, callback) {};

// Helpers

var blogRequest = function(path, blogName, options, callback, credentials) {
    options = options || {};
    options.api_key = credentials.consumer_key;

    get(blogPathForBlogName(blogName) + path, options, callback, credentials);
};

var blogPathForBlogName = function(blogName) {
    return '/blog/' + blogName + '.tumblr.com';
};

var get = function(path, params, callback, oauth) {
    // TODO: Be smarter about handling which arguments are passed

    // TODO: Is this a good idea?
    if (!callback) {
        callback = function(response) {
            console.log(response);
        };
    }

    var url = 'http://api.tumblr.com/v2' + path;

    // TODO: Better way to checkjust for this? Look at Underscore
    if (params && Object.keys(params).length > 0) {
        url += '?' + qs.stringify(params);
    }

    console.log(url);

    request.get({ url: url, oauth: oauth }, function(err, response, body) {
        // TODO: Error handling

        // TODO: JSON.parse(body) doesn't handle nested objects ([Object object])
        callback(body);
    });
};<commit_msg>Reorganizing<commit_after>var request = require('request')
  , qs = require('querystring');

function Tumblr(credentials) {
  this.credentials = credentials;
}

module.exports = Tumblr;

// TODO: Check option validity (arrays of expected option values)

// Blogs

Tumblr.prototype.blogInfo = function (blogName, callback) {
  blogRequest('/info', blogName, {}, callback, this.credentials);
};

Tumblr.prototype.avatar = function (options, callback) {
};

Tumblr.prototype.followers = function (blogName, options, callback) {
  blogRequest('/followers', blogName, options, callback, this.credentials);
};

Tumblr.prototype.posts = function (blogName, options, callback) {
  blogRequest('/posts', blogName, options, callback, this.credentials);
};

Tumblr.prototype.queue = function (blogName, options, callback) {
  blogRequest('/posts/queue', blogName, options, callback, this.credentials);
};

Tumblr.prototype.drafts = function (blogName, options, callback) {
  blogRequest('/posts/draft', blogName, options, callback, this.credentials);
};

Tumblr.prototype.submissions = function (blogName, options, callback) {
  blogRequest('/posts/submission', blogName, options, callback, this.credentials);
};

// Posts

Tumblr.prototype.edit = function (options) {
};

Tumblr.prototype.reblog = function (options) {
};

Tumblr.prototype.delete = function (options) {
};

Tumblr.prototype.photo = function (options) {
  options = options || {};
  options.type = 'photo';
};

Tumblr.prototype.quote = function (options) {
  options = options || {};
  options.type = 'quote';
};

Tumblr.prototype.text = function (options) {
  options = options || {};
  options.type = 'text';
};

Tumblr.prototype.link = function (options) {
  options = options || {};
  options.type = 'link';
};

Tumblr.prototype.chat = function (options) {
  options = options || {};
  options.type = 'chat';
};

Tumblr.prototype.audio = function (options) {
  options = options || {};
  options.type = 'audio';
};

Tumblr.prototype.video = function (options) {
  options = options || {};
  options.type = 'video';
};

// User

Tumblr.prototype.userInfo = function (callback) {
  get('/user/info', {}, callback, this.credentials);
};

Tumblr.prototype.dashboard = function (options, callback) {
  get('/user/dashboard', options, callback, this.credentials);
};

Tumblr.prototype.likes = function (offset, limit, callback) {
  offset = offset || 0;
  limit = limit || 20;

  get('/user/likes', {offset: offset, limit: limit}, callback, this.credentials);
};

Tumblr.prototype.following = function (offset, limit, callback) {
  offset = offset || 0;
  limit = limit || 20;

  get('/user/following', {offset: offset, limit: limit}, callback, this.credentials);
};

Tumblr.prototype.follow = function (blogName, callback) {
  post('/user/follow', {url: blogURL(blogName)}, callback, this.credentials);
};

Tumblr.prototype.unfollow = function (blogName, callback) {
  post('/user/unfollow', {url: blogURL(blogName)}, callback, this.credentials);
};

Tumblr.prototype.like = function (id, reblogKey, callback) {
};

Tumblr.prototype.unlike = function (id, reblogKey, callback) {
};

// Helpers

var blogRequest = function (path, blogName, options, callback, credentials) {
  options = options || {};
  options.api_key = credentials.consumer_key;

  get(blogURLPath(blogName, path), options, callback, credentials);
};

var blogURL = function (blogName) {
  return blogName + '.tumblr.com';
}

var blogURLPath = function (blogName, path) {
  return '/blog/' + blogURL(blogName) + path;
};

var baseURL = 'http://api.tumblr.com/v2';

var get = function (path, params, callback, oauth) {
  // TODO: Be smarter about handling which arguments are passed
  request.get({url: baseURL + path + '?' + qs.stringify(params), oauth: oauth}, requestCallback(callback));
};

var post = function (path, params, callback, oauth) {
  // TODO: Be smarter about handling which arguments are passed
  console.log('URL: ' + baseURL + path);
  console.log('Body: ' + qs.stringify(params));

  request.post({url: baseURL + path, oauth: oauth, body: qs.stringify(params)}, requestCallback(callback));
};

var requestCallback = function (callback) {
  if (!callback) {
    // If callback has not been provided, log the response (particularly useful in the REPL)
    callback = function (response) {
      console.log(JSON.stringify(response, null, 2));
    };
  }

  return function (err, response, body) {
    if (err)
      return callback('Unknown error');

    var responseBody = JSON.parse(body)
      , statusCode = responseBody.meta.status;

    if (statusCode != 200)
      return callback('API error: ' + statusCode);

    return callback(responseBody.response);
  };
};
{'fraction_non_alphanumeric': 0.15458461538461538, 'fraction_numerical': 0.0016, 'mean_word_length': 4.413724183877415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2687325', 'n_tokens_mistral': 2569, 'n_tokens_neox': 2457, 'n_words': 575}