       SC._popupWindow = SC.Helper.openCenteredPopup uri.toString(), 456, 510
     else
       throw "Either client_id and redirect_uri (for user agent flow) must be passed as an option"
-    
+
   connectCallback: ->
     popupWindow = SC._popupWindow
     popupLocation = popupWindow.location.toString()

  initialize: (options={}) ->
    this.accessToken(options["access_token"])
    this.options[key] = value for own key, value of options
    this

  hostname: (subdomain) ->

    query ||= {}
    uri = SC.prepareRequestURI(path, query)
    uri.query.format = "json"

    if SC.options.flashXHR
      uri.query["_status_code_map[400]"] = 200
      uri.query["_status_code_map[401]"] = 200
      uri.query["_status_code_map[403]"] = 200
      uri.query["_status_code_map[404]"] = 200
      uri.query["_status_code_map[422]"] = 200
      uri.query["_status_code_map[500]"] = 200
      uri.query["_status_code_map[503]"] = 200
      uri.query["_status_code_map[504]"] = 200

    if method == "PUT" || method == "DELETE"
      uri.query._method = method
      method = "POST"

    if method != "GET"
      data = uri.encodeParams(uri.query)
      uri.query = {}

    handleResponse = (responseText, xhr) ->
      json = SC.Helper.JSON.parse(responseText)
      error = null

      if !json
        if xhr
          error = {message: "HTTP Error: " + xhr.status}
        else
          error = {message: "Unknown error"}
      else if json.errors
        error = { message: json.errors && json.errors[0].error_message }

      callback(json, error)

    if SC.options.flashXHR
      this.whenRecordingReady ->
        Recorder.request method, uri.toString(), data, handleResponse
    else
      this._request method, uri.toString(), data, handleResponse

  _request: (method, uri, data, callback) ->
    request = new XMLHttpRequest();
    request.open(method, uri.toString(), true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    request.onreadystatechange = (e) ->
      if(e.target.readyState == 4)
        callback(e.target.responseText, e.target)
    request.send(data);

  post:   (path, query, callback) ->
    this.request("POST",   path, query, callback)
