lib/jabber_admin.rb in jabber_admin-1.0.4 vs lib/jabber_admin.rb in jabber_admin-1.0.5
- old
+ new
@@ -110,9 +110,24 @@
def self.predefined_callable(name)
method = name.to_s.end_with?('!') ? 'perform!' : 'perform'
proc { |*args| ApiCall.send(method, *args) }
end
+ # 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.
+ #
+ # @param room [String] the name of the room to check
+ # @return [Boolean] whether the room exists or not
+ 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
+
# 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.
#
# @param method [String] the method to lookup
# @param include_private [Boolean] allow the lookup of private methods