 Promise             = require('es6-promise').Promise
 assign              = require '../polyfills/assign'
 _                   = require '../utils/lodash'
+cookies             = require '../utils/cookies'
+Base64              = require '../utils/base64'
 logger              = require '../utils/logger'
 EventBus            = require '../utils/eventbus'
 clone               = require '../utils/clone'

class Gateway

  constructor: (config={}) ->
    {batching, appId} = config
    @options = _.defaults({},batching,{min:1,max:1,delay:2})
    @queue = batchable @options.delay, (requests) -> @flush(requests)


  fetch : (options={}) =>
    {method, headers, path, params} = options

    method = (method||'get').toUpperCase()

    headers = assign({}, RemoteHeaderStore.getState(), headers)

    #TODO Check SuperAgent under IE8 and below
    s = superagent(method, path).set(headers)

  timeout = null
  args = []

  ->
    args.push Array::slice.call(arguments)
    clearTimeout timeout
    delayed = =>
