openfire_rest_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a9575f1e7b1c21354175b39005219d5fb9a4152
4
- data.tar.gz: ce785b38cd08773faee8dc87738c9f87e25bf055
3
+ metadata.gz: 9f06cd01af92ab289c6029351aa6a77f7d652cbc
4
+ data.tar.gz: 09809d851444139737e60e944bb09a0bc1f1eb4a
5
5
  SHA512:
6
- metadata.gz: 9090e6000137d7b2310c48f4a3b426b1fc40063225c9086a7cad9331759436b2d3ab0702f404d26833aad3c7b0e322c18e3f57fdb170032ae05f3575bf22b7c4
7
- data.tar.gz: fdd81077e7db4d5b8749e6428fd080916aa44de8caa8b06cb54c987c7ca75eb50bd9c7949c1a8e572101ba89cff2177cdc33aa7070b6095a49df16ae47058782
6
+ metadata.gz: f0ac8ea9ca55ec17fd9b9d2b16261e359aea520366d27946e5c67bbdcdde8476b692dc6c5ad4e72e6ae8d570e5190f1a9e7eeb8e6be3bd490f9b3a7e4b43768c
7
+ data.tar.gz: 850ae354b0a42e9237ff60bddd1c309bbbdebf7c69077df5108fbb5cea815d1508bfc7882c89a587943892d64f969dfcd07d9eb8bf9ea385d01bce32a299e141
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
- ## v0.0.1
1
+ ## v0.1.0
2
2
 
3
3
  * Initial release
4
+
5
+ ## v0.2.0
6
+
7
+ * Added methods to get sessions, system properties, send broadcast messages
data/lib/openfire/api.rb CHANGED
@@ -75,6 +75,94 @@ module Openfire
75
75
  (request[:status_code] == 200)
76
76
  end
77
77
 
78
+ def get_user_roster(username)
79
+ raise 'not implemented'
80
+ end
81
+
82
+ def create_user_roster(username, roster_data={})
83
+ raise 'not implemented'
84
+ end
85
+
86
+ def delete_user_roster(username, jid)
87
+ raise 'not implemented'
88
+ end
89
+
90
+ def update_user_roster(username, jid, roster_data={})
91
+ raise 'not implemented'
92
+ end
93
+
94
+ def get_chatrooms
95
+ raise 'not implemented'
96
+ end
97
+
98
+ def get_chatroom(room_name)
99
+ raise 'not implemented'
100
+ end
101
+
102
+ def get_chatroom_participants(room_name)
103
+ raise 'not implemented'
104
+ end
105
+
106
+ def create_chatroom(room_data={})
107
+ raise 'not implemented'
108
+ end
109
+
110
+ def delete_chatroom(room_name)
111
+ raise 'not implemented'
112
+ end
113
+
114
+ def update_chatroom(room_name, room_data={})
115
+ raise 'not implemented'
116
+ end
117
+
118
+ def add_user_to_chatroom(room_name, username_or_jid, role)
119
+ raise 'not implemented'
120
+ end
121
+
122
+ def delete_user_from_chatroom(room_name, username_or_jid, role)
123
+ raise 'not implemented'
124
+ end
125
+
126
+ def get_system_properties
127
+ request = web_request('GET', '/system/properties', { }, default_headers)
128
+ request[:body]['property'].map { |x| Openfire::SystemProperty.new(x) }
129
+ end
130
+
131
+ def get_system_property(property_name)
132
+ request = web_request('GET', "/system/properties/#{property_name}", { }, default_headers)
133
+ Openfire::SystemProperty.new(request[:body])
134
+ end
135
+
136
+ def create_system_property(property_name, value)
137
+ payload = {
138
+ '@key' => property_name,
139
+ '@value' => value
140
+ }.to_json
141
+
142
+ request = web_request('POST', '/system/properties', payload, default_headers)
143
+ (request[:status_code] == 201)
144
+ end
145
+
146
+ def delete_system_property(property_name)
147
+ request = web_request('DELETE', "/system/properties/#{property_name}", { }, default_headers)
148
+ (request[:status_code] == 200)
149
+ end
150
+
151
+ def update_system_property(property_name, value)
152
+ payload = {
153
+ '@key' => property_name,
154
+ '@value' => value
155
+ }.to_json
156
+
157
+ request = web_request('PUT', "/system/properties/#{property_name}", payload, default_headers)
158
+ (request[:status_code] == 200)
159
+ end
160
+
161
+ def get_concurrent_sessions_count
162
+ request = web_request('GET', '/system/statistics/sessions', { }, default_headers)
163
+ Openfire::SessionsCount.new(request[:body])
164
+ end
165
+
78
166
  def get_groups
79
167
  request = web_request('GET', '/groups', { }, default_headers)
80
168
  request[:body]['group'].map { |x| Openfire::Group.new(x) }
@@ -100,6 +188,39 @@ module Openfire
100
188
  (request[:status_code] == 200)
101
189
  end
102
190
 
