<commit_before>/**
 * Low-level client to the ProPublica congress API. Encapsulates behavior
 * common to all API interactions.
 */

const {create, assign} = Object
  , {stringify} = JSON
  , http = require('./http')
  , validators = require('./validators');

const VERSION = '1';
const HOST = 'https://api.propublica.org';

const proto = {
  /**
   * HTTP get to the API
   * @param  {String} endpoint   API endpoint fragment eg. 'members/new'
   * @param  {Number} [offset=0]
   * @return {Promise}
   */
  get(endpoint, offset = 0) {
    if (!validators.isValidOffset(offset)) {
      return Promise.reject(new Error(`Received invalid offset: ${stringify(offset)}`));
    }

    const headers = {['X-API-Key']: this.key};
    const body = offset ? {offset} : {};
    return http.get(
      `${HOST}/congress/v${VERSION}/${endpoint}.json`,
      assign({headers, json: true}, {body})
    // pluck out relevant data from the body probably from having to
    // support xml
    ).then(response => {
      if (!validators.isValidResponse(response)) {
        throw new Error(`Received invalid response structure: ${stringify(response)}`);
      }

      return response.body.results[0];
    });
  }
};

module.exports = {
  /**
   * Factory function for getting client instances
   * @param  {String} key API Key
   * @return {Object}
   */
  create(key) {
    if (!validators.isValidApiKey(key)) {
      throw Error(`Received invalid API key: ${stringify(key)}`);
    }

    return assign(create(proto), {
      key
    });
  }
};
<commit_msg>Updating doc<commit_after>/**
 * Low-level client to the ProPublica congress API. Encapsulates behavior
 * common to all API interactions.
 */

const {create, assign} = Object
  , {stringify} = JSON
  , http = require('./http')
  , validators = require('./validators');

const VERSION = '1';
const HOST = 'https://api.propublica.org';

const proto = {
  /**
   * HTTP get to the API
   * @param  {String} endpoint   API endpoint fragment eg. 'members/new'
   * @param  {Number} [offset=0]
   * @return {Promise}
   */
  get(endpoint, offset = 0) {
    if (!validators.isValidOffset(offset)) {
      return Promise.reject(new Error(`Received invalid offset: ${stringify(offset)}`));
    }

    const headers = {['X-API-Key']: this.key};
    const body = offset ? {offset} : {};
    return http.get(
      `${HOST}/congress/v${VERSION}/${endpoint}.json`,
      assign({headers, json: true}, {body})
    // pluck out relevant data from the body probably from having to
    // support xml
    ).then(response => {
      if (!validators.isValidResponse(response)) {
        throw new Error(`Received invalid response structure: ${stringify(response)}`);
      }

      return response.body.results[0];
    });
  }
};

module.exports = {
  /**
   * Factory function for getting client instances
   * @param  {String} key ProPublica API Key
   * @return {Object}
   */
  create(key) {
    if (!validators.isValidApiKey(key)) {
      throw Error(`Received invalid API key: ${stringify(key)}`);
    }

    return assign(create(proto), {
      key
    });
  }
};

{'fraction_non_alphanumeric': 0.15633074935400518, 'fraction_numerical': 0.002583979328165375, 'mean_word_length': 2.985842985842986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1247709', 'n_tokens_mistral': 938, 'n_tokens_neox': 943, 'n_words': 258}