 
 querystring = require('querystring')
 _ = require('lodash')
-request = require('request')
+Promise = require('bluebird')
+request = Promise.promisify(require('request'))
 LANGUAGES = require('./data/languages.json')
 TRANSLATE_URI = 'https://translate.yandex.net/api/v1.5/tr.json/translate'
 API_KEY = process.env.YANDEX_TRANSLATE_API_KEY
 LOCAL_LANGUAGE = process.env.HUBOT_GARBLE_LOCAL_LANGUAGE || 'en'
-SHOW_TRANSLATION_PATH = process.env.HUBOT_GARBLE_TRANSLATION_PATH_LOG || true
+DISPLAY_TRANSLATION_PATH = process.env.HUBOT_GARBLE_TRANSLATION_PATH_LOG || true
 DEFAULT_GARBLE_AMOUNT = 5
 
 # get full language name from a language code


    langs = getTranslationPath(garbleAmount)

    if text?.length

      request getRequestURI(langs[0], langs[1], text), (error, response, body) ->
        request getRequestURI(langs[1], langs[2], parseResponse(body)), (error, response, body) ->
          request getRequestURI(langs[2], langs[3], parseResponse(body)), (error, response, body) ->
            request getRequestURI(langs[3], langs[4], parseResponse(body)), (error, response, body) ->
              request getRequestURI(langs[4], langs[5], parseResponse(body)), (error, response, body) ->
                request getRequestURI(langs[5], langs[6], parseResponse(body)), (error, response, body) ->
                  msg.send parseResponse(body)
                  unless SHOW_TRANSLATION_PATH == 'false'
                    msg.send getTranslationPathLog(langs)

    text: text
  return "#{TRANSLATE_URI}?#{querystring.stringify(opts)}"

# returns request promise
getTranslation = (fromLang, toLang, text) ->
  request getRequestURI(fromLang, toLang, text)

# a string of translated text
parseResponse = (str) ->
  try
    return JSON.parse(str).text[0]
  catch e
    return str

module.exports = (robot) ->

