Class: Jabber::Observable::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpp4r-observable.rb

Overview

Jabber::Observable::Subscriptions - convenience class to deal with Presence subscriptions

observable

points to a Jabber::Observable object

Instance Method Summary collapse

Constructor Details

#initialize(observable) ⇒ Subscriptions

Returns a new instance of Subscriptions.



321
322
323
# File 'lib/xmpp4r-observable.rb', line 321

def initialize(observable)
	@observable = observable
end

Instance Method Details

#accept=(accept_status) ⇒ Object

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



367
368
369
# File 'lib/xmpp4r-observable.rb', line 367

def accept=(accept_status)
	@accept=accept_status
end

#accept?Boolean

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

Returns:

  • (Boolean)


361
362
363
364
# File 'lib/xmpp4r-observable.rb', line 361

def accept?
	@accept = true if @accept.nil?
	@accept
end

#add(*jids) ⇒ Object

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_observable.subs.add("[email protected]")

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 notified to observers of :new_subscription



337
338
339
340
341
342
# File 'lib/xmpp4r-observable.rb', line 337

def add(*jids)
	@observable.contacts(*jids) do |friend|
		next if subscribed_to? friend
		friend.ask_for_authorization!
	end
end

#remove(*jids) ⇒ Object

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



345
346
347
348
349
# File 'lib/xmpp4r-observable.rb', line 345

def remove(*jids)
	@observable.contacts(*jids) do |unfriend|
		unfriend.unsubscribe!
	end
end

#subscribed_to?(jid) ⇒ Boolean

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

Returns:

  • (Boolean)


353
354
355
356
357
# File 'lib/xmpp4r-observable.rb', line 353

def subscribed_to?(jid)
	@observable.contacts(jid) do |contact|
		return contact.subscribed?
	end
end