<commit_before>var _ = require('./lodash-local')                               // import _ from 'lodash'

var method_types = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
var allowed_auth = ['', 'basic', 'bearer', 'oauth2']

function toBase64(str) {
  try { return btoa(unescape(encodeURIComponent(str))) } catch(e) { return '' }
}

function fromBase64(str) {
  try { return decodeURIComponent(escape(atob(str))) } catch(e) { return '' }
}


module.exports = {}
module.exports.getConnectionConstructor = function(Flexio) {

return function() {

  if (!(this instanceof Flexio.connection)) {
    return new Flexio.connection
  }

  var retval = _.assign(this, {
    // -- state --

    connection: {
      name: 'Untitled',
      description: '',
      connection_type: "http", // defaults to http
      connection_info: {
        method: '',        // request method
        url: '',           // base url for all calls that will use this connection
        auth: '',          // ``, `basic`, `bearer`, `oauth2`
        username: '',      // `basic auth` only
        password: '',      // `<PASSWORD>` only
        token: '',         // `bearer token` only
        access_token: '',  // `oauth2` only
        refresh_token: '', // `oauth2` only
        expires: '',       // `oauth2` only
        data: {},          // form data for POST
        headers: {}        // custom request headers
      }
    },
    loading: false,
    saving: false,
    running: false,

    // -- methods --

    getJSON() {
      return _.assign({}, this.connection)
    },

    name(value) {
      this.connection.name = value
      return this
    },

    description(value) {
      this.connection.description = value
      return this
    },

    method() {
      var args = Array.from(arguments)
      var method = _.get(args, '[0]')

      if (!_.isString(method))
        return this

      if (!_.includes(method_types, method))
        return this

      return this._setInfo('method', method)
    },

    url() {
      var args = Array.from(arguments)
      var url = _.get(args, '[0]')

      if (!_.isString(url))
        return this

      return this._setInfo('url', url)
    },

    auth() {
      var args = Array.from(arguments)
      var auth = _.get(args, '[0]')

      if (!_.isString(auth))
        return this

      if (!_.includes(allowed_auth, auth))
        return this

      if (auth == 'none')
        auth = ''

      return this._setInfo('auth', auth)<commit_msg>removed _.includes dependency<commit_after>var _ = require('./lodash-local')                               // import _ from 'lodash'

var method_types = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']
var allowed_auth = ['', 'basic', 'bearer', 'oauth2']

function toBase64(str) {
  try { return btoa(unescape(encodeURIComponent(str))) } catch(e) { return '' }
}

function fromBase64(str) {
  try { return decodeURIComponent(escape(atob(str))) } catch(e) { return '' }
}


module.exports = {}
module.exports.getConnectionConstructor = function(Flexio) {

return function() {

  if (!(this instanceof Flexio.connection)) {
    return new Flexio.connection
  }

  var retval = _.assign(this, {
    // -- state --

    connection: {
      name: 'Untitled',
      description: '',
      connection_type: "http", // defaults to http
      connection_info: {
        method: '',        // request method
        url: '',           // base url for all calls that will use this connection
        auth: '',          // ``, `basic`, `bearer`, `oauth2`
        username: '',      // `basic auth` only
        password: '',      // `basic auth` only
        token: '',         // `bearer token` only
        access_token: '',  // `oauth2` only
        refresh_token: '', // `oauth2` only
        expires: '',       // `oauth2` only
        data: {},          // form data for POST
        headers: {}        // custom request headers
      }
    },
    loading: false,
    saving: false,
    running: false,

    // -- methods --

    getJSON() {
      return _.assign({}, this.connection)
    },

    name(value) {
      this.connection.name = value
      return this
    },

    description(value) {
      this.connection.description = value
      return this
    },

    method() {
      var args = Array.from(arguments)
      var method = _.get(args, '[0]')

      if (!_.isString(method))
        throw 'Invalid/empty method'

      if (method_types.indexOf(method) == -1)
        throw 'Invalid method'

      return this._setInfo('method', method)
    },

    url() {
      var args = Array.from(arguments)
      var url = _.get(args, '[0]')

      if (!_.isString(url))
        return this

      return this._setInfo('url', url)
    },

    auth() {
      var args = Array.from(arguments)
      var auth = _.get(args, '[0]')

      if (!_.isString(auth))
        throw 'Invalid/empty auth'

      if (allowed_auth.indexOf(auth) == -1)
        throw 'Invalid auth'

      if (auth == 'none')
        auth = ''

      return this._setInfo('auth', auth)
{'fraction_non_alphanumeric': 0.15386138613861386, 'fraction_numerical': 0.005148514851485149, 'mean_word_length': 2.004759071980964, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1953717', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1492, 'n_words': 378}