       return
     access_token_secret = robot.brain.get("#{user.id}:twitter:access_token_secret_t")
     oauth = new TwitterOAuth({consumer_key:TWITTER_CONSUMER_KEY, consumer_secret_key:TWITTER_CONSUMER_SECERT_KEY, callback:TWITTER_CALLBACK_URL})
-    oauth.verify_oauth access_token, access_token_secret, oauth, (oa)=>
+    oauth.access_token access_token, access_token_secret, oauth, (oa)=>
       robot.brain.set("#{user.id}:twitter:access_token", oa.access_token)
       robot.brain.set("#{user.id}:twitter:access_token_secret", oa.access_token_secret)
-      robot.brain.remove "twitter:#{access_token}" 
+      robot.brain.remove "twitter:#{access_token}"
       robot.brain.remove "#{user.id}:twitter:access_token_t"
       robot.brain.remove "#{user.id}:twitter:access_token_secret_t" 
       draft = robot.brain.get "#{user.id}:twitter:draft"
       if draft?
         room = robot.adapter.client.rtm.dataStore.getDMByName user.name
         robot.reply {room:room.id, user: user}, "I'm posting that tweet: #{draft}"
-
     res.send 'OK'
-    
-    
+   

          st.push "#{kv[0]}=#{encodeURIComponent(kv[1])}"
    st.join(joiner)

  oauth_params: ->
    options = [
      ["oauth_callback", @callback],
      ["oauth_consumer_key" , @consumer_key],
      ["oauth_nonce", @oauth_nonce()],
      ["oauth_signature_method" , "HMAC-SHA1"],
      ["oauth_timestamp" , Math.floor(Date.now() / 1000)],
      ["oauth_version" , "1.0"]
    ]
    options


  extend_list:(obj, sources...) ->
    for source in sources
      for el in source
        obj.push el
    obj
 
  signature: (post_data = [], url='', method = 'POST') ->
    post_data = @sort_options post_data
    post_data = @join_options post_data, '&', false
    sb = "#{method.toUpperCase()}&"+encodeURIComponent(url)
    sb = sb + "&" + encodeURIComponent(post_data)
    if @consumer_secret_key?
      signature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(sb, @consumer_secret_key+"&"))
      signature
    else
      null

  request_access_token: (callback) ->
    oauth_headers = @oauth_params()
    post_data = @extend_list([], oauth_headers)
    sign = @signature(post_data, TwitterOAuth.URL.REQUEST_TOKEN, "POST")
    if sign?
      oauth_headers.push ["oauth_signature", sign]
    oauth_headers = @sort_options oauth_headers
    @oauth_data = @join_options oauth_headers, ", ", true
    @oauth_data = "OAuth #{@oauth_data}"

    options = 
      hostname : TwitterOAuth.URL.BASE_URL
      host : TwitterOAuth.URL.BASE_URL
      port : 443
      path : '/oauth/request_token'
      method : 'POST'
      headers : 
        'Accept' : '*/*'
        'Content-Length' : '0'
        'Content-Type' : 'application/x-www-form-urlencoded'
        'Authorization' : @oauth_data
    options.agent = new https.Agent(options)
    req = https.request options, (res) =>
      res.on 'data', (chunk) ->
        console.log chunk+""
        dt = QUERY_STRING.parse(chunk+"")
        @access_token_secret = dt["oauth_token_secret"]
        @access_token = dt["oauth_token"]
        callback?@, "#{TwitterOAuth.URL.AUTHORIZE}?oauth_token=#{@access_token}"
      res.on 'error', (e) ->
        console.log e.message
    req.end()

  verify_oauth: (@access_token, @access_token_secret, @oauth_verifier, callback) ->
    true
	  
  tweet: (t) ->
    "" 

TWITTER_CONSUMER_KEY = process.env.TWITTER_CONSUMER_KEY
TWITTER_CONSUMER_SECERT_KEY = process.env.TWITTER_CONSUMER_SECERT_KEY

class TwitterOAuth
  @HEX : '0123456789ABCDEF'
  @URL:{
    BASE: "api.twitter.com",
    REQUEST: "https://api.twitter.com/oauth/request_token",
    REQUEST_PATH : "/oauth/request_token",
    ACCESS: "https://api.twitter.com/oauth/access_token",
    ACCESS_PATH: "/oauth/access_token"
    AUTHORIZE: "https://api.twitter.com/oauth/authorize",
    POST_PATH: "/1.1/statuses/update.json",
    POST: "https://api.twitter.com/1.1/statuses/update.json",
  }
  constructor: (@_options={ consumer_key:"", consumer_secret_key:"", callback:"", access_token:"", access_token_secret:"" }) ->
    @consumer_key = @_options["consumer_key"]
