# -*- coding: utf-8 -*-

"""
km-hipchat-screamer.annoy
~~~~~~~~~~~~~~~~~~~~~~~

Module providing test routes for the KISSmetrics HipChat Webhook service
"""


from flask import Blueprint, jsonify
import os
import hipchat


ANNOY_HIPCHAT_TOKEN = os.environ.get('ANNOY_HIPCHAT_TOKEN')

annoy = Blueprint('annoy', __name__)

#-------
# Routes
#-------

if ANNOY_HIPCHAT_TOKEN:
    @annoy.route('/annoy/<channel>')
    def annoy_route(channel):
        """Spam a particular room"""
    
    
        hipchat_api = hipchat.HipChat(token=ANNOY_HIPCHAT_TOKEN)
        hipchat_api.message_room(channel, 'Screamer', 'test', notify=True)
    
        body = { "action": "message sent" }
    
        return jsonify(body)
else:
    print "ANNOY_HIPCHAT_TOKEN not supplied, annoy routes disabled"

@@ -189,16 +189,44 @@
 jsonify%0A
+from utils import env_check%0A
 import o
@@ -375,36 +375,8 @@
 --%0A%0A
-if ANNOY_HIPCHAT_TOKEN:%0A    
 @ann
@@ -404,20 +404,50 @@
 nnel%3E')%0A
-    
+@env_check('ANNOY_HIPCHAT_TOKEN')%0A
 def anno
@@ -464,20 +464,16 @@
 annel):%0A
-    
     %22%22%22S
@@ -501,22 +501,10 @@
 %22%22%22%0A
-    %0A    %0A    
+%0A%0A
     
@@ -564,20 +564,16 @@
 EN)%0A    
- 
-   
 hipchat_
@@ -631,25 +631,17 @@
 y=True)%0A
-    %0A    
+%0A
     body
@@ -676,21 +676,13 @@
 %22 %7D%0A
-    %0A 
+%0A
     
-   
 retu
@@ -702,78 +702,4 @@
 dy)%0A
-else:%0A    print %22ANNOY_HIPCHAT_TOKEN not supplied, annoy routes disabled%22%0A

update annoy example route to use env_check decorator