|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SolutionDrive\HipchatAPIv2Client\API; |
|
4
|
|
|
|
|
5
|
|
|
use SolutionDrive\HipchatAPIv2Client\ClientInterface; |
|
6
|
|
|
use SolutionDrive\HipchatAPIv2Client\Model\User; |
|
7
|
|
|
use SolutionDrive\HipchatAPIv2Client\Model\Message; |
|
8
|
|
|
use SolutionDrive\HipchatAPIv2Client\Model\UserInterface; |
|
9
|
|
|
|
|
10
|
|
|
class UserAPI implements UserAPIInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var ClientInterface */ |
|
13
|
|
|
protected $client; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Room api constructor |
|
17
|
|
|
* |
|
18
|
|
|
* @param ClientInterface $client that will be used to connect the server |
|
19
|
|
|
*/ |
|
20
|
12 |
|
public function __construct(ClientInterface $client) |
|
21
|
|
|
{ |
|
22
|
12 |
|
$this->client = $client; |
|
23
|
12 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritdoc |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function getAllUsers($parameters = array()) |
|
29
|
|
|
{ |
|
30
|
1 |
|
$response = $this->client->get('/v2/user', $parameters); |
|
31
|
|
|
|
|
32
|
1 |
|
$users = array(); |
|
33
|
1 |
|
foreach ($response['items'] as $response) { |
|
34
|
1 |
|
$users[] = new User($response); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
return $users; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @inheritdoc |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function getUser($userId) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$response = $this->client->get(sprintf('/v2/user/%s', $userId)); |
|
46
|
|
|
|
|
47
|
1 |
|
return new User($response); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritdoc |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public function createUser(UserInterface $user, $password) |
|
54
|
|
|
{ |
|
55
|
1 |
|
$request = $user->toJson(); |
|
56
|
1 |
|
$request['password'] = $password; |
|
57
|
1 |
|
$response = $this->client->post('/v2/user', $request); |
|
58
|
|
|
|
|
59
|
1 |
|
return $response['id']; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritdoc |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function updateUser(UserInterface $user) |
|
66
|
|
|
{ |
|
67
|
1 |
|
$request = $user->toJson(); |
|
68
|
1 |
|
$this->client->put(sprintf('/v2/user/%s', $user->getId()), $request); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @inheritdoc |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function deleteUser($userId) |
|
75
|
|
|
{ |
|
76
|
1 |
|
$this->client->delete(sprintf('/v2/user/%s', $userId)); |
|
77
|
1 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @inheritdoc |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function privateMessageUser($userId, $message) |
|
83
|
|
|
{ |
|
84
|
2 |
|
if (is_string($message)) { |
|
85
|
1 |
|
$content = array('message' => $message); |
|
86
|
|
|
} else { // Assuming its a Message |
|
87
|
1 |
|
$content = $message->toJson(); |
|
88
|
|
|
} |
|
89
|
2 |
|
$this->client->post(sprintf('/v2/user/%s/message', $userId), $content); |
|
90
|
2 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
2 |
|
public function getRecentPrivateChatHistory($userId, array $parameters = array()) |
|
96
|
|
|
{ |
|
97
|
2 |
|
$response = $this->client->get( |
|
98
|
2 |
|
sprintf('/v2/user/%s/history/latest', $userId), |
|
99
|
2 |
|
$parameters |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
2 |
|
$messages = array(); |
|
103
|
2 |
|
foreach ($response['items'] as $response) { |
|
104
|
1 |
|
$messages[] = new Message($response); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
2 |
|
return $messages; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @inheritdoc |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function getPrivateChatMessage($user, $messageId, array $parameters = array()) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$response = $this->client->get( |
|
116
|
1 |
|
sprintf('/v2/user/%s/history/%s', $user, $messageId), |
|
117
|
1 |
|
$parameters |
|
118
|
|
|
); |
|
119
|
|
|
|
|
120
|
1 |
|
$message = new Message($response['message']); |
|
121
|
|
|
|
|
122
|
1 |
|
return $message; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @inheritdoc |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getPhoto($userId, $size) |
|
129
|
|
|
{ |
|
130
|
1 |
|
$response = $this->client->get( |
|
131
|
1 |
|
sprintf('/v2/user/%s/photo/%s', $userId, $size) |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
1 |
|
return $response; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|