<commit_before>'use strict'

const handleRecurlyError = require('./util').handleRecurlyError

const RecurlyError = require('./recurly-error')
const _ = require('lodash')
const rparser = require('./parser.js')
const debugR = require('debug')('recurring:request')
const debug = require('debug')('recurring')
const pkg = require('../package.json')

const parser = rparser.createParser()

class RecurlyData {
  constructor(options) {
    // Store a reference to the Recurring instance.
    this._recurring = options.recurring

    this.properties = { }
    this._resources = { }

    for (var i = 0; i < options.properties.length; i++) {
      RecurlyData.addProperty(this, options.properties[i])
    }
    this.proplist = options.properties

    this.__defineGetter__('id', function() {
      return this.properties[options.idField]
    })

    var idSetter = function() {
      var newval = arguments['0']
      this.properties[options.idField] = newval
      this.href = this.constructor.ENDPOINT + '/' + newval
    }
    this.__defineSetter__('id', idSetter)
    this.__defineSetter__(options.idField, idSetter)
  }

  static get ENDPOINT() {
    return 'https://api.recurly.com/v2/'
  }

  static addProperty(instance, propname) {
    var getterFunc = function() {
      return this.properties[propname]
    }
    var setterFunc = function() {
      var newval = arguments['0']
      this.properties[propname] = newval
    }

    instance.__defineGetter__(propname, getterFunc)
    instance.__defineSetter__(propname, setterFunc)
  }

  baseOptions() {
    return {
      headers: {
        'Accept': 'application/xml',
        'Authorization': this._recurring.AUTH_BASIC,
        'User-Agent': `${pkg.name}/${pkg.version}`,
        'X-Api-Version': '2.3'
      }
    }
  }

  go(method, uri, args, opts, callback) {
    if (typeof callback === 'undefined' && typeof opts === 'function') {
      callback = opts
      opts = { }
    }

    var options = _.merge(this.baseOptions(), opts)
    options.uri = uri

    if (method === 'GET') {
      options.qs = args
    }
    else {
      options.body = args
    }

    options.method = method

    this.execute(options, callback)
  }

  get(uri, args, opts, callback) {
    this.go('GET', uri, args, opts, callback)
  }

  put(uri, args, opts, callback) {
    this.go('PUT', uri, args, opts, callback)<commit_msg>feat: set X-Api-Version header to 2.4<commit_after>'use strict'

const handleRecurlyError = require('./util').handleRecurlyError

const RecurlyError = require('./recurly-error')
const _ = require('lodash')
const rparser = require('./parser.js')
const debugR = require('debug')('recurring:request')
const debug = require('debug')('recurring')
const pkg = require('../package.json')

const parser = rparser.createParser()

class RecurlyData {
  constructor(options) {
    // Store a reference to the Recurring instance.
    this._recurring = options.recurring

    this.properties = { }
    this._resources = { }

    for (var i = 0; i < options.properties.length; i++) {
      RecurlyData.addProperty(this, options.properties[i])
    }
    this.proplist = options.properties

    this.__defineGetter__('id', function() {
      return this.properties[options.idField]
    })

    var idSetter = function() {
      var newval = arguments['0']
      this.properties[options.idField] = newval
      this.href = this.constructor.ENDPOINT + '/' + newval
    }
    this.__defineSetter__('id', idSetter)
    this.__defineSetter__(options.idField, idSetter)
  }

  static get ENDPOINT() {
    return 'https://api.recurly.com/v2/'
  }

  static addProperty(instance, propname) {
    var getterFunc = function() {
      return this.properties[propname]
    }
    var setterFunc = function() {
      var newval = arguments['0']
      this.properties[propname] = newval
    }

    instance.__defineGetter__(propname, getterFunc)
    instance.__defineSetter__(propname, setterFunc)
  }

  baseOptions() {
    return {
      headers: {
        'Accept': 'application/xml',
        'Authorization': this._recurring.AUTH_BASIC,
        'User-Agent': `${pkg.name}/${pkg.version}`,
        'X-Api-Version': '2.4'
      }
    }
  }

  go(method, uri, args, opts, callback) {
    if (typeof callback === 'undefined' && typeof opts === 'function') {
      callback = opts
      opts = { }
    }

    var options = _.merge(this.baseOptions(), opts)
    options.uri = uri

    if (method === 'GET') {
      options.qs = args
    }
    else {
      options.body = args
    }

    options.method = method

    this.execute(options, callback)
  }

  get(uri, args, opts, callback) {
    this.go('GET', uri, args, opts, callback)
  }

  put(uri, args, opts, callback) {
    this.go('PUT', uri, args, opts, callback)
{'fraction_non_alphanumeric': 0.14406065711878685, 'fraction_numerical': 0.0029486099410278013, 'mean_word_length': 2.941078838174274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1832648', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1483, 'n_words': 316}