jabber_admin 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +30 -0
  3. data/.gitignore +4 -2
  4. data/.rubocop.yml +33 -0
  5. data/.simplecov +3 -0
  6. data/.travis.yml +7 -3
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +30 -0
  9. data/Gemfile +4 -2
  10. data/Makefile +100 -0
  11. data/README.md +142 -22
  12. data/Rakefile +5 -3
  13. data/bin/console +4 -3
  14. data/docker-compose.yml +15 -0
  15. data/jabber_admin.gemspec +22 -15
  16. data/lib/jabber_admin.rb +100 -34
  17. data/lib/jabber_admin/api_call.rb +106 -20
  18. data/lib/jabber_admin/commands.rb +6 -5
  19. data/lib/jabber_admin/commands/ban_account.rb +11 -10
  20. data/lib/jabber_admin/commands/create_room.rb +15 -10
  21. data/lib/jabber_admin/commands/create_room_with_opts.rb +20 -14
  22. data/lib/jabber_admin/commands/muc_register_nick.rb +26 -0
  23. data/lib/jabber_admin/commands/register.rb +16 -11
  24. data/lib/jabber_admin/commands/registered_users.rb +8 -6
  25. data/lib/jabber_admin/commands/restart.rb +8 -5
  26. data/lib/jabber_admin/commands/send_direct_invitation.rb +19 -16
  27. data/lib/jabber_admin/commands/send_stanza.rb +12 -10
  28. data/lib/jabber_admin/commands/send_stanza_c2s.rb +28 -0
  29. data/lib/jabber_admin/commands/set_nickname.rb +22 -0
  30. data/lib/jabber_admin/commands/set_presence.rb +37 -0
  31. data/lib/jabber_admin/commands/set_room_affiliation.rb +17 -12
  32. data/lib/jabber_admin/commands/subscribe_room.rb +19 -12
  33. data/lib/jabber_admin/commands/unregister.rb +13 -7
  34. data/lib/jabber_admin/commands/unsubscribe_room.rb +10 -7
  35. data/lib/jabber_admin/configuration.rb +6 -1
  36. data/lib/jabber_admin/exceptions.rb +40 -0
  37. data/lib/jabber_admin/version.rb +3 -1
  38. metadata +85 -16
  39. data/lib/jabber_admin/initializer.rb +0 -6
@@ -2,17 +2,22 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Create a MUC room name@service in host
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#create-room-create-a-muc-room-name-service-in-host
5
+ # Create a new room (MUC).
6
+ #
7
+ # @see https://bit.ly/2rB8DFR
8
8
  class CreateRoom
9
- # @param [name] The room name
10
- # @param [service] MUC service
11
- # @param [host] Server host
12
- def self.call(name:, service:, host:)
13
- JabberAdmin::ApiCall.perform(
14
- 'create_room', name: name, service: service, host: host
15
- )
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # *Note:* this command should not be used in the bang-variant, due to raw
12
+ # result string in the response. (the response body is not zero/one like
13
+ # on almost all commands)
14
+ #
15
+ # @param callable [Proc, #call] the callable to call
16
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
17
+ # @param host [String] the jabber host (eg. +localhost+)
18
+ def self.call(callable, room:, host:)
19
+ name, service = room.split('@')
20
+ callable.call('create_room', name: name, service: service, host: host)
16
21
  end
17
22
  end
18
23
  end
@@ -2,21 +2,27 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Create a MUC room name@service in host
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#create-room-with-opts-create-a-muc-room-name-service-in-host-with-given-options
5
+ # Create a new room (MUC) with additional options.
6
+ #
7
+ # @see https://bit.ly/2IBEfVO
8
8
  class CreateRoomWithOpts
9
- # @param [name] The room name
10
- # @param [service] MUC service
11
- # @param [host] Server host
12
- # @param [options] [{ Name::String, Value::String }] List of options
13
- def self.call(name:, service:, host:, options:)
14
- JabberAdmin::ApiCall.perform(
15
- 'create_room_with_opts', name: name,
16
- service: service,
17
- host: host,
18
- options: options
19
- )
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
13
+ # @param host [String] the jabber host (eg. +localhost+)
14
+ # @param options pass additional +symbol: value+ pairs
15
+ def self.call(callable, room:, host:, **options)
16
+ name, service = room.split('@')
17
+ options = options.map do |key, value|
18
+ Hash['name', key.to_s, 'value', value.to_s]
19
+ end
20
+
21
+ callable.call('create_room_with_opts',
22
+ name: name,
23
+ service: service,
24
+ host: host,
25
+ options: options)
20
26
  end
