   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

Robot   = require('hubot').Robot
Adapter = require('hubot').Adapter
TextMessage = require('hubot').TextMessage
HTTPS = require 'https'

class Slack extends Adapter
  log: console.log.bind console
  logError: console.error.bind console

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

    user = @userFromParams(params)

    strings.forEach (str) =>
      str = @escapeHtml str

      args = JSON.stringify({"channel": user.reply_to, "text": str, username: @robot.name})
      @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

  escapeHtml: (string) ->
    string
      # Escape entities

    @log "Successfully 'connected' as", self.robot.name
    self.emit "connected"


  ###################################################################
  # Convenience HTTP Methods for sending data back to slack.
  ###################################################################
  get: (path, callback) ->
    @request "GET", path, null, callback

