jabber_admin 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +30 -0
  3. data/.gitignore +4 -2
  4. data/.rubocop.yml +35 -0
  5. data/.simplecov +5 -0
  6. data/.travis.yml +8 -6
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +53 -0
  9. data/Gemfile +4 -2
  10. data/Makefile +108 -0
  11. data/README.md +145 -21
  12. data/Rakefile +5 -3
  13. data/bin/config.rb +11 -0
  14. data/bin/console +3 -3
  15. data/docker-compose.yml +15 -0
  16. data/jabber_admin.gemspec +34 -27
  17. data/lib/jabber_admin.rb +97 -34
  18. data/lib/jabber_admin/api_call.rb +110 -20
  19. data/lib/jabber_admin/commands.rb +6 -13
  20. data/lib/jabber_admin/commands/ban_account.rb +11 -10
  21. data/lib/jabber_admin/commands/create_room.rb +15 -10
  22. data/lib/jabber_admin/commands/create_room_with_opts.rb +20 -14
  23. data/lib/jabber_admin/commands/get_vcard.rb +84 -0
  24. data/lib/jabber_admin/commands/muc_register_nick.rb +26 -0
  25. data/lib/jabber_admin/commands/register.rb +16 -11
  26. data/lib/jabber_admin/commands/registered_users.rb +18 -0
  27. data/lib/jabber_admin/commands/restart.rb +8 -5
  28. data/lib/jabber_admin/commands/send_direct_invitation.rb +19 -16
  29. data/lib/jabber_admin/commands/send_stanza.rb +21 -0
  30. data/lib/jabber_admin/commands/send_stanza_c2s.rb +28 -0
  31. data/lib/jabber_admin/commands/set_nickname.rb +22 -0
  32. data/lib/jabber_admin/commands/set_presence.rb +37 -0
  33. data/lib/jabber_admin/commands/set_room_affiliation.rb +17 -12
  34. data/lib/jabber_admin/commands/set_vcard.rb +68 -0
  35. data/lib/jabber_admin/commands/subscribe_room.rb +19 -12
  36. data/lib/jabber_admin/commands/unregister.rb +13 -7
  37. data/lib/jabber_admin/commands/unsubscribe_room.rb +10 -7
  38. data/lib/jabber_admin/configuration.rb +6 -1
  39. data/lib/jabber_admin/exceptions.rb +41 -0
  40. data/lib/jabber_admin/version.rb +20 -1
  41. metadata +119 -25
  42. data/lib/jabber_admin/initializer.rb +0 -5
@@ -2,19 +2,24 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Change an affiliation in a MUC room
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#set-room-affiliation-change-an-affiliation-in-a-muc-room
5
+ # Change a user affiliation in a MUC room. (eg. allow him to enter a
6
+ # members-only room)
7
+ #
8
+ # @see https://bit.ly/2G5MfbW
8
9
  class SetRoomAffiliation
9
- # @param [name] Room name
10
- # @param [service] MUC service
11
- # @param [jid] User JID
12
- # @param [affiliation] Affiliation to set
13
- def self.call(name:, service:, jid:, affiliation:)
14
- JabberAdmin::ApiCall.perform(
15
- 'set_room_affiliation',
16
- name: name, service: service, jid: jid, affiliation: affiliation
17
- )
10
+ # Pass the correct data to the given callable.
11
+ #
12
+ # @param callable [Proc, #call] the callable to call
13
+ # @param user [String] user JID wo/ resource (eg. +tom@localhost+)
14
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
15
+ # @param affiliation [String] the MUC/user affiliation (eg. +member+)
16
+ def self.call(callable, user:, room:, affiliation: 'member')
17
+ name, service = room.split('@')
18
+ callable.call('set_room_affiliation',
19
+ name: name,
20
+ service: service,
21
+ jid: user,
22
+ affiliation: affiliation)
18
23
  end
19
24
  end
