-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOpenfireAPIClient.cs
More file actions
161 lines (129 loc) · 7.43 KB
/
OpenfireAPIClient.cs
File metadata and controls
161 lines (129 loc) · 7.43 KB
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
using OpenfireAPI.entity;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp.Deserializers;
using OpenfireAPI.util;
namespace OpenfireAPI
{
class OpenfireAPIClient
{
private OpenfireClient client;
private JsonDeserializer deserial;
public OpenfireAPIClient(string url, int port, OpenfireAuthenticator authenticator) {
client = new OpenfireClient(url, port, authenticator);
deserial = new JsonDeserializer();
}
/*User related APIs*/
public UserEntities getUsers()
{
IRestResponse response = client.get("users", new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<UserEntities>(response) : null;
}
public UserEntity getUser(string username) {
IRestResponse response = client.get("users/"+username, new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<UserEntity>(response) : null;
}
public bool createUser(UserEntity userEntity)
{
return client.isStatusCodeOK(client.post("users", userEntity, new Dictionary<string, string>()));
}
public bool deleteUser(string username) {
return client.isStatusCodeOK(client.delete("users/" + username, null, new Dictionary<string, string>()));
}
public bool updateUser(string username, UserEntity userEntity) {
return client.isStatusCodeOK(client.put("users/" + username, userEntity, new Dictionary<string, string>()));
}
public UserGroupsEntiry getUserGroups(string username) {
IRestResponse response = client.get("users/"+username+"/groups", new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<UserGroupsEntiry>(response) : null;
}
public bool addUserToGroups(string username, UserGroupsEntiry groups) {
return client.isStatusCodeOK(client.post("users/" + username + "/groups", groups, new Dictionary<string, string>()));
}
public bool addUserToGroup(string username, string group) {
return client.isStatusCodeOK(client.post("users/" + username + "/groups/" + group, null, new Dictionary<string, string>()));
}
public bool deleteUserFromGroups(string username, UserGroupsEntiry groups) {
return client.isStatusCodeOK(client.delete("users/" + username + "/groups", groups, new Dictionary<string, string>()));
}
public bool deleteUserFromGroup(string username, string group) {
return client.isStatusCodeOK(client.delete("users/" + username + "/groups/" + group, null, new Dictionary<string, string>()));
}
public bool lockoutUser(string username) {
return client.isStatusCodeOK(client.post("lockouts/"+username, null, new Dictionary<string, string>()));
}
public bool unlockUser(string username) {
return client.isStatusCodeOK(client.delete("lockouts/"+username, null, new Dictionary<string, string>()));
}
public RosterEntities getRoster(string username) {
IRestResponse response = client.get("users/"+username+"/roster", new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<RosterEntities>(response) : null;
}
public bool addRosterEntry(string username, RosterEntity rosterEntry) {
return client.isStatusCodeOK(client.post("users/" + username + "/roster", rosterEntry, new Dictionary<string, string>()));
}
public bool deleteRosterEntry(string username, string jid) {
return client.isStatusCodeOK(client.delete("users/" + username + "/roster/" + jid, null ,new Dictionary<string, string>()));
}
public bool updateRosterEntry(string username, RosterEntity rosterEntry)
{
return client.isStatusCodeOK(client.put("users/" + username + "/roster", rosterEntry, new Dictionary<string, string>()));
}
public SystemProperties getSystemProperties() {
IRestResponse response = client.get("system/properties", new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<SystemProperties>(response) : null;
}
public SystemProperty getSystemProperty(string propertyName) {
IRestResponse response = client.get("system/properties/"+propertyName, new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<SystemProperty>(response) : null;
}
public bool createSystemProperty(SystemProperty systemProperty) {
return client.isStatusCodeOK(client.post("system/properties", systemProperty, new Dictionary<string, string>()));
}
public bool updateSystemProperty(SystemProperty systemProperty) {
return client.isStatusCodeOK(client.put("system/properties/"+systemProperty.key, systemProperty, new Dictionary<string, string>()));
}
public bool deleteSystemProperty(String propertyName) {
return client.isStatusCodeOK(client.delete("system/properties/"+ propertyName, null, new Dictionary<string, string>()));
}
public GroupEntities getGroups() {
IRestResponse response = client.get("groups" , new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<GroupEntities>(response) : null;
}
public GroupEntity getGroup(string groupName) {
IRestResponse response = client.get("groups/" + groupName, new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<GroupEntity>(response) : null;
}
public bool createGroup(GroupEntity groupEntity) {
return client.isStatusCodeOK(client.post("groups", groupEntity, new Dictionary<string, string>()));
}
public bool deleteGroup(string groupName) {
return client.isStatusCodeOK(client.delete("groups/" + groupName, null, new Dictionary<string, string>()));
}
public bool updateGroup(GroupEntity groupEntity) {
return client.isStatusCodeOK(client.put("groups/" + groupEntity.name, groupEntity, new Dictionary<string, string>()));
}
//TODO: /system/statistics/sessions
//TODO: Chatroom
public SessionEntities getSessions()
{
IRestResponse response = client.get("sessions", new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<SessionEntities>(response) : null;
}
public SessionEntities getSessions(string username) {
IRestResponse response = client.get("sessions/" + username, new Dictionary<string, string>());
return client.isStatusCodeOK(response) ? deserial.Deserialize<SessionEntities>(response) : null;
}
public bool closeSessions(string username) {
return client.isStatusCodeOK(client.delete("sessions/" + username, null, new Dictionary<string, string>()));
}
public bool broadcastMsg(MessageEntity messageEntity) {
return client.isStatusCodeOK(client.post("messages/users", messageEntity, new Dictionary<string, string>()));
}
}
}