21
27
  end
22
28
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ # Register a nick to a user JID in the MUC service of a server.
6
+ #
7
+ # *Note*: On ejabberd <= 18.01 this command always returns a error code,
8
+ # even when the command was successful under the hood. (See:
9
+ # https://bit.ly/2L1CpvE)
10
+ #
11
+ # @see https://bit.ly/2G9EBNQ
12
+ class MucRegisterNick
13
+ # Pass the correct data to the given callable.
14
+ #
15
+ # @param callable [Proc, #call] the callable to call
16
+ # @param user [String] user JID wo/ resource (eg. +tom@localhost+)
17
+ # @param nick [String] the user nickname (eg. +TomTom+)
18
+ def self.call(callable, user:, nick:)
19
+ callable.call('muc_register_nick',
20
+ nick: nick,
21
+ jid: user,
22
+ serverhost: user.split('@').last)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -2,18 +2,23 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Register a user
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#register-register-a-user
5
+ # Register a new user on the XMPP service.
6
+ #
7
+ # @see https://bit.ly/2wyhAox
8
8
  class Register
9
- # @param [user] The username
10
- # @param [host] Local vhost served by ejabberd
11
- # @param [password] The password
12
- def self.call(user:, host:, password:)
13
- JabberAdmin::ApiCall.perform(
14
- 'register',
15
- user: user, host: host, password: password
16
- )
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
+ # @param password [String] the new plain password for the user
14
+ # (eg. +secret+)
15
+ def self.call(callable, user:, password:)
16
+ uid, host = user.split('@')
17
+ callable.call('register',
18
+ check_res_body: false,
19
+ user: uid,
20
+ host: host,
21
+ password: password)
17
22
  end
18
23
  end
19
24
  end
@@ -2,14 +2,16 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # List all registered users in HOST
5
+ # List all registered users on the ejabberd vhost.
7
6
  #
8
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#registered-users-list-all-registered-users-in-host
7
+ # @see https://bit.ly/2KhwT6Z
9
8
  class RegisteredUsers
10
- # @param [host] The Local vhost
11
- def self.call(host:)
12
- JabberAdmin::ApiCall.perform 'registered_users', host: host
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param host [String] the jabber vhost (eg. +localhost+)
13
+ def self.call(callable, host:)
14
+ callable.call('registered_users', check_res_body: false, host: host)
13
15
  end
14
16
  end
15
17
  end
@@ -2,12 +2,15 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Restart ejabberd gracefully
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#restart-restart-ejabberd-gracefully
5
+ # Restart ejabberd service gracefully.
6
+ #
7
+ # @see https://bit.ly/2G7YEwd
8
8
  class Restart
9
- def self.call
10
- JabberAdmin::ApiCall.perform 'restart'
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ def self.call(callable)
13
+ callable.call('restart')
11
14
  end
12
15
  end
13
16
  end
@@ -2,23 +2,26 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Password and Message can also be: none. Users JIDs are separated with :
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#send-direct-invitation-send-a-direct-invitation-to-several-destinations
5
+ # Send a direct invitation to several destinations.
6
+ #
7
+ # @see https://bit.ly/2wuTpr2
8
8
  class SendDirectInvitation
9
- # @param [name] The room name
10
- # @param [service] MUC service
11
- # @param [password] Password, or none
12
- # @param [reason] The reason text, or none
13
- # @param [users] Users JIDs
14
- def self.call(name:, service:, password:, reason:, users:)
15
- joined_users = users.join(':')
16
-
17
- JabberAdmin::ApiCall.perform(
18
- 'send_direct_invitation',
19
- name: name, service: service, password: password, reason: reason,
20
- users: joined_users
21
- )
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param room [String] room JID (eg. +room1@conference.localhost+)
13
+ # @param users [Array<String>] user JIDs wo/ resource
14
+ # (eg. +tom@localhost+)
15
+ # @param password [String] a optional room password
16
+ # @param reason [String] the reason for the invitation
17
+ def self.call(callable, room:, users:, password: '', reason: '')
18
+ name, service = room.split('@')
19
+ callable.call('send_direct_invitation',
20
+ name: name,
21
+ service: service,
22
+ password: password,
23
+ reason: reason,
24
+ users: users.join(':'))
22
25
  end
