Module: JabberAdmin
- Defined in:
- lib/jabber_admin.rb,
lib/jabber_admin/errors.rb,
lib/jabber_admin/version.rb,
lib/jabber_admin/api_call.rb,
lib/jabber_admin/configuration.rb,
lib/jabber_admin/commands/restart.rb,
lib/jabber_admin/commands/register.rb,
lib/jabber_admin/commands/get_vcard.rb,
lib/jabber_admin/commands/set_vcard.rb,
lib/jabber_admin/commands/unregister.rb,
lib/jabber_admin/commands/ban_account.rb,
lib/jabber_admin/commands/create_room.rb,
lib/jabber_admin/commands/send_stanza.rb,
lib/jabber_admin/commands/destroy_room.rb,
lib/jabber_admin/commands/set_nickname.rb,
lib/jabber_admin/commands/set_presence.rb,
lib/jabber_admin/commands/subscribe_room.rb,
lib/jabber_admin/commands/send_stanza_c2s.rb,
lib/jabber_admin/commands/registered_users.rb,
lib/jabber_admin/commands/unsubscribe_room.rb,
lib/jabber_admin/commands/muc_register_nick.rb,
lib/jabber_admin/commands/set_room_affiliation.rb,
lib/jabber_admin/commands/create_room_with_opts.rb,
lib/jabber_admin/commands/get_room_affiliations.rb,
lib/jabber_admin/commands/send_direct_invitation.rb
Overview
The gem version details.
Defined Under Namespace
Modules: Commands Classes: ApiCall, CommandError, Configuration, Error, RequestError, UnknownCommandError
Constant Summary collapse
- VERSION =
The version of the
jabber_admingem '2.1.0'
Class Attribute Summary collapse
-
.configuration ⇒ JabberAdmin::Configuration
A simple getter to the global JabberAdmin configuration structure.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Class method to set and change the global configuration.
-
.gem_version ⇒ Gem::Version
Returns the version of the gem as a
Gem::Version. -
.method_missing(method) ⇒ RestClient::Response
Allow an easy to use DSL on the
JabberAdminmodule. -
.predefined_callable(name) ⇒ Proc
Generate a matching API call wrapper for the given command name.
-
.predefined_command(name) ⇒ Class
Try to find the given name as a predefined command.
-
.respond_to_missing?(_method, _include_private = false) ⇒ Boolean
We support all methods if you ask for.
-
.room_exist?(room) ⇒ Boolean
Determine if a room exists.
-
.version ⇒ String
Returns the version of gem as a string.
Class Attribute Details
.configuration ⇒ JabberAdmin::Configuration
A simple getter to the global JabberAdmin configuration structure.
77 78 79 |
# File 'lib/jabber_admin.rb', line 77 def configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
Class method to set and change the global configuration. This is just a tapped variant of the .configuration method.
86 87 88 |
# File 'lib/jabber_admin.rb', line 86 def configure yield(configuration) end |
.gem_version ⇒ Gem::Version
Returns the version of the gem as a Gem::Version.
19 20 21 |
# File 'lib/jabber_admin/version.rb', line 19 def gem_version Gem::Version.new VERSION end |
.method_missing(method) ⇒ RestClient::Response
Allow an easy to use DSL on the JabberAdmin module. We support predefined (known) commands and unknown ones in bang and non-bang variants. This allows maximum flexibility to the user. The bang versions perform the response checks and raise in case of issues. The non-bang versions skip this checks. For unknown commands the JabberAdmin::ApiCall is directly utilized with the method name as command. (Without the trailling bang, when it is present)
102 103 104 105 106 107 108 |
# File 'lib/jabber_admin.rb', line 102 def method_missing(method, *, **) predefined_command(method).call( predefined_callable(method), *, ** ) rescue NameError predefined_callable(method).call(method.to_s.chomp('!'), *, **) end |
.predefined_callable(name) ⇒ Proc
Generate a matching API call wrapper for the given command name. When we have to deal with a bang version, we pass the bang down to the API call instance. Otherwise we just run the regular #perform method on the API call instance.
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/jabber_admin.rb', line 127 def predefined_callable(name) method = name.to_s.end_with?('!') ? 'perform!' : 'perform' proc do |*args, **kwargs| if kwargs.empty? ApiCall.send(method, *args) else ApiCall.send(method, *args, **kwargs) end end end |
.predefined_command(name) ⇒ Class
Try to find the given name as a predefined command. When there is no such predefined command, we raise a NameError.
115 116 117 118 |
# File 'lib/jabber_admin.rb', line 115 def predefined_command(name) # Remove bangs and build the camel case variant "JabberAdmin::Commands::#{name.to_s.chomp('!').camelize}".constantize end |
.respond_to_missing?(_method, _include_private = false) ⇒ Boolean
We support all methods if you ask for. This is our dynamic command approach here to support predefined and custom commands in the same namespace.
160 161 162 |
# File 'lib/jabber_admin.rb', line 160 def respond_to_missing?(_method, _include_private = false) true end |
.room_exist?(room) ⇒ Boolean
Determine if a room exists. This is a convenience method for the JabberAdmin::Commands::GetRoomAffiliations command, which can be used to reliably determine whether a room exists or not.
144 145 146 147 148 149 150 151 |
# File 'lib/jabber_admin.rb', line 144 def room_exist?(room) get_room_affiliations!(room: room) true rescue JabberAdmin::CommandError => e raise e unless /room does not exist/.match? e.response.body false end |
.version ⇒ String
Returns the version of gem as a string.
12 13 14 |
# File 'lib/jabber_admin/version.rb', line 12 def version VERSION end |