20
25
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ # Set contents in a vCard.
6
+ #
7
+ # Examples:
8
+ #
9
+ # JabberAdmin.set_vcard!(
10
+ # user: 'ac865680-9681-45da-8fee-8584053dde5b@jabber.local',
11
+ # 'org.orgunit[]' => %w[Marketing Production],
12
+ # fn: 'Max Mustermann',
13
+ # 'n.given': 'Max',
14
+ # 'n.family' => 'Mustermann'
15
+ # )
16
+ # # => {"org.orgunit[]"=>["Marketing", "Production"],
17
+ # # "n.family"=>"Mustermann",
18
+ # # :fn=>"Max Mustermann",
19
+ # # :"n.given"=>"Max"}
20
+ #
21
+ # @see https://bit.ly/2ZB9S6y
22
+ # @see https://bit.ly/3lAIGzO
23
+ # @see https://bit.ly/34MiviZ
24
+ class SetVcard
25
+ # Pass the correct data to the given callable.
26
+ #
27
+ # @param callable [Proc, #call] the callable to call
28
+ # @param args [Hash] the keys/values to set to the vCard
29
+ # (eg. +n.family+ for multiple levels)
30
+ # @param user [String] user JID wo/ resource (eg. +tom@localhost+)
31
+ # @param sym_args [Hash{Symbol => Mixed}] additional keys/values to
32
+ # set to the vCard
33
+ # @return [Hash] the vCard details
34
+ #
35
+ # rubocop:disable Metrics/MethodLength because the ejabberd REST API is
36
+ # hard to use in complex scenarios, so we have to work around it
37
+ # rubocop:disable Metrics/AbcSize dito
38
+ def self.call(callable, args = {}, user:, **sym_args)
39
+ args = args.merge(sym_args)
40
+ uid, host = user.split('@')
41
+
42
+ set = proc do |key, val|
43
+ parts = key.to_s.upcase.split('.')
44
+ body = { name: parts.shift, content: val }
45
+ meth = 'set_vcard'
46
+
47
+ unless parts.empty?
48
+ body[:subname] = parts.shift
49
+ meth = 'set_vcard2'
50
+
51
+ if body[:subname].end_with? '[]'
52
+ meth += '_multi'
53
+ body[:subname].delete_suffix!('[]')
54
+ body[:contents] = body.delete(:content)
55
+ end
56
+ end
57
+
58
+ callable.call(meth, user: uid, host: host, **body)
59
+ end
60
+
61
+ args.each { |key, val| set[key, val] }
62
+ args
63
+ end
64
+ # rubocop:enable Metrics/MethodLength
65
+ # rubocop:enable Metrics/AbcSize
66
+ end
67
+ end
68
+ end
@@ -2,19 +2,26 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Subscribe to a MUC conference
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#subscribe-room-subscribe-to-a-muc-conference
5
+ # Subscribe to a MUC conference, via the mucsub feature.
6
+ #
7
+ # @see https://bit.ly/2Ke7Zoy
8
8
  class SubscribeRoom
9
- # @param [user] Full JID, including some resource
10
- # @param [nick] A user's nick
11
- # @param [room] The room to subscribe
12
- # @param [nodes] nodes
13
- def self.call(user:, nick:, room:, nodes:)
14
- JabberAdmin::ApiCall.perform(
15
- 'subscribe_room',
16
- user: user, nick: nick, room: room, nodes: nodes
17
- )
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param user [String] user JID w/ resource (eg. +tom@localhost/dummy+)
13
+ # @param nick [String] the user nickname (eg. +TomTom+)
14
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
15
+ # @param nodes [Array<String>] nodes comma separated
16
+ # (eg. +urn:xmpp:mucsub:nodes:messages+,
17
+ # +urn:xmpp:mucsub:nodes:affiliations+)
18
+ def self.call(callable, user:, nick:, room:, nodes: [])
19
+ callable.call('subscribe_room',
20
+ check_res_body: false,
21
+ user: user,
22
+ nick: nick,
23
+ room: room,
24
+ nodes: nodes.join(','))
18
25
  end
