<commit_before>'use strict';

var request = require('supertest');

var configuration = require('../config/configuration.js');

/**
 * Extend the prototype of Anyfetch with manager-related functions
 */
module.exports = function addManagerFunctions(AnyFetch) {
  /**
   * Override the default MANAGER_URL for the **current instance only**.
   * Useful for testing.
   */
  AnyFetch.prototype.setManagerUrl = function(url) {
    this.managerUrl = url;
  };

  /**
   * Override the default MANAGER_URL for all future instances.
   * Useful for testing.
   */
  AnyFetch.setManagerUrl = function(url) {
    configuration.managerUrl = url;
  };

  /**
   * Trade authentification credentials for an access token with the AnyFetch API.
   * @param {String} APP_ID Obtained from manager.anyfetch.com
   * @param {String} APP_SECRET Obtained from manager.anyfetch.com
   * @param {String} code Code obtained during the first step of the oAuth flow
   * @param {function} cb(err, accessToken)
   */
  AnyFetch.getAccessToken = function(APP_ID, APP_SECRET, code, cb) {
    var body = {
      client_id: APP_ID,
      client_secret: APP_SECRET,
      code: code,
      grant_type: 'authorization_code'
    };

    request(configuration.managerUrl)
      .post(configuration.oAuthEndpoint)
      .type('form')
      .send(body)
      .expect(200)
      .end(function(err, res) {
        if(err) {
          return cb(err);
        }
        if(!res.body || !res.body.access_token) {
          return cb(new Error('Expected response to contain `access_token`, got ' + res.body));
        }

        cb(err, res.body.access_token);
      });
  };


  return AnyFetch;
};
<commit_msg>`getAvailableProviders` function<commit_after>'use strict';

var request = require('supertest');

var configuration = require('../config/configuration.js');

/**
 * Extend the prototype of Anyfetch with manager-related functions
 */
module.exports = function addManagerFunctions(AnyFetch) {
  /**
   * Override the default MANAGER_URL for the **current instance only**.
   * Useful for testing.
   */
  AnyFetch.prototype.setManagerUrl = function(url) {
    this.managerUrl = url;
  };

  /**
   * Override the default MANAGER_URL for all future instances.
   * Useful for testing.
   */
  AnyFetch.setManagerUrl = function(url) {
    configuration.managerUrl = url;
  };

  /**
   * Trade authentification credentials for an access token with the AnyFetch API.
   * @param {String} APP_ID Obtained from manager.anyfetch.com
   * @param {String} APP_SECRET Obtained from manager.anyfetch.com
   * @param {String} code Code obtained during the first step of the oAuth flow
   * @param {function} cb(err, accessToken)
   */
  AnyFetch.getAccessToken = function(APP_ID, APP_SECRET, code, cb) {
    var body = {
      client_id: APP_ID,
      client_secret: APP_SECRET,
      code: code,
      grant_type: 'authorization_code'
    };

    request(configuration.managerUrl)
      .post(configuration.oAuthEndpoint)
      .type('form')
      .send(body)
      .expect(200)
      .end(function(err, res) {
        if(err) {
          return cb(err);
        }
        if(!res.body || !res.body.access_token) {
          return cb(new Error('Expected response to contain `access_token`, got ' + res.body));
        }

        cb(err, res.body.access_token);
      });
  };

  /**
   * Request the manager (manager.anyfetch.com) to obtain the list
   * of all available providers.
   * @param {boolean} [trusted] Restrict to trusted providers only. Defaults to false.
   * @param {boolean} [featured] Restrict to featured providers only. Defaults to false.
   */
  AnyFetch.getAvailableProviders = function(trusted, featured, cb) {
    // Ommit `trusted` and `featured`
    if(!cb && (!featured && featured !== false)) {
      cb = trusted;
      trusted = false;
      featured = false;
    }
    // Ommit `featured`
    else if(!cb) {
      cb = featured;
      featured = false;
    }

    request(configuration.managerUrl)
      .get('/marketplace.json')
      .query({ trusted: trusted, featured: featured })
      .expect(200)
      .end(cb);
  };

  return AnyFetch;
};

{'fraction_non_alphanumeric': 0.12034799420009666, 'fraction_numerical': 0.0021749637506041568, 'mean_word_length': 2.861007462686567, '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': '6292783', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1259, 'n_words': 330}