Class: Jabber::Observable::Subscriptions
- Inherits:
-
Object
- Object
- Jabber::Observable::Subscriptions
- 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
-
#accept=(accept_status) ⇒ Object
Change whether or not subscriptions (friend requests) are automatically accepted.
-
#accept? ⇒ Boolean
Returns true if auto-accept subscriptions (friend requests) is enabled (default), false otherwise.
-
#add(*jids) ⇒ Object
Ask the users specified by jids for authorization (i.e., ask them to add you to their contact list).
-
#initialize(observable) ⇒ Subscriptions
constructor
A new instance of Subscriptions.
-
#remove(*jids) ⇒ Object
Remove the jabber users specified by jids from the contact list.
-
#subscribed_to?(jid) ⇒ Boolean
Returns true if this Jabber account is subscribed to status updates for the jabber user jid, false otherwise.
Constructor Details
#initialize(observable) ⇒ Subscriptions
Returns a new instance of Subscriptions.
355 356 357 |
# File 'lib/xmpp4r-observable.rb', line 355 def initialize(observable) @observable = observable end |
Instance Method Details
#accept=(accept_status) ⇒ Object
Change whether or not subscriptions (friend requests) are automatically accepted.
401 402 403 |
# File 'lib/xmpp4r-observable.rb', line 401 def accept=(accept_status) @accept=accept_status end |
#accept? ⇒ Boolean
Returns true if auto-accept subscriptions (friend requests) is enabled (default), false otherwise.
395 396 397 398 |
# File 'lib/xmpp4r-observable.rb', line 395 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
371 372 373 374 375 376 |
# File 'lib/xmpp4r-observable.rb', line 371 def add(*jids) @observable.contacts(*jids) do |friend| next if subscribed_to? friend friend. end end |
#remove(*jids) ⇒ Object
Remove the jabber users specified by jids from the contact list.
379 380 381 382 383 |
# File 'lib/xmpp4r-observable.rb', line 379 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.
387 388 389 390 391 |
# File 'lib/xmpp4r-observable.rb', line 387 def subscribed_to?(jid) @observable.contacts(jid) do |contact| return contact.subscribed? end end |