
var extend = require('extend')
var api = require('@request/api')
var _methods = require('../config/methods')


module.exports = (ctor, config, request) => {

  if (ctor.api === 'basic') {
    return api({
      type: 'basic',
      define: {
        request: request
      }
    })
  }

  var define = {
    alias: (options, name) => {
      options.alias = name
    },
    auth: (options, arg1, arg2) => {
      var alias = (options.alias || ctor.alias || '__default')
      config.endpoint.auth(alias, options, arg1, arg2)
    },
    options: (options, opts) => {
      extend(true, options, opts)
    },
    request: (options, callback) => {
      if (callback) {
        options.callback = callback
      }
      return request(options)
    }
  }

  ctor.methods = ctor.methods || {}

  var custom = {}
  extend(custom, define, ctor.methods.define)
  delete ctor.methods.define

  var methods = {}
  extend(true, methods, _methods, ctor.methods)

  return api({
    type: 'chain',
    config: methods,
    define: custom
  })
}


var extend = require('extend')
var api = require('@request/api')
var _methods = require('../config/methods')


module.exports = (ctor, config, request) => {

  if (ctor.api === 'basic') {
    return api({
      type: 'basic',
      define: {
        request: request
      }
    })
  }

  var define = {
    alias: (options, name) => {
      options.alias = name
    },
    auth: (options, arg1, arg2) => {
      var alias = (options.alias || ctor.alias || '__default')
      config.endpoint.auth(alias, options, arg1, arg2)
    },
    oauth: (options, opts) => {
      options.oauth = opts
    },
    options: (options, opts) => {
      extend(true, options, opts)
    },
    request: (options, callback) => {
      if (callback) {
        options.callback = callback
      }
      return request(options)
    }
  }

  ctor.methods = ctor.methods || {}

  var custom = {}
  extend(custom, define, ctor.methods.define)
  delete ctor.methods.define

  var methods = {}
  extend(true, methods, _methods, ctor.methods)

  return api({
    type: 'chain',
    config: methods,
    define: custom
  })
}

Add custom oauth method