<commit_before>var request = require('request');
var RSVP = require('rsvp');
var _ = require('lodash');
var qs = require('querystring');
var cache = require('./q-cache');

var cacheTime = (60 * 1000); //cache specified in minutes
var telQCachingEnabled = true;

function TelQ() {
  'use strict';

  function get(options) {

    var getDfd = RSVP.defer();

    options.expires = (options.expires || 0) * cacheTime;

    var sanitizedOptions = checkRequiredInputs(options);

    if (!sanitizedOptions.url) {
      getDfd.reject(new Error('No url or source provided.'));
    }

    var params = (sanitizedOptions.params) ? sanitizedOptions.params : null,
    url = params ? sanitizedOptions.url + '?' + qs.stringify(params) : sanitizedOptions.url;

    function requestCallback(error, response, body) {
      if (!error && response.statusCode === 200) {

        var result = typeof body === 'string' ? JSON.parse(body) : body;

        if (telQCachingEnabled && options.expires > 0) {
          cache.add({
            id: url,
            value: [result, response],
            expires: new Date(new Date().getTime() + options.expires)
          });
        }

        getDfd.resolve(result, response);
      } else {
        getDfd.reject(error);
      }
    }

    function returnIfCached(cachedItem) {
      if (cachedItem.id === url) {
        getDfd.resolve(cachedItem.value[0], cachedItem.value[1]);
      }
    }

    //memoize short circuit.
    if (telQCachingEnabled) {
      _.each(cache.list(), returnIfCached);
    }

    request.get(url, requestCallback);

    return getDfd.promise;
  }

  function post(options) {<commit_msg>Extends error object<commit_after>var request = require('request');
var RSVP = require('rsvp');
var _ = require('lodash');
var qs = require('querystring');
var cache = require('./q-cache');

var cacheTime = (60 * 1000); //cache specified in minutes
var telQCachingEnabled = true;

function TelQ() {
  'use strict';

  function get(options) {

    var getDfd = RSVP.defer();

    options.expires = (options.expires || 0) * cacheTime;

    var sanitizedOptions = checkRequiredInputs(options);

    if (!sanitizedOptions.url) {
      getDfd.reject(new Error('No url or source provided.'));
    }

    var params = (sanitizedOptions.params) ? sanitizedOptions.params : null,
    url = params ? sanitizedOptions.url + '?' + qs.stringify(params) : sanitizedOptions.url;

    function requestCallback(error, response, body) {
      if (!error && response.statusCode === 200) {

        var result = typeof body === 'string' ? JSON.parse(body) : body;

        if (telQCachingEnabled && options.expires > 0) {
          cache.add({
            id: url,
            value: [result, response],
            expires: new Date(new Date().getTime() + options.expires)
          });
        }

        getDfd.resolve(result, response);
      } else {
        getDfd.reject({error:error, body:body, statusCode:response.statusCode});
      }
    }

    function returnIfCached(cachedItem) {
      if (cachedItem.id === url) {
        getDfd.resolve(cachedItem.value[0], cachedItem.value[1]);
      }
    }

    //memoize short circuit.
    if (telQCachingEnabled) {
      _.each(cache.list(), returnIfCached);
    }

    request.get(url, requestCallback);

    return getDfd.promise;
  }

  function post(options) {
{'fraction_non_alphanumeric': 0.1396045536249251, 'fraction_numerical': 0.007789095266626723, 'mean_word_length': 2.8029612756264237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3651632', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1005, 'n_words': 230}