 #   Given: https://rpm.newrelic.com/accounts/xxx/applications/yyy
 #     xxx is your Account ID and yyy is your App ID
 #   Account Settings > API + Web Integrations > API Access > "API key"
-# 
+#
 # Author:
 #   briandoll
 
 module.exports = (robot) ->
-  robot.respond /newrelic me/i, (msg) ->
-    accountId = process.env.HUBOT_NEWRELIC_ACCOUNT_ID
-    appId     = process.env.HUBOT_NEWRELIC_APP_ID
-    apiKey    = process.env.HUBOT_NEWRELIC_API_KEY
-    Parser = require("xml2js").Parser
-    
+  fetchData = (appId) ->
     msg.http("https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}/threshold_values?api_key=#{apiKey}")
       .get() (err, res, body) ->
         if err

          threshold_values = json['threshold-values']['threshold_value'] || []
          lines = threshold_values.map (threshold_value) ->
            "#{threshold_value['$']['name']}: #{threshold_value['$']['formatted_metric_value']}"
             
          msg.send lines.join("\n"), "https://rpm.newrelic.com/accounts/#{accountId}/applications/#{appId}"

#   HUBOT_NEWRELIC_ACCOUNT_ID
#   HUBOT_NEWRELIC_APP_ID
#   HUBOT_NEWRELIC_API_KEY
#
# Commands:
#   hubot newrelic me - Returns summary application stats from New Relic
#