19
26
  end
20
27
  end
@@ -2,14 +2,20 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Unregister a user
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#unregister-unregister-a-user
5
+ # Unregister (delete) a user from the XMPP service.
6
+ #
7
+ # @see https://bit.ly/2wwYnDE
8
8
  class Unregister
9
- # @param [user] The username
10
- # @param [host] Local vhost served by ejabberd
11
- def self.call(user:, host:)
12
- JabberAdmin::ApiCall.perform 'unregister', user: user, host: host
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param user [String] user JID wo/ resource (eg. +tom@localhost+)
13
+ def self.call(callable, user:)
14
+ uid, host = user.split('@')
15
+ callable.call('unregister',
16
+ check_res_body: false,
17
+ user: uid,
18
+ host: host)
13
19
  end
14
20
  end
15
21
  end
@@ -2,14 +2,17 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Subscribe to a MUC conference
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#unsubscribe-room-unsubscribe-from-a-muc-conference
5
+ # Subscribe to a MUC conference, via the mucsub feature.
6
+ #
7
+ # @see https://bit.ly/2G5zcrj
8
8
  class UnsubscribeRoom
9
- # @param [user] Full JID, including some resource
10
- # @param [room] The room to subscribe
11
- def self.call(user:, room:)
12
- JabberAdmin::ApiCall.perform 'unsubscribe_room', user: user, room: room
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param user [String] user JID w/ resource (eg. +tom@localhost/dummy+)
13
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
14
+ def self.call(callable, user:, room:)
15
+ callable.call('unsubscribe_room', user: user, room: room)
13
16
  end
14
17
  end
15
18
  end
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JabberAdmin
4
+ # A JabberAdmin configuration definition. It is directly accessible via
5
+ # +JabberAdmin.configuration+ or
6
+ # +JabberAdmin.configure(&block(configuration))+ in a tapped variant.
7
+ #
8
+ # See the +JabberAdmin+ documentation for further details.
4
9
  class Configuration
5
- attr_accessor :admin, :password, :api_host
10
+ attr_accessor :username, :password, :url
6
11
  end
7
12
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ # The base exception which all other exceptions inherit. In case you want to
5
+ # use our error handling with the bang variants, you can rescue all
6
+ # exceptions like this:
7
+ #
8
+ # begin
9
+ # JabberAdmin.COMMAND!
10
+ # rescue JabberAdmin::Error => err
11
+ # # Do your error handling here
12
+ # end
13
+ class Error < StandardError
14
+ attr_accessor :response
15
+
16
+ # Create a new exception.
17
+ #
18
+ # @param msg [String] the excpetion message
19
+ # @param response [RestClient::Response] the response when available
20
+ def initialize(msg, response = nil)
21
+ @response = response
22
+ msg += " => #{response.body}" if response&.body
23
+ super(msg)
24
+ end
25
+ end
26
+
27
+ # This exception is raised when the request was denied due to premission
28
+ # issues or a general unavaliability of the command on the REST API. This
29
+ # simply means the response code from ejabberd was not 200 OK.
30
+ class RequestError < Error; end
31
+
32
+ # This exception is raised when the response from the ejabberd REST API
33
+ # indicated that the status of the command was not successful. In this case
34
+ # the response body includes a one (1). In case everything was fine, it
35
+ # includes a zero (0).
36
+ class CommandError < Error; end
37
+
38
+ # This exception is raised when we send an unknown command to the REST API.
39
+ # It will respond with a 404 status code in this case.
40
+ class UnknownCommandError < Error; end
41
+ end
@@ -1,5 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The gem module.
3
4
  module JabberAdmin
4
- VERSION = "0.1.2"
5
+ # The version constant of the gem. Increase this value
6
+ # in case of a gem release.
7
+ VERSION = '1.0.1'
8
+
9
+ class << self
10
+ # Returns the version of gem as a string.
11
+ #
12
+ # @return [String] the gem version as string
13
+ def version
14
+ VERSION
15
+ end
16
+
17
+ # Returns the version of the gem as a +Gem::Version+.
18
+ #
19
+ # @return [Gem::Version] the gem version as object
20
+ def gem_version
21
+ Gem::Version.new VERSION
22
+ end
23
+ end
5
24
  end
