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.
260 261 262 |
# File 'lib/xmpp4r-observable.rb', line 260 def initialize(observable) @observable = observable end |
Instance Method Details
#accept=(accept_status) ⇒ Object
Change whether or not subscriptions (friend requests) are automatically accepted.
306 307 308 |
# File 'lib/xmpp4r-observable.rb', line 306 def accept=(accept_status) @accept=accept_status end |
#accept? ⇒ Boolean
Returns true if auto-accept subscriptions (friend requests) is enabled (default), false otherwise.
300 301 302 303 |
# File 'lib/xmpp4r-observable.rb', line 300 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
276 277 278 279 280 281 |
# File 'lib/xmpp4r-observable.rb', line 276 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.
284 285 286 287 288 |
# File 'lib/xmpp4r-observable.rb', line 284 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.
292 293 294 295 296 |
# File 'lib/xmpp4r-observable.rb', line 292 def subscribed_to?(jid) @observable.contacts(jid) do |contact| return contact.subscribed? end end |