-
Notifications
You must be signed in to change notification settings - Fork 8
/
README
163 lines (128 loc) · 4.28 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
ABOUT
python-hipchat is a Python interfacet to the HipChat JSON api. It
wraps the various routes supported by the API in Python classes,
though the mapping isn't perfect. It is also a work in
progress. Through python, it also exposes command line utilities that
will dump either json output to stdout or print human readable results
as a poor mans FFI into other languages, such as Perl.
INSTALLATION
is pretty easy. At the command line as root:
# python setup.py install
DEVELOPMENT
is also pretty easy, either using your virtualenv or as root, run the
following:
$ python setup.py development
This will create shortcuts to the various command line utilities and
expose the hipchat top level module for testing and integration into
other projects.
EXAMPLES
The full documentation of the HipChat API can be found here:
https://www.hipchat.com/docs/api
The following examples show how the python interface maps to the
published API.
The first step is to initialise the config with the appropriate
hipchat token. This is stored in an ini style file, handled by
ConfigObj
In [12]: import hipchat.config
In [13]: hipchat.config.init_cfg('hipchat.cfg')
In [17]: hipchat.config.token
Out[17]: 'fa28d24b4ee537f0ffa51d545a9bf7'
In [18]: cat 'hipchat.cfg'
token = fa28d24b4ee537f0ffa51d545a9bf7
proxy_server = proxy.example.org
proxy_type = http
No worries though, by the time you see this, i'll have revoked this
token.
Then we can perform actions on rooms:
In [19]: Room.list()
Out[19]:
[<hipchat.room.Room object at 0x2e5c990>,
<hipchat.room.Room object at 0x2e78d50>,
<hipchat.room.Room object at 0x2e78d90>,
<hipchat.room.Room object at 0x2e78dd0>]
In [22]: map(str, Room.list())
Out[22]:
['{"room": {"topic": "Discuss open Hackathon projects and request QA
testing", "owner_user_id": 5257, "room_id": 13010, "name": "2011
Hackathon!", "last_active": 1303918853}}',
'{"room": {"topic": "", "owner_user_id": 5237, "room_id": 3721,
"name": "All Testers (only)", "last_active": 1304534734}}',
'{"room": {"topic": "or is it Testing all things?", "owner_user_id":
5237, "room_id": 2444, "name": "All Things Testing", "last_active":
1303239018}}',
'{"room": {"topic": "Analytics", "owner_user_id": 2038, "room_id":
14208, "name": "Analytics", "last_active": 1299629441}}']
In [23]: map(dir, Room.list())
Out[23]:
[['__class__',
'__delattr__',
'__dict__',
'__doc__',
'__format__',
'__getattribute__',
'__hash__',
'__init__',
'__module__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'history',
'jsono',
'last_active',
'list',
'message',
'name',
'owner_user_id',
'room_id',
'show',
'sort',
'topic'],
*SNIP*
]
So you can see that the various properties are preserved. Still, type
safety isn't a true guarantee, since list and show return different
results.
In [5]: str(Room.show(room_id=13010))
Out[5]: '{"room": {"name": "2011 Hackathon!", "last_active":
1303918853, "created": 1297912387, "topic": "Discuss open Hackathon
projects and request QA testing", "participants": [], "room_id":
13010, "owner_user_id": 5257}}'
Sometimes we need to wrap around the silly notion of reserved keywords
(like we care about making compiler authors' lives easy...)
In [6]: x = {'room_id': 13010, 'from': 'Python', 'message': 'Python
Rocks'}
In [7]: Room.message(**x)
Out[7]: <hipchat.room.MessageSentStatus object at 0x31ec690>
In [8]: str(Room.message(**x))
Out[8]: '{"status": "sent"}'
COMMAND LINE
There are a bunch of command line tools to wrap the python, and they
will all return appropriate error codes or dump json to stdout. They
are prefixed with hipchat, so tab completion is your friend. If your
shell does not offer this functionality, then read the fine source
code to discover all the tools.
The commands are as follows:
hipchat-add-user
hipchat-del-user
hipchat-disable-user
hipchat-enable-user
hipchat-list-users
hipchat-set-user-admin
hipchat-set-user-name
hipchat-set-user-password
hipchat-set-user-timezone
hipchat-set-user-title
hipchat-show-user
hipchat-update-user
hipchat-undel-user
Run them with no parameters to find out what they do
PROXY
We can use a proxy server in case your command and control server is
behind some firewall. As seen above, just set the appropriate settings
in hipchat.cfg