<commit_before>import {Http} from './http';
import {RestResource} from './restResource';
import assign from 'lodash/object/assign';

export class RestClient {

  constructor(baseUrl, config = {}) {
    this._baseUrl = baseUrl;
    this._config = config;
    this._interceptors = config.interceptors || [];
    this._headers = config.headers || {};
    this._http = config.http || null;
    this._cache = {};
  }

  set baseUrl(baseUrl) {
    this._baseUrl = baseUrl;
  }

  addHeader(field, val) {
    this._headers[field] = val;
  }

  set http(http) {
    this._http = http;
  }

  addInterceptor(interceptor, onEnd = true) {
    if (onEnd) {
      this._interceptors.push(interceptor);
    } else {
       this._interceptors.unshift(interceptor);
    }
  }

  resource(resourceName, config = {}) {
    if (!this._cache[resourceName]) {
      let conf = assign({}, this._config);
      conf.http = config.http || null;
      conf.defaultHeaders = assign({}, this._headers, config.defaultHeaders || {});
      conf.interceptors = (config.interceptors || []).concat(this._interceptors);
      if (!conf.http) {
        conf.http = this._http;
      }

      this._cache[resourceName] = new RestResource(this._baseUrl, resourceName , conf);
    }

    return this._cache[resourceName];
  }
}<commit_msg>decomposition<commit_after>import {Http} from './http';
import {RestResource} from './restResource';
import assign from 'lodash/object/assign';

export class RestClient {

  constructor(baseUrl, config = {}) {
    this._baseUrl = baseUrl;
    this._config = config;
    this._interceptors = config.interceptors || [];
    this._headers = config.headers || {};
    this._http = config.http || null;
    this._cache = {};
  }

  set baseUrl(baseUrl) {
    this._baseUrl = baseUrl;
  }

  addHeader(field, val) {
    this._headers[field] = val;
  }

  set http(http) {
    this._http = http;
  }

  addInterceptor(interceptor, onEnd = true) {
    if (onEnd) {
      this._interceptors.push(interceptor);
    } else {
       this._interceptors.unshift(interceptor);
    }
  }

  instanciateResource(resourceName, conf) {
   return new RestResource(this._baseUrl, resourceName , conf);
  }

  resource(resourceName, config = {}) {
    if (!this._cache[resourceName]) {
      let conf = assign({}, this._config);
      conf.http = config.http || null;
      conf.defaultHeaders = assign({}, this._headers, config.defaultHeaders || {});
      conf.interceptors = (config.interceptors || []).concat(this._interceptors);
      if (!conf.http) {
        conf.http = this._http;
      }

      this._cache[resourceName] = this.instanciateResource(resourceName , conf);
    }

    return this._cache[resourceName];
  }
}
{'fraction_non_alphanumeric': 0.14686346863468636, 'fraction_numerical': 0.0, 'mean_word_length': 3.058383233532934, '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': '3802404', 'n_tokens_mistral': 873, 'n_tokens_neox': 843, 'n_words': 161}