 API_BASE = 'https://api.clever.com'
 CLEVER_BASE = 'https://clever.com'
 
+Promise = Q.Promise
+
 handle_errors = (resp, body, cb) ->
   return cb?(null, resp, body) if resp.statusCode is 200
   err = new Error "received statusCode #{resp.statusCode} instead of 200"


Clever.handle_errors = handle_errors

Clever.me = (token, url_base..., cb) ->
  url_base = url_base[0]
  url_base ?= API_BASE

      # convert stringify nested query params
      opts.qs[key] = JSON.stringify val for key, val of opts.qs when _(val).isObject()
      waterfall = [async.apply quest, opts].concat(@_post.exec or [])
      promise = new Promise (resolve, reject) ->
        async.waterfall waterfall, (err, data) ->
          reject err if err
          resolve data
          return cb?(err) if err
          cb?(err, data)
      return cb if _.isFunction(cb)
      promise

    stream: () => new QueryStream @

