<commit_before>'use strict';

const request = require('request');
const fs = require('fs');


function SpeechmaticsError(obj) {
  Error.captureStackTrace(this, this.constructor);
  Object.assign(this, obj);
  this.name = this.constructor.name;
  this.statusCode = obj.code;
  this.message = obj.error;
}
require('util').inherits(SpeechmaticsError, Error);


class Client {
  constructor(userId, apiToken, opts) {
    if (!userId) throw new Error('API User ID required');
    if (!apiToken) throw new Error('API Auth Token required');
    if (!(this instanceof Client)) {
      return new Client(userId, apiToken, opts);
    }

    this.userId = userId;
    this.apiToken = apiToken;

    opts = opts || {};
    this.baseUrl = opts.baseUrl || 'https://api.speechmatics.com';
    this.apiVersion = opts.apiVersion || '1.0';
    this.callbackUrl = opts.callbackUrl;
    this.headers = opts.headers || {};

    return this;
  }

  makeRequest(method, path, opts, done) {
    if (typeof opts === 'function') {
      done = done || opts;
      opts = {};
    }

    path = path.replace(':userId', this.userId);
    const options = Object.assign(opts, {
      method,
      json: true,
      headers: this.headers,
      baseUrl: this.baseUrl,
      url: `/v${this.apiVersion}/${path}`,
    });
    options.qs = options.qs || {};
    options.qs.auth_token = this.apiToken;

    request(options, (err, resp, body) => {
      if (!err && resp.statusCode >= 400) {
        err = new SpeechmaticsError(body);
      }
      if (typeof body === 'object') {
        const keys = Object.keys(body);
        if (keys.length === 1) body = body[keys[0]];
      }
      done(err, body);
    });
  }

  get(path, opts, done) {
    this.makeRequest('GET', path, opts, done);
  }

  post(path, opts, done) {
    opts = opts || {};
    var model = opts.model;
    //default 
    var diarisation = 'false';
    if(opts.diarisation){
        if(opts.diarisation === true){
          diarisation = 'true';
      }
    }
    const fd = Object.assign({
      model: model, //eg 'en-US',
      diarisation: diarisation,
    }, opts.formData);

    delete opts.model;
    delete opts.diarisation;

    if (this.callbackUrl) {
      fd.notification = 'callback';
      fd.callback = this.callbackUrl;
    }

    if (opts.audioFilename) {
      fd.data_file = fs.createReadStream(opts.audioFilename);
      delete opts.audioFilename;
    } else if (opts.audioStream) {
      fd.data_file = opts.audioStream;
      delete opts.audioStream;
    }
    if (opts.textFilename) {
      fd.text_file = fs.createReadStream(opts.textFilename);
      delete opts.textFilename;
    } else if (opts.textStream) {
      fd.text_file = opts.textStream;
      delete opts.textStream;
    }
    opts.formData = fd;

    this.makeRequest('POST', path, opts, done);
  }
<commit_msg>updating with default<commit_after>'use strict';

const request = require('request');
const fs = require('fs');


function SpeechmaticsError(obj) {
  Error.captureStackTrace(this, this.constructor);
  Object.assign(this, obj);
  this.name = this.constructor.name;
  this.statusCode = obj.code;
  this.message = obj.error;
}
require('util').inherits(SpeechmaticsError, Error);


class Client {
  constructor(userId, apiToken, opts) {
    if (!userId) throw new Error('API User ID required');
    if (!apiToken) throw new Error('API Auth Token required');
    if (!(this instanceof Client)) {
      return new Client(userId, apiToken, opts);
    }

    this.userId = userId;
    this.apiToken = apiToken;

    opts = opts || {};
    this.baseUrl = opts.baseUrl || 'https://api.speechmatics.com';
    this.apiVersion = opts.apiVersion || '1.0';
    this.callbackUrl = opts.callbackUrl;
    this.headers = opts.headers || {};

    return this;
  }

  makeRequest(method, path, opts, done) {
    if (typeof opts === 'function') {
      done = done || opts;
      opts = {};
    }

    path = path.replace(':userId', this.userId);
    const options = Object.assign(opts, {
      method,
      json: true,
      headers: this.headers,
      baseUrl: this.baseUrl,
      url: `/v${this.apiVersion}/${path}`,
    });
    options.qs = options.qs || {};
    options.qs.auth_token = this.apiToken;

    request(options, (err, resp, body) => {
      if (!err && resp.statusCode >= 400) {
        err = new SpeechmaticsError(body);
      }
      if (typeof body === 'object') {
        const keys = Object.keys(body);
        if (keys.length === 1) body = body[keys[0]];
      }
      done(err, body);
    });
  }

  get(path, opts, done) {
    this.makeRequest('GET', path, opts, done);
  }

  post(path, opts, done) {
    opts = opts || {};
    //default for language model is english global
    var model = 'en';
     if(opts.model){
      model = opts.model;
     }
    //default for speaker diarization is off
    var diarisation = 'false';
    if(opts.diarisation){
        if(opts.diarisation === true){
          diarisation = 'true';
      }
    }
    const fd = Object.assign({
      model: model, //eg: 'en-US',
      diarisation: diarisation,
    }, opts.formData);
    //clean up model and diarization 
    delete opts.model;
    delete opts.diarisation;

    if (this.callbackUrl) {
      fd.notification = 'callback';
      fd.callback = this.callbackUrl;
    }

    if (opts.audioFilename) {
      fd.data_file = fs.createReadStream(opts.audioFilename);
      delete opts.audioFilename;
    } else if (opts.audioStream) {
      fd.data_file = opts.audioStream;
      delete opts.audioStream;
    }
    if (opts.textFilename) {
      fd.text_file = fs.createReadStream(opts.textFilename);
      delete opts.textFilename;
    } else if (opts.textStream) {
      fd.text_file = opts.textStream;
      delete opts.textStream;
    }
    opts.formData = fd;

    this.makeRequest('POST', path, opts, done);
  }

{'fraction_non_alphanumeric': 0.14694296968659018, 'fraction_numerical': 0.002397670834046926, 'mean_word_length': 2.6250775915580387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5114222', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1845, 'n_words': 426}