 moment = require('moment')
 
 pagerDutyUsers = {}
-pagerDutyUsername    = process.env.HUBOT_PAGERDUTY_USERNAME
-pagerDutyPassword    = process.env.HUBOT_PAGERDUTY_PASSWORD
-pagerDutySubdomain   = process.env.HUBOT_PAGERDUTY_SUBDOMAIN
-pagerDutyBaseUrl     = "https://#{pagerDutySubdomain}.pagerduty.com/api/v1"
-pagerDutyApiKey      = process.env.HUBOT_PAGERDUTY_APIKEY
-pagerDutyScheduleId  = process.env.HUBOT_PAGERDUTY_SCHEDULE_ID
+pagerDutyApiKey        = process.env.HUBOT_PAGERDUTY_API_KEY
+pagerDutySubdomain     = process.env.HUBOT_PAGERDUTY_SUBDOMAIN
+pagerDutyBaseUrl       = "https://#{pagerDutySubdomain}.pagerduty.com/api/v1"
+pagerDutyServiceApiKey = process.env.HUBOT_PAGERDUTY_SERVICE_API_KEY
+pagerDutyScheduleId    = process.env.HUBOT_PAGERDUTY_SCHEDULE_ID
 
 module.exports = (robot) ->
   robot.respond /pager( me)?$/i, (msg) ->

      return
  
    json = JSON.stringify(data)
    auth = 'Basic ' + new Buffer(pagerDutyUsername + ':' + pagerDutyPassword).toString('base64')
    msg.http(pagerDutyBaseUrl + url)
      .headers(Authorization: auth, Accept: 'application/json')
      .header("content-type","application/json")

      ""
  
  updateIncident = (msg, incident_number, status) ->
    withPagerDutyUsers msg, (users) ->
      userId = pagerDutyUserId(msg, users)
      return unless userId

      pagerDutyIncidents msg, (incidents) ->
        foundIncidents = []
        for incident in incidents
          if "#{incident.incident_number}" == incident_number
            foundIncidents = [ incident ]
            # loljson
            data = {
              requester_id: userId
              incidents: [
                {
                  'id':     incident.id,
                  'status': status
                }
              ]
            }
            pagerDutyPut msg, "/incidents", data, (json) ->
              if incident = json.incidents[0]
                msg.reply "Incident #{incident.incident_number} #{incident.status}."
              else
                msg.reply "Problem updating incident #{incident_number}"
        if foundIncidents.length == 0
          msg.reply "Couldn't find incident #{incident_number}"
  
  
  pagerDutyIntergrationPost = (msg, json, cb) ->
    msg.http('https://events.pagerduty.com/generic/2010-04-15/create_event.json')
      .header("content-type","application/json")
      .header("content-length", json.length)
      .post(json) (err, res, body) ->
        switch res.statusCode
          when 200
