fix user notification for v2 api

`notify` parameter is not working as expected for hipchat API v2.
This commit is contained in:
Igor Khomyakov 2015-07-02 14:17:56 +03:00
parent 7717719ed4
commit bbb578ac59

View file

@ -5,7 +5,7 @@ DOCUMENTATION = '''
--- ---
module: hipchat module: hipchat
version_added: "1.2" version_added: "1.2"
short_description: Send a message to hipchat short_description: Send a message to hipchat.
description: description:
- Send a message to hipchat - Send a message to hipchat
options: options:
@ -56,7 +56,7 @@ options:
version_added: 1.5.1 version_added: 1.5.1
api: api:
description: description:
- API url if using a self-hosted hipchat server - API url if using a self-hosted hipchat server. For hipchat api version 2 use C(/v2) path in URI
required: false required: false
default: 'https://api.hipchat.com/v1' default: 'https://api.hipchat.com/v1'
version_added: 1.6.0 version_added: 1.6.0
@ -67,7 +67,15 @@ author: "WAKAYAMA Shirou (@shirou), BOURDEL Paul (@pb8226)"
''' '''
EXAMPLES = ''' EXAMPLES = '''
- hipchat: token=AAAAAA room=notify msg="Ansible task finished" - hipchat: room=notify msg="Ansible task finished"
# Use Hipchat API version 2
- hipchat:
api: "https://api.hipchat.com/v2/"
token: OAUTH2_TOKEN
room: notify
msg: "Ansible task finished"
''' '''
# =========================================== # ===========================================
@ -80,7 +88,6 @@ DEFAULT_URI = "https://api.hipchat.com/v1"
MSG_URI_V1 = "/rooms/message" MSG_URI_V1 = "/rooms/message"
MSG_URI_V2 = "/room/{id_or_name}/message"
NOTIFY_URI_V2 = "/room/{id_or_name}/notification" NOTIFY_URI_V2 = "/room/{id_or_name}/notification"
def send_msg_v1(module, token, room, msg_from, msg, msg_format='text', def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
@ -95,11 +102,7 @@ def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
params['message_format'] = msg_format params['message_format'] = msg_format
params['color'] = color params['color'] = color
params['api'] = api params['api'] = api
params['notify'] = int(notify)
if notify:
params['notify'] = 1
else:
params['notify'] = 0
url = api + MSG_URI_V1 + "?auth_token=%s" % (token) url = api + MSG_URI_V1 + "?auth_token=%s" % (token)
data = urllib.urlencode(params) data = urllib.urlencode(params)
@ -116,7 +119,7 @@ def send_msg_v1(module, token, room, msg_from, msg, msg_format='text',
def send_msg_v2(module, token, room, msg_from, msg, msg_format='text', def send_msg_v2(module, token, room, msg_from, msg, msg_format='text',
color='yellow', notify=False, api=MSG_URI_V2): color='yellow', notify=False, api=NOTIFY_URI_V2):
'''sending message to hipchat v2 server''' '''sending message to hipchat v2 server'''
print "Sending message to v2 server" print "Sending message to v2 server"
@ -126,13 +129,11 @@ def send_msg_v2(module, token, room, msg_from, msg, msg_format='text',
body['message'] = msg body['message'] = msg
body['color'] = color body['color'] = color
body['message_format'] = msg_format body['message_format'] = msg_format
params['notify'] = notify
if notify:
POST_URL = api + NOTIFY_URI_V2 POST_URL = api + NOTIFY_URI_V2
else:
POST_URL = api + MSG_URI_V2
url = POST_URL.replace('{id_or_name}',room) url = POST_URL.replace('{id_or_name}', room)
data = json.dumps(body) data = json.dumps(body)
if module.check_mode: if module.check_mode: