Class Jabber::Simple
In: lib/xmpp4r-simple.rb
Parent: Object

Methods

Included Modules

DRb::DRbUndumped

Public Class methods

Create a new Jabber::Simple client. You will be automatically connected to the Jabber server and your status message will be set to the string passed in as the status_message argument.

jabber = Jabber::Simple.new("me@example.com", "password", "Chat with me - Please!")

Public Instance methods

Change whether or not subscriptions (friend requests) are automatically accepted.

Returns true if auto-accept subscriptions (friend requests) is enabled (default), false otherwise.

Ask the users specified by jids for authorization (i.e., ask them to add you to their contact list). If you are already in the user‘s contact list, add() will not attempt to re-request authorization. In order to force re-authorization, first remove() the user, then re-add them.

Example usage:

  jabber_simple.add("friend@friendosaurus.com")

Because the authorization process might take a few seconds, or might never happen depending on when (and if) the user accepts your request, results are placed in the Jabber::Simple#new_subscriptions queue.

Direct access to the underlying Jabber client.

Returns true if the Jabber client is connected to the Jabber server, false otherwise.

If contacts is a single contact, returns a Jabber::Contact object representing that user; if contacts is an array, returns an array of Jabber::Contact objects.

When called with a block, contacts will yield each Jabber::Contact object in turn. This is mainly used internally, but exposed as an utility function.

Send a message to jabber user jid.

Valid message types are:

  * :normal (default): a normal message.
  * :chat: a one-to-one chat message.
  * :groupchat: a group-chat message.
  * :headline: a "headline" message.
  * :error: an error message.

If the recipient is not in your contacts list, the message will be queued for later delivery, and the Contact will be automatically asked for authorization (see Jabber::Simple#add).

message should be a string or a valid Jabber::Message object. In either case, the message recipient will be set to jid.

Queue messages for delivery once a user has accepted our authorization request. Works in conjunction with the deferred delivery thread.

You can use this method if you want to manually add friends and still have the message queued for later delivery.

Use this to force the client to disconnect and not automatically reconnect.

Returns an array of subscription notifications received since the last time new_subscriptions was called. Passing a block will yield each update in turn, allowing you to break part-way through processing (especially useful when your subscription handling code is not thread-safe (e.g., ActiveRecord).

e.g.:

  jabber.new_subscriptions do |friend, presence|
    puts "Received presence update from #{friend.to_s}: #{presence}"
  end

Returns true if there are unprocessed presence updates waiting in the queue, false otherwise.

Returns an array of presence updates received since the last time presence_updates was called. Passing a block will yield each update in turn, allowing you to break part-way through processing (especially useful when your presence handling code is not thread-safe (e.g., ActiveRecord).

e.g.:

  jabber.presence_updates do |friend, new_presence|
    puts "Received presence update from #{friend}: #{new_presence}"
  end

Returns true if there are unprocessed presence updates waiting in the queue, false otherwise.

Returns an array of messages received since the last time received_messages was called. Passing a block will yield each message in turn, allowing you to break part-way through processing (especially useful when your message handling code is not thread-safe (e.g., ActiveRecord).

e.g.:

  jabber.received_messages do |message|
    puts "Received message from #{message.from}: #{message.body}"
  end

Returns true if there are unprocessed received messages waiting in the queue, false otherwise.

Use this to force the client to reconnect after a force_disconnect.

Remove the jabber users specified by jids from the contact list.

Direct access to the underlying Roster helper.

Send a Jabber stanza over-the-wire.

Set your presence, with a message.

Available values for presence are:

  * nil: online.
  * :chat: free for chat.
  * :away: away from the computer.
  * :dnd: do not disturb.
  * :xa: extended away.

It‘s not possible to set an offline status - to do that, disconnect! :-)

Returns true if this Jabber account is subscribed to status updates for the jabber user jid, false otherwise.

Returns an array of subscription notifications received since the last time subscription_requests was called. Passing a block will yield each update in turn, allowing you to break part-way through processing (especially useful when your subscription handling code is not thread-safe (e.g., ActiveRecord).

e.g.:

  jabber.subscription_requests do |friend, presence|
    puts "Received presence update from #{friend.to_s}: #{presence}"
  end

[Validate]