1
+ // == HTTPBUILDER IMPORTS
2
+ @Grab (group = ' org.codehaus.groovy.modules.http-builder' , module = ' http-builder' , version = ' 0.7.2' )
3
+ import groovyx.net.http.*
4
+ import static groovyx.net.http.ContentType.*
5
+ import static groovyx.net.http.Method.*
6
+
7
+ // == END HTTPBUILDER IMPORTS
8
+
9
+ appUrl = " https://api.hipchat.com/v1/rooms/message"
10
+
11
+ def sendHipChatMessage (args ) {
12
+ def cli = new CliBuilder (usage : " groovy hip_chat_notify.groovy -from 'Autoconfig' -message 'Test failed' -color 'red' -room 'Automation team' -token '1e21112e46936d74c2468b81efe'" )
13
+ def http = new HTTPBuilder (appUrl)
14
+ cli. f(longOpt : ' from' , args : 1 , ' Define to whom message will be send' , required : true )
15
+ cli. m(longOpt : ' message' , args : 1 , ' Define message to send' , required : true )
16
+ cli. c(longOpt : ' color' , args : 1 , " Define message color" , required : false )
17
+ cli. r(longOpt : ' room' , args : 1 , " Define room where to send message" , required : true )
18
+ cli. t(longOpt : ' token' , args : 1 , " Define token to be used" , required : true )
19
+ options = cli. parse(args)
20
+ if (! options) {
21
+ cli. usage
22
+ return
23
+ }
24
+
25
+ http. request(GET ) { req ->
26
+
27
+ uri. query = [
28
+ auth_token : options. t,
29
+ format : ' json' ,
30
+ room_id : options. r,
31
+ from : options. f,
32
+ message : options. m,
33
+ color : options. c ? options. c : " green"
34
+ ]
35
+
36
+ response. success = { resp , json ->
37
+ println " Response status: ${ resp.statusLine} "
38
+ println " Response: ${ json} "
39
+ }
40
+ }
41
+
42
+ }
43
+
44
+ sendHipChatMessage(args)
0 commit comments