Module: JabberAdmin

Defined in:
lib/jabber_admin.rb,
lib/jabber_admin/version.rb,
lib/jabber_admin/api_call.rb,
lib/jabber_admin/commands.rb,
lib/jabber_admin/exceptions.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_admin gem

'1.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationJabberAdmin::Configuration

A simple getter to the global JabberAdmin configuration structure.

Returns:



63
64
65
# File 'lib/jabber_admin.rb', line 63

def self.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.

Yields:

Yield Parameters:



72
73
74
# File 'lib/jabber_admin.rb', line 72

def self.configure
  yield(configuration)
end

.gem_versionGem::Version

Returns the version of the gem as a Gem::Version.

Returns:

  • (Gem::Version)

    the gem version as object



19
20
21
# File 'lib/jabber_admin/version.rb', line 19

def gem_version
  Gem::Version.new VERSION
end

.method_missing(method, *args) ⇒ 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)

Parameters:

  • method (Symbol, String, #to_s)

    the name of the command to run

  • args

    all additional payload to pass down to the API call

Returns:

  • (RestClient::Response)

    the actual response of the command



87
88
89
90
91
# File 'lib/jabber_admin.rb', line 87

def self.method_missing(method, *args)
  predefined_command(method).call(predefined_callable(method), *args)
rescue NameError
  predefined_callable(method).call(method.to_s.chomp('!'), *args)
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.

Parameters:

  • name (Symbol, String, #to_s)

    the command name to match

Returns:

  • (Proc)

    the API call wrapper



110
111
112
113
# File 'lib/jabber_admin.rb', line 110

def self.predefined_callable(name)
  method = name.to_s.end_with?('!') ? 'perform!' : 'perform'
  proc { |*args| ApiCall.send(method, *args) }
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.

Parameters:

  • name (Symbol, String, #to_s)

    the command name to lookup

Returns:

  • (Class)

    the predefined command class constant



98
99
100
101
# File 'lib/jabber_admin.rb', line 98

def self.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.

Parameters:

  • method (String)

    the method to lookup

  • include_private (Boolean)

    allow the lookup of private methods

Returns:

  • (Boolean)

    always true



136
137
138
# File 'lib/jabber_admin.rb', line 136

def self.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.

Parameters:

  • room (String)

    the name of the room to check

Returns:

  • (Boolean)

    whether the room exists or not



121
122
123
124
125
126
127
128
# File 'lib/jabber_admin.rb', line 121

def self.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

.versionString

Returns the version of gem as a string.

Returns:

  • (String)

    the gem version as string



12
13
14
# File 'lib/jabber_admin/version.rb', line 12

def version
  VERSION
end