metadata CHANGED
@@ -1,15 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jabber_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Vogt
8
- autorequire:
8
+ - Hermann Mayer
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
12
+ date: 2020-10-13 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 5.2.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 5.2.0
13
28
  - !ruby/object:Gem::Dependency
14
29
  name: rest-client
15
30
  requirement: !ruby/object:Gem::Requirement
@@ -31,91 +46,163 @@ dependencies:
31
46
  - !ruby/object:Gem::Version
32
47
  version: 2.0.2
33
48
  - !ruby/object:Gem::Dependency
34
- name: activesupport
49
+ name: bundler
35
50
  requirement: !ruby/object:Gem::Requirement
36
51
  requirements:
37
52
  - - ">="
38
53
  - !ruby/object:Gem::Version
39
- version: '5'
40
- type: :runtime
54
+ version: '1.16'
55
+ - - "<"
56
+ - !ruby/object:Gem::Version
57
+ version: '3'
58
+ type: :development
41
59
  prerelease: false
42
60
  version_requirements: !ruby/object:Gem::Requirement
43
61
  requirements:
44
62
  - - ">="
45
63
  - !ruby/object:Gem::Version
46
- version: '5'
64
+ version: '1.16'
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '3'
47
68
  - !ruby/object:Gem::Dependency
48
- name: bundler
69
+ name: irb
49
70
  requirement: !ruby/object:Gem::Requirement
50
71
  requirements:
51
72
  - - "~>"
52
73
  - !ruby/object:Gem::Version
53
- version: '1.16'
74
+ version: '1.2'
54
75
  type: :development
55
76
  prerelease: false
56
77
  version_requirements: !ruby/object:Gem::Requirement
57
78
  requirements:
58
79
  - - "~>"
59
80
  - !ruby/object:Gem::Version
60
- version: '1.16'
81
+ version: '1.2'
61
82
  - !ruby/object:Gem::Dependency
62
83
  name: rake
63
84
  requirement: !ruby/object:Gem::Requirement
64
85
  requirements:
65
86
  - - "~>"
66
87
  - !ruby/object:Gem::Version
67
- version: '10.0'
88
+ version: '13.0'
68
89
  type: :development
69
90
  prerelease: false
70
91
  version_requirements: !ruby/object:Gem::Requirement
71
92
  requirements:
72
93
  - - "~>"
73
94
  - !ruby/object:Gem::Version
74
- version: '10.0'
95
+ version: '13.0'
75
96
  - !ruby/object:Gem::Dependency
76
97
  name: rspec
77
98
  requirement: !ruby/object:Gem::Requirement
78
99
  requirements:
79
100
  - - "~>"
80
101
  - !ruby/object:Gem::Version
81
- version: '3.0'
102
+ version: '3.9'
82
103
  type: :development
83
104
  prerelease: false
84
105
  version_requirements: !ruby/object:Gem::Requirement
85
106
  requirements:
86
107
  - - "~>"
87
108
  - !ruby/object:Gem::Version
88
- version: '3.0'
109
+ version: '3.9'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubocop
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.93'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.93'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rubocop-rspec
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.43'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '1.43'
89
138
  - !ruby/object:Gem::Dependency
90
139
  name: simplecov
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '0.18'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "<"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.18'
152
+ - !ruby/object:Gem::Dependency
153
+ name: vcr
91
154
  requirement: !ruby/object:Gem::Requirement
92
155
  requirements:
93
156
  - - "~>"
94
157
  - !ruby/object:Gem::Version
95
- version: '0.15'
158
+ version: '6.0'
96
159
  type: :development
97
160
  prerelease: false
98
161
  version_requirements: !ruby/object:Gem::Requirement