191
+ def get_sessions
192
+ request = web_request('GET', '/sessions', { }, default_headers)
193
+ data = request[:body]['session']
194
+
195
+ if data.is_a?(Array)
196
+ data.map { |x| Openfire::Session.new(x) }
197
+ else
198
+ [Openfire::Session.new(data)]
199
+ end
200
+ end
201
+
202
+ def get_user_sessions(username)
203
+ request = web_request('GET', "/sessions/#{username}", { }, default_headers)
204
+ data = request[:body]['session']
205
+
206
+ if data.is_a?(Array)
207
+ data.map { |x| Openfire::Session.new(x) }
208
+ else
209
+ [Openfire::Session.new(data)]
210
+ end
211
+ end
212
+
213
+ def close_user_sessions(username)
214
+ request = web_request('DELETE', "/sessions/#{username}", { }, default_headers)
215
+ (request[:status_code] == 200)
216
+ end
217
+
218
+ def send_broadcast_message(message_text)
219
+ payload = { body: message_text }.to_json
220
+
221
+ request = web_request('POST', '/messages/users', payload, default_headers)
222
+ end
223
+
103
224
  private
104
225
 
105
226
  def default_headers
@@ -4,8 +4,18 @@ module Openfire
4
4
 
5
5
  def initialize(attributes={})
6
6
  attributes.each do |k,v|
7
- self.send("#{k}=", v)
7
+ self.send("#{to_underscore(k)}=", v)
8
8
  end
9
9
  end
10
+
11
+ private
12
+
13
+ def to_underscore(val)
14
+ val.gsub(/::/, '/').
15
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
16
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
17
+ tr("-", "_").
18
+ downcase
19
+ end
10
20
  end
11
21
  end
@@ -0,0 +1,34 @@
1
+ module Openfire
2
+ class Session
3
+ attr_accessor :session_id, :username, :resource, :node, :session_status,
4
+ :presence_status, :presence_message, :priority, :host_address, :host_name,
5
+ :creation_date, :last_action_date, :secure
6
+
7
+ def initialize(attributes={})
8
+ time_attrs = ['creationDate', 'lastActionDate']
9
+ boolean_attrs = ['secure']
10
+
11
+ attributes.each do |k,v|
12
+ if k == 'ressource'
13
+ self.resource = v
14
+ elsif time_attrs.include?(k)
15
+ self.send("#{to_underscore(k)}=", Time.parse(v)) unless v.nil?
16
+ elsif boolean_attrs.include?(k)
17
+ self.send("#{to_underscore(k)}=", v == 'true')
18
+ else
19
+ self.send("#{to_underscore(k)}=", v)
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def to_underscore(val)
27
+ val.gsub(/::/, '/').
28
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
29
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
30
+ tr("-", "_").
31
+ downcase
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ module Openfire
2
+ class SessionsCount
3
+ attr_accessor :cluster_sessions, :local_sessions
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{to_underscore(k)}=", v)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def to_underscore(val)
14
+ val.gsub(/::/, '/').
15
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
16
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
17
+ tr("-", "_").
18
+ downcase
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Openfire
2
+ class SystemProperty
3
+ attr_accessor :key, :value
4
+
5
+ def initialize(attributes={})
6
+ attributes.each do |k,v|
7
+ self.send("#{to_underscore(k).gsub('@','')}=", v)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def to_underscore(val)
14
+ val.gsub(/::/, '/').
15
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
16
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
17
+ tr("-", "_").
18
+ downcase
19
+ end
20
+ end
21
+ end
data/lib/openfire/user.rb CHANGED
@@ -4,8 +4,18 @@ module Openfire
4
4
 
5
5
  def initialize(attributes={})
6
6
  attributes.each do |k,v|
7
- self.send("#{k}=", v)
7
+ self.send("#{to_underscore(k)}=", v)
8
8
  end
9
9
  end
10
+
11
+ private
12
+
13
+ def to_underscore(val)
14
+ val.gsub(/::/, '/').
15
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
16
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
17
+ tr("-", "_").
18
+ downcase
19
+ end
10
20
  end
11
21
  end
@@ -1,3 +1,3 @@
1
1
  module OpenfireRestApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,8 +1,11 @@
1
1
  require "openfire_rest_api/version"
2
2
 
3
3
  require 'openfire/api'
4
- require 'openfire/user'
5
4
  require 'openfire/group'
5
+ require 'openfire/session'
6
+ require 'openfire/sessions_count'
7
+ require 'openfire/system_property'
8
+ require 'openfire/user'
6
9
 
7
10
  # external dependencies
8
11
  require 'rest-client'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openfire_rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,9 @@ files:
65
65
  - README.md
66
66
  - lib/openfire/api.rb
67
67
  - lib/openfire/group.rb
68
+ - lib/openfire/session.rb
69
+ - lib/openfire/sessions_count.rb
70
+ - lib/openfire/system_property.rb
68
71
  - lib/openfire/user.rb
69
72
  - lib/openfire_rest_api.rb
70
73
  - lib/openfire_rest_api/version.rb