<commit_before>import assign  from 'object-assign';
import querify from './querify';

let fetch = () => {
  throw new ReferenceError('fetch is not defined');
};

if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
  fetch = window.fetch;
}

class EasyAgent {
  constructor(url, options = {}) {
    this.url         = url;
    this.method      = options.method || 'GET';
    this.queries     = options.queries || {};
    this.headers     = options.headers || {};
    this.body        = options.body || null;
    this.credentials = options.credentials;
    this.chache      = options.chache;
  }

  __setOptions(options) {
    return new EasyAgent(this.url, assign({}, Object(this), options));
  }

  setUrl(newUrl) {
    return new EasyAgent(newUrl, this.options);
  }

  setMethod(method) {
    return this.__setOptions({ method });
  }

  setHeaders(headers) {
    return this.__setOptions({ headers: assign({}, this.headers, headers) });
  }

  setQueries(queries) {
    return this.__setOptions({ queries: assign({}, this.queries, queries) });
  }

  setBody(body) {
    return this.__setOptions({ body });
  }

  setJson(json) {
    return this.__setOptions({
      body:    JSON.stringify(json),
      headers: assign({}, this.headers, {
        'Content-Type': 'application/json',
      }),
    });
  }

  setForm(form) {
    return this.__setOptions({
      body:    form,
      headers: assign({}, this.headers, {
        'Content-Type': 'application/x-www-form-urlencoded',
      }),
    });
  }

  fetch() {
    const querified = querify(this.queries);

    return fetch(this.url + querified, {
      method:  this.method,
      headers: this.headers,
      body:    this.body,
    });
  }

  fetchJson() {
    return this
      .setHeaders({ Accept: 'application/json' })
      .fetch()
      .then(res => res.json());
  }
<commit_msg>Bugfix: not supported credentials<commit_after>import assign  from 'object-assign';
import querify from './querify';

let fetch = () => {
  throw new ReferenceError('fetch is not defined');
};

if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
  fetch = window.fetch;
}

class EasyAgent {
  constructor(url, options = {}) {
    this.url         = url;
    this.method      = options.method || 'GET';
    this.queries     = options.queries || {};
    this.headers     = options.headers || {};
    this.body        = options.body || null;
    this.credentials = options.credentials;
    this.chache      = options.chache;
  }

  __setOptions(options) {
    return new EasyAgent(this.url, assign({}, Object(this), options));
  }

  setUrl(newUrl) {
    return new EasyAgent(newUrl, this.options);
  }

  setMethod(method) {
    return this.__setOptions({ method });
  }

  setHeaders(headers) {
    return this.__setOptions({ headers: assign({}, this.headers, headers) });
  }

  setQueries(queries) {
    return this.__setOptions({ queries: assign({}, this.queries, queries) });
  }

  setBody(body) {
    return this.__setOptions({ body });
  }

  setJson(json) {
    return this.__setOptions({
      body:    JSON.stringify(json),
      headers: assign({}, this.headers, {
        'Content-Type': 'application/json',
      }),
    });
  }

  setForm(form) {
    return this.__setOptions({
      body:    form,
      headers: assign({}, this.headers, {
        'Content-Type': 'application/x-www-form-urlencoded',
      }),
    });
  }

  fetch() {
    const querified = querify(this.queries);

    return fetch(this.url + querified, {
      method:      this.method,
      headers:     this.headers,
      body:        this.body,
      credentials: this.credentials,
      cache:       this.cache,
    });
  }

  fetchJson() {
    return this
      .setHeaders({ Accept: 'application/json' })
      .fetch()
      .then(res => res.json());
  }

{'fraction_non_alphanumeric': 0.15607087024491922, 'fraction_numerical': 0.0, 'mean_word_length': 2.6080827067669174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6154834', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1187, 'n_words': 249}