jabber_admin 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/jabber_admin.gemspec +1 -0
- data/lib/jabber_admin/version.rb +1 -1
- data/lib/jabber_admin.rb +102 -86
- metadata +17 -4
- data/lib/jabber_admin/commands.rb +0 -11
- /data/lib/jabber_admin/{exceptions.rb → errors.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fa0d27d4b8c2a0a59245d30cde035edc63b28e470d015d33b00ef966f28de4d
|
4
|
+
data.tar.gz: 14799e6fdadf03f199e1e80832f9b471843a3d4e9c994043ade9cb20e64ba314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c719550407ca39da92b3b6c6ac08b0c38e5f3aa57c92128ea9f6f29170fc2cec6ebb10a9abea605d09587fa9f2f21c1b3f9c9a897e8572fd4823e32bb3d664a2
|
7
|
+
data.tar.gz: e6ce78a3ccc5504266bb2c10b7180d7f4b8d679069b658a6a0340e7708afed11b81cb311c113eab5bfc43e176803f7a516e5e9f451f4b7f0b91240e35e3306f5
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
* TODO: Replace this bullet point with an actual description of a change.
|
4
4
|
|
5
|
+
### 1.5.1 (17 January 2025)
|
6
|
+
|
7
|
+
* Added the logger dependency (#17)
|
8
|
+
|
9
|
+
### 1.5.0 (12 January 2025)
|
10
|
+
|
11
|
+
* Switched to Zeitwerk as autoloader (#16)
|
12
|
+
|
5
13
|
### 1.4.0 (3 January 2025)
|
6
14
|
|
7
15
|
* Raised minimum supported Ruby/Rails version to 2.7/6.1 (#15)
|
data/jabber_admin.gemspec
CHANGED
data/lib/jabber_admin/version.rb
CHANGED
data/lib/jabber_admin.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'zeitwerk'
|
4
|
+
require 'logger'
|
3
5
|
require 'active_support/inflector'
|
4
6
|
require 'json'
|
5
7
|
require 'pathname'
|
6
8
|
require 'rest-client'
|
7
9
|
|
8
|
-
require 'jabber_admin/exceptions'
|
9
|
-
require 'jabber_admin/configuration'
|
10
|
-
require 'jabber_admin/commands'
|
11
|
-
require 'jabber_admin/api_call'
|
12
|
-
require 'jabber_admin/version'
|
13
|
-
|
14
10
|
# jabber_admin
|
15
11
|
#
|
16
12
|
# This gem allows making API calls to the ejabberd RESTful admin backend. We
|
@@ -53,96 +49,116 @@ require 'jabber_admin/version'
|
|
53
49
|
# @example Delete a user from the XMPP service, in fire and forget manner
|
54
50
|
# JabberAdmin.unregister user: 'peter@example.com'
|
55
51
|
module JabberAdmin
|
52
|
+
# Configure the relative gem code base location
|
53
|
+
root_path = Pathname.new("#{__dir__}/jabber_admin")
|
54
|
+
|
55
|
+
# Setup a Zeitwerk autoloader instance and configure it
|
56
|
+
loader = Zeitwerk::Loader.for_gem
|
57
|
+
|
58
|
+
# Do not auto load some parts of the gem
|
59
|
+
loader.ignore(root_path.join('errors.rb'))
|
60
|
+
|
61
|
+
# Finish the auto loader configuration
|
62
|
+
loader.setup
|
63
|
+
|
64
|
+
# Load standalone code
|
65
|
+
require 'jabber_admin/version'
|
66
|
+
require 'jabber_admin/errors'
|
67
|
+
|
68
|
+
# Make sure to eager load all constants
|
69
|
+
loader.eager_load
|
70
|
+
|
56
71
|
class << self
|
57
72
|
attr_writer :configuration
|
58
|
-
end
|
59
73
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
# A simple getter to the global JabberAdmin configuration structure.
|
75
|
+
#
|
76
|
+
# @return [JabberAdmin::Configuration] the global JabberAdmin configuration
|
77
|
+
def configuration
|
78
|
+
@configuration ||= Configuration.new
|
79
|
+
end
|
66
80
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
81
|
+
# Class method to set and change the global configuration. This is just a
|
82
|
+
# tapped variant of the +.configuration+ method.
|
83
|
+
#
|
84
|
+
# @yield [configuration]
|
85
|
+
# @yieldparam [JabberAdmin::Configuration] configuration
|
86
|
+
def configure
|
87
|
+
yield(configuration)
|
88
|
+
end
|
75
89
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
# Allow an easy to use DSL on the +JabberAdmin+ module. We support
|
91
|
+
# predefined (known) commands and unknown ones in bang and non-bang
|
92
|
+
# variants. This allows maximum flexibility to the user. The bang versions
|
93
|
+
# perform the response checks and raise in case of issues. The non-bang
|
94
|
+
# versions skip this checks. For unknown commands the
|
95
|
+
# +JabberAdmin::ApiCall+ is directly utilized with the method name as
|
96
|
+
# command. (Without the trailling bang, when it is present)
|
97
|
+
#
|
98
|
+
# @param method [Symbol, String, #to_s] the name of the command to run
|
99
|
+
# @param args [Array<Mixed>] all additional API call payload
|
100
|
+
# @param kwargs [Hash{Symbol => Mixed}] all additional API call payload
|
101
|
+
# @return [RestClient::Response] the actual response of the command
|
102
|
+
def method_missing(method, *args, **kwargs)
|
103
|
+
predefined_command(method).call(
|
104
|
+
predefined_callable(method), *args, **kwargs
|
105
|
+
)
|
106
|
+
rescue NameError
|
107
|
+
predefined_callable(method).call(method.to_s.chomp('!'), *args, **kwargs)
|
108
|
+
end
|
95
109
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
110
|
+
# Try to find the given name as a predefined command. When there is no such
|
111
|
+
# predefined command, we raise a +NameError+.
|
112
|
+
#
|
113
|
+
# @param name [Symbol, String, #to_s] the command name to lookup
|
114
|
+
# @return [Class] the predefined command class constant
|
115
|
+
def predefined_command(name)
|
116
|
+
# Remove bangs and build the camel case variant
|
117
|
+
"JabberAdmin::Commands::#{name.to_s.chomp('!').camelize}".constantize
|
118
|
+
end
|
105
119
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
+
# Generate a matching API call wrapper for the given command name. When we
|
121
|
+
# have to deal with a bang version, we pass the bang down to the API call
|
122
|
+
# instance. Otherwise we just run the regular +#perform+ method on the API
|
123
|
+
# call instance.
|
124
|
+
#
|
125
|
+
# @param name [Symbol, String, #to_s] the command name to match
|
126
|
+
# @return [Proc] the API call wrapper
|
127
|
+
def predefined_callable(name)
|
128
|
+
method = name.to_s.end_with?('!') ? 'perform!' : 'perform'
|
129
|
+
proc do |*args, **kwargs|
|
130
|
+
if kwargs.empty?
|
131
|
+
ApiCall.send(method, *args)
|
132
|
+
else
|
133
|
+
ApiCall.send(method, *args, **kwargs)
|
134
|
+
end
|
120
135
|
end
|
121
136
|
end
|
122
|
-
end
|
123
137
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
false
|
137
|
-
end
|
138
|
+
# Determine if a room exists. This is a convenience method for the
|
139
|
+
# +JabberAdmin::Commands::GetRoomAffiliations+ command, which can be used
|
140
|
+
# to reliably determine whether a room exists or not.
|
141
|
+
#
|
142
|
+
# @param room [String] the name of the room to check
|
143
|
+
# @return [Boolean] whether the room exists or not
|
144
|
+
def room_exist?(room)
|
145
|
+
get_room_affiliations!(room: room)
|
146
|
+
true
|
147
|
+
rescue JabberAdmin::CommandError => e
|
148
|
+
raise e unless /room does not exist/.match? e.response.body
|
138
149
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
150
|
+
false
|
151
|
+
end
|
152
|
+
|
153
|
+
# We support all methods if you ask for. This is our dynamic command
|
154
|
+
# approach here to support predefined and custom commands in the same
|
155
|
+
# namespace.
|
156
|
+
#
|
157
|
+
# @param method [String] the method to lookup
|
158
|
+
# @param include_private [Boolean] allow the lookup of private methods
|
159
|
+
# @return [Boolean] always +true+
|
160
|
+
def respond_to_missing?(_method, _include_private = false)
|
161
|
+
true
|
162
|
+
end
|
147
163
|
end
|
148
164
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jabber_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hermann Mayer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-01-
|
12
|
+
date: 2025-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '2.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: zeitwerk
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.6'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.6'
|
42
56
|
description: Library for the ejabberd RESTful admin API
|
43
57
|
email:
|
44
58
|
- hermann.mayer92@gmail.com
|
@@ -79,7 +93,6 @@ files:
|
|
79
93
|
- jabber_admin.gemspec
|
80
94
|
- lib/jabber_admin.rb
|
81
95
|
- lib/jabber_admin/api_call.rb
|
82
|
-
- lib/jabber_admin/commands.rb
|
83
96
|
- lib/jabber_admin/commands/ban_account.rb
|
84
97
|
- lib/jabber_admin/commands/create_room.rb
|
85
98
|
- lib/jabber_admin/commands/create_room_with_opts.rb
|
@@ -101,7 +114,7 @@ files:
|
|
101
114
|
- lib/jabber_admin/commands/unregister.rb
|
102
115
|
- lib/jabber_admin/commands/unsubscribe_room.rb
|
103
116
|
- lib/jabber_admin/configuration.rb
|
104
|
-
- lib/jabber_admin/
|
117
|
+
- lib/jabber_admin/errors.rb
|
105
118
|
- lib/jabber_admin/version.rb
|
106
119
|
homepage:
|
107
120
|
licenses:
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module JabberAdmin
|
4
|
-
# Contains all predefined commands that are supported.
|
5
|
-
module Commands; end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Require all commands from the commands subfolder
|
9
|
-
Dir[Pathname.new(__dir__).join('commands', '**', '*.rb')].sort.each do |file|
|
10
|
-
require file
|
11
|
-
end
|
File without changes
|