
function API (config, custom) {
  this.options = {}

  var api = {}

  var wrap = {
    method: (key) => ((url) => {
      this.options.method = key.toUpperCase()
      this.options.url = url || ''
      return api
    }),
    option: (key) => ((value) => {
      this.options[key] = value
      return api
    }),
    custom: (key) => custom[key].bind(api, this.options)
  }

  Object.keys(config).forEach((type) => {
    Object.keys(config[type]).forEach((method) => {
      api[method] = wrap[type](method)

      config[type][method].forEach((alias) => {
        api[alias] = wrap[type](method)
      })
    })
  })

  return api
}

module.exports = (config, custom) => {
  return new API(config, custom)
}


module.exports = (config, custom) => {

  var wrap = {
    method: function (key) {
      return (value) => {
        if (!this._options) {
          var api = init()
          api._options = {}
          return api[key](value)
        }
        this._options.method = key.toUpperCase()
        this._options.url = value || ''
        return this
      }
    },
    option: function (key) {
      return (value) => {
        if (!this._options) {
          var api = init()
          api._options = {}
          return api[key](value)
        }
        this._options[key] = value
        return this
      }
    },
    custom: function (key) {
      return function () {
        if (!this._options) {
          var api = init()
          api._options = {}
          return custom[key].apply(api, arguments)
        }
        return custom[key].apply(this, arguments)
      }.bind(this)
    }
  }

  function init () {
    var api = {}

    Object.keys(config).forEach((type) => {
      Object.keys(config[type]).forEach((method) => {
        api[method] = wrap[type].call(api, method)

        config[type][method].forEach((alias) => {
          api[alias] = wrap[type].call(api, method)
        })
      })
    })

    return api
  }

  return init()
}

Allow options initialization from any method
Allow options initialization from any method