23
26
  end
24
27
  end
@@ -2,17 +2,19 @@
2
2
 
3
3
  module JabberAdmin
4
4
  module Commands
5
- ##
6
- # Password and Message can also be: none. Users JIDs are separated with :
7
- # https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#send-direct-invitation-send-a-direct-invitation-to-several-destinations
5
+ # Send a stanza; provide From JID and valid To JID.
6
+ #
7
+ # @see https://bit.ly/2rzxyK1
8
8
  class SendStanza
9
- # @param [from] Sender JID
10
- # @param [to] Receiver JID
11
- # @param [stanza] Stanza
12
- def self.call(from:, to:, stanza:)
13
- JabberAdmin::ApiCall.perform(
14
- 'send_stanza', to: to, from: from, stanza: stanza
15
- )
9
+ # Pass the correct data to the given callable.
10
+ #
11
+ # @param callable [Proc, #call] the callable to call
12
+ # @param from [String] user JID wo/ resource (eg. +tom@localhost+)
13
+ # @param to [String] user/room JID wo/ resource (eg. +bob@localhost+)
14
+ # @param stanza [String] the XML stanz to send
15
+ # (eg. <tt><message><ext attr='value'/></message></tt>)
16
+ def self.call(callable, from:, to:, stanza:)
17
+ callable.call('send_stanza', from: from, to: to, stanza: stanza)
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ # Send a message (stanza) as if sent from a c2s session.
6
+ #
7
+ # @see https://bit.ly/2wwUcYr
8
+ class SendStanzaC2s
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/bot+)
13
+ # @param stanza [String] the XML stanz to send
14
+ # (eg. <tt><message to='user1@localhost'>
15
+ # <ext attr='value'/></message></tt>)
16
+ def self.call(callable, user:, stanza:)
17
+ uid, host = user.split('@')
18
+ host, resource = host.split('/')
19
+ resource ||= 'bot'
20
+ callable.call('send_stanza_c2s',
21
+ user: uid,
22
+ host: host,
23
+ resource: resource,
24
+ stanza: stanza)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ # Set nickname in a user's vCard.
6
+ #
7
+ # @see https://bit.ly/2rBdyqc
8
+ class SetNickname
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
+ # @param nick [String] the user nickname (eg. +TomTom+)
14
+ def self.call(callable, user:, nick:)
15
+ uid, host = user.split('@')
16
+ callable.call(
17
+ 'set_nickname', user: uid, host: host, nickname: nick
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JabberAdmin
4
+ module Commands
5
+ # Send a stanza; provide From JID and valid To JID.
6
+ #
7
+ # @see https://bit.ly/2rzxyK1
8
+ class SetPresence
9
+ # @param callable [Proc, #call] the callable to call
10
+ # @param user [String] user JID w/ resource (eg. +tom@localhost/bot+)
11
+ # @param type [String] the presence type
12
+ # (eg. +available+, +error+, +probe+)
13
+ # @param show [String] the showed presence
14
+ # (eg. +away+, +chat+, +dnd+, +xa+)
15
+ # @param status [String] the user status (eg. +I'm online+)
16
+ # @param priority [String] presence priority (eg. +7+)
17
+ #
18
+ # rubocop:disable Metrics/ParameterLists because of the mapping
19
+ # rubocop:disable Metrics/MethodLength because of the mapping
20
+ def self.call(callable, user:, type: 'available', show: 'chat',
21
+ status: '', priority: '7')
22
+ uid, host = user.split('@')
23
+ host, resource = host.split('/')
24
+ resource ||= 'bot'
25
+ callable.call('set_presence',
26
+ user: uid,
27
+ host: host,
28
+ resource: resource,
29
+ type: type,
30
+ show: show,
31
+ status: status,
32
+ priority: priority)
33
+ end
34
+ # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
35
+ end
36
+ end
37
+ end
@@ -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
@@ -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