<commit_before>
var request = require('request')
try {
  var debug = require('request-debug')
} catch (e) {
  var debug = function () {}
}

var utils = require('./utils')
  , config = require('./config')
  , Query = require('./query')
  , Url = require('./url')
var Options = require('./options').Options
  , Before = require('./options').Before
var providers = require('../config/providers')
  , override = require('../config/override')


function Provider (options) {
  if (!options || !options.provider)
    throw new Error('Purest: provider option is required!')

  config.extend(providers, options.config)
  var provider = providers[options.provider]
  if (!provider) {
    throw new Error('Purest: non existing provider!')
  }

  this.key = options.consumerKey||options.key||null
  this.secret = options.consumerSecret||options.secret||null
  if (provider.__provider) {
    this.oauth = provider.__provider.oauth
    this.oauth2 = provider.__provider.oauth2
  }

  this._request = request.defaults(options.defaults||{})
  options.debug && debug(this._request)
  // url modifiers
  this.domain = options.domain||''
  this.path = options.path||''
  this.version = options.version||''
  this.type = options.type||'json'

  this.apis = config.aliases(provider)||null
  if (options.api && (!this.apis || !this.apis[options.api])) {
    throw new Error('Purest: non existing API!')
  }
  this.api = options.api||'__default'

  this.name = options.provider
  this[options.provider] = true

  this.options = new Options(this)
  this.before = new Before(this)
  this.url = new Url(this)
  // override
  if (override[this.name]) {
    override[this.name].call(this)
  }
}

function prepare (method, uri, options, callback) {
  var params = request.initParams(uri, options, callback)
  var endpoint = params.uri,
    options = params,
    callback = params.callback

  options.method = options.method||(method=='del'?'delete':method).toUpperCase()
  if (method != 'put') {
    options.json = (options.json == undefined) ? true : options.json
  }

  this.oauth && options.oauth && this.options.oauth(options)
  options = config.options(endpoint, options, method, this.apis[options.api||this.api].endpoints)
  this.before.all(endpoint, options)
  this.before[method](endpoint, options)

  return this._request(
    endpoint.indexOf('http') == -1 ? this.url.get(endpoint, options) : endpoint,
    options,
    callback && utils.response(callback))
}

Provider.prototype.get = function (uri, options, callback) {
  return prepare.call(this, 'get', uri, options, callback)
}

Provider.prototype.post = function (uri, options, callback) {
  return prepare.call(this, 'post', uri, options, callback)
}

Provider.prototype.put = function (uri, options, callback) {
  return prepare.call(this, 'put', uri, options, callback)
}

Provider.prototype.del = function (uri, options, callback) {
  return prepare.call(this, 'del', uri, options, callback)
}

Provider.prototype.patch = function (uri, options, callback) {
  return prepare.call(this, 'patch', uri, options, callback)
}

Provider.prototype.head = function (uri, options, callback) {
  return prepare.call(this, 'head', uri, options, callback)
}


Provider.prototype.config = function (name) {
  return new Query(this, name)
}

Provider.prototype.query = function (name) {
  return new Query(this, name)
}

Provider.request = request
exports = module.exports = Provider
<commit_msg>Add override option in ctor<commit_after>
var request = require('request')
try {
  var debug = require('request-debug')
} catch (e) {
  var debug = function () {}
}

var utils = require('./utils')
  , config = require('./config')
  , Query = require('./query')
  , Url = require('./url')
var Options = require('./options').Options
  , Before = require('./options').Before
var providers = require('../config/providers')
  , override = require('../config/override')


function Provider (options) {
  if (!options || !options.provider)
    throw new Error('Purest: provider option is required!')

  config.extend(providers, options.config)
  var provider = providers[options.provider]
  if (!provider) {
    throw new Error('Purest: non existing provider!')
  }

  this.key = options.consumerKey||options.key||null
  this.secret = options.consumerSecret||options.secret||null
  if (provider.__provider) {
    this.oauth = provider.__provider.oauth
    this.oauth2 = provider.__provider.oauth2
  }

  this._request = request.defaults(options.defaults||{})
  options.debug && debug(this._request)
  // url modifiers
  this.domain = options.domain||''
  this.path = options.path||''
  this.version = options.version||''
  this.type = options.type||'json'

  this.apis = config.aliases(provider)||null
  if (options.api && (!this.apis || !this.apis[options.api])) {
    throw new Error('Purest: non existing API!')
  }
  this.api = options.api||'__default'

  this.name = options.provider
  this[options.provider] = true

  this.options = new Options(this)
  this.before = new Before(this)
  this.url = new Url(this)
  // override
  if (override[this.name]) {
    override[this.name].call(this)
  }
  if (options.override) {
    options.override.call(this)
  }
}

function prepare (method, uri, options, callback) {
  var params = request.initParams(uri, options, callback)
  var endpoint = params.uri,
    options = params,
    callback = params.callback

  options.method = options.method||(method=='del'?'delete':method).toUpperCase()
  if (method != 'put') {
    options.json = (options.json == undefined) ? true : options.json
  }

  this.oauth && options.oauth && this.options.oauth(options)
  options = config.options(endpoint, options, method, this.apis[options.api||this.api].endpoints)
  this.before.all(endpoint, options)
  this.before[method](endpoint, options)

  return this._request(
    endpoint.indexOf('http') == -1 ? this.url.get(endpoint, options) : endpoint,
    options,
    callback && utils.response(callback))
}

Provider.prototype.get = function (uri, options, callback) {
  return prepare.call(this, 'get', uri, options, callback)
}

Provider.prototype.post = function (uri, options, callback) {
  return prepare.call(this, 'post', uri, options, callback)
}

Provider.prototype.put = function (uri, options, callback) {
  return prepare.call(this, 'put', uri, options, callback)
}

Provider.prototype.del = function (uri, options, callback) {
  return prepare.call(this, 'del', uri, options, callback)
}

Provider.prototype.patch = function (uri, options, callback) {
  return prepare.call(this, 'patch', uri, options, callback)
}

Provider.prototype.head = function (uri, options, callback) {
  return prepare.call(this, 'head', uri, options, callback)
}


Provider.prototype.config = function (name) {
  return new Query(this, name)
}

Provider.prototype.query = function (name) {
  return new Query(this, name)
}

Provider.request = request
exports = module.exports = Provider

{'fraction_non_alphanumeric': 0.15323512420566146, 'fraction_numerical': 0.0008665511265164644, 'mean_word_length': 4.218538055764883, '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': '4961582', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2101, 'n_words': 503}