99
162
  requirements:
100
163
  - - "~>"
101
164
  - !ruby/object:Gem::Version
102
- version: '0.15'
103
- description: Library for the Ejabberd RESTful admin API
165
+ version: '6.0'
166
+ - !ruby/object:Gem::Dependency
167
+ name: webmock
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.0'
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '3.0'
180
+ description: Library for the ejabberd RESTful admin API
104
181
  email:
105
182
  - henning.vogt@hausgold.de
183
+ - hermann.mayer@hausgold.de
106
184
  executables: []
107
185
  extensions: []
108
186
  extra_rdoc_files: []
109
187
  files:
188
+ - ".editorconfig"
110
189
  - ".gitignore"
111
190
  - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".simplecov"
112
193
  - ".travis.yml"
194
+ - ".yardopts"
195
+ - CHANGELOG.md
113
196
  - Gemfile
114
197
  - LICENSE
198
+ - Makefile
115
199
  - README.md
116
200
  - Rakefile
201
+ - bin/config.rb
117
202
  - bin/console
118
203
  - bin/setup
204
+ - doc/assets/project.svg
205
+ - docker-compose.yml
119
206
  - jabber_admin.gemspec
120
207
  - lib/jabber_admin.rb
121
208
  - lib/jabber_admin/api_call.rb
@@ -123,39 +210,46 @@ files:
123
210
  - lib/jabber_admin/commands/ban_account.rb
124
211
  - lib/jabber_admin/commands/create_room.rb
125
212
  - lib/jabber_admin/commands/create_room_with_opts.rb
213
+ - lib/jabber_admin/commands/get_vcard.rb
214
+ - lib/jabber_admin/commands/muc_register_nick.rb
126
215
  - lib/jabber_admin/commands/register.rb
216
+ - lib/jabber_admin/commands/registered_users.rb
127
217
  - lib/jabber_admin/commands/restart.rb
128
218
  - lib/jabber_admin/commands/send_direct_invitation.rb
219
+ - lib/jabber_admin/commands/send_stanza.rb
220
+ - lib/jabber_admin/commands/send_stanza_c2s.rb
221
+ - lib/jabber_admin/commands/set_nickname.rb
222
+ - lib/jabber_admin/commands/set_presence.rb
129
223
  - lib/jabber_admin/commands/set_room_affiliation.rb
224
+ - lib/jabber_admin/commands/set_vcard.rb
130
225
  - lib/jabber_admin/commands/subscribe_room.rb
131
226
  - lib/jabber_admin/commands/unregister.rb
132
227
  - lib/jabber_admin/commands/unsubscribe_room.rb
133
228
  - lib/jabber_admin/configuration.rb
134
- - lib/jabber_admin/initializer.rb
229
+ - lib/jabber_admin/exceptions.rb
135
230
  - lib/jabber_admin/version.rb
136
231
  homepage: https://github.com/hausgold/jabber_admin
137
232
  licenses:
138
233
  - MIT
139
234
  metadata:
140
235
  allowed_push_host: https://rubygems.org
141
- post_install_message:
236
+ post_install_message:
142
237
  rdoc_options: []
143
238
  require_paths:
144
239
  - lib
145
240
  required_ruby_version: !ruby/object:Gem::Requirement
146
241
  requirements:
147
- - - ">="
242
+ - - "~>"
148
243
  - !ruby/object:Gem::Version
149
- version: '2.2'
244
+ version: '2.5'
150
245
  required_rubygems_version: !ruby/object:Gem::Requirement
151
246
  requirements:
152
247
  - - ">="
153
248
  - !ruby/object:Gem::Version
154
249
  version: '0'
155
250
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.6.11
158
- signing_key:
251
+ rubygems_version: 3.1.4
252
+ signing_key:
159
253
  specification_version: 4
160
- summary: Library for the Ejabberd RESTful admin API
254
+ summary: Library for the ejabberd RESTful admin API
161
255
  test_files: []