   request: (method, path, body, callback) ->
     self = @
 
-    #console.log method, path, body
-    host = @options.team + '.slack.com'
-    headers = "Host": host
-
-    path += "?token=" + @options.token
-
-    req_options =
-      "agent"  : false
-      "hostname"   : host
-      "port"   : 443
-      "path"   : path
-      "method" : method
-      "headers": headers
+    host = "#{@options.team}.slack.com"
+    headers =
+      Host: host
+
+    path += "?token=#{@options.token}"
+
+    reqOptions =
+      agent    : false
+      hostname : host
+      port     : 443
+      path     : path
+      method   : method
+      headers  : headers
 
     if method is "POST"
-      headers["Content-Type"] = "application/x-www-form-urlencoded"
-      req_options.headers["Content-Length"] = body.length
-
-    request = HTTPS.request req_options, (response) ->
+      reqOptions.headers["Content-Type"] = "application/x-www-form-urlencoded"
+      reqOptions.headers["Content-Length"] = body.length
+
+    request = https.request reqOptions, (response) ->
       data = ""
       response.on "data", (chunk) ->
         data += chunk

          self.logError data

        #console.log "HTTPS response:", data
        if callback
          callback null, data

        response.on "error", (err) ->
          self.logError "HTTPS response error:", err
          if callback
            callback err, null

    if method is "POST"
      request.end(body, 'binary')
    else
      request.end()

    request.on "error", (err) ->
      self.logError "HTTPS request error:", err
      self.logError err.stack
      if callback
        callback err

exports.use = (robot) ->
  new Slack robot

{Robot, Adapter, TextMessage} = require 'hubot'
https = require 'https'

class Slack extends Adapter
  ###################################################################
  # Slightly abstract logging, primarily so that it can
  # be easily altered for unit tests.
  ###################################################################
  log: console.log.bind console
  logError: console.error.bind console


  ###################################################################
  # Communicating back to the chat rooms. These are exposed
  # as methods on the argument passed to callbacks from
  # robot.respond, robot.listen, etc.
  ###################################################################
  send: (params, strings...) ->
    @log "Sending message"
    user = @userFromParams params

    strings.forEach (str) =>
      str = @escapeHtml str
      args = JSON.stringify
        username : @robot.name
        channel  : user.reply_to
        text     : str

      @post "/services/hooks/hubot", args

  reply: (params, strings...) ->
    @log "Sending reply"

    user = @userFromParams params
    strings.forEach (str) =>
      @send params, "#{user.name}: #{str}"

  topic: (params, strings...) ->
    # TODO: Set the topic


  ###################################################################
  # HTML helpers.
  ###################################################################
  escapeHtml: (string) ->
    string
      # Escape entities
