-
Notifications
You must be signed in to change notification settings - Fork 52
/
example.php
executable file
·44 lines (38 loc) · 1.06 KB
/
example.php
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
#!/usr/bin/php
<?php
require 'src/HipChat/HipChat.php';
if (!isset($argv[1])) {
echo "Usage: $argv[0] <token> [target]\n";
die;
}
$token = $argv[1];
$target = isset($argv[2]) ? $argv[2] : 'https://api.hipchat.com';
$hc = new HipChat\HipChat($token, $target);
echo "Testing HipChat API.\nTarget: $target\nToken: $token\n\n";
// get rooms
echo "Rooms:\n";
try {
$rooms = $hc->get_rooms();
foreach ($rooms as $room) {
echo "Room $room->room_id\n";
echo " - Name: $room->name\n";
$room_data = $hc->get_room($room->room_id);
echo " - Participants: ".count($room_data->participants)."\n";
}
} catch (HipChat\HipChat_Exception $e) {
echo "Oops! Error: ".$e->getMessage();
}
// get users
echo "\nUsers:\n";
try {
$users = $hc->get_users();
foreach ($users as $user) {
echo "User $user->user_id\n";
echo " - Name: $user->name\n";
echo " - Email: $user->email\n";
$user_data = $hc->get_user($user->user_id);
echo " - Status: ".$user_data->status."\n";
}
} catch (HipChat\HipChat_Exception $e) {
echo "Oops! Error: ".$e->getMessage();
}