Class: Jabber::Observable::Subscriptions
- Inherits:
-
Object
- Object
- Jabber::Observable::Subscriptions
- Defined in:
- lib/xmpp4r/observable/subscription.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 are automatically accepted.
-
#accept? ⇒ Boolean
Returns true if auto-accept subscriptions 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), unless already in the 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.
13 14 15 16 |
# File 'lib/xmpp4r/observable/subscription.rb', line 13 def initialize(observable) @observable = observable @accept = true end |
Instance Method Details
#accept=(accept_status) ⇒ Object
Change whether or not subscriptions are automatically accepted.
51 52 53 |
# File 'lib/xmpp4r/observable/subscription.rb', line 51 def accept=(accept_status) @accept = accept_status end |
#accept? ⇒ Boolean
Returns true if auto-accept subscriptions is enabled (default), false otherwise.
46 47 48 |
# File 'lib/xmpp4r/observable/subscription.rb', line 46 def accept? @accept end |
#add(*jids) ⇒ Object
Ask the users specified by jids for authorization (i.e., ask them to add you to their contact list), unless already in the contact list.
Because the authorization process depends on the other user accepting your request, results are notified to observers of :new_subscription.
23 24 25 26 27 28 |
# File 'lib/xmpp4r/observable/subscription.rb', line 23 def add(*jids) @observable.contacts(*jids).each do |contact| next if subscribed_to?(contact) contact. end end |
#remove(*jids) ⇒ Object
Remove the jabber users specified by jids from the contact list.
31 32 33 34 35 |
# File 'lib/xmpp4r/observable/subscription.rb', line 31 def remove(*jids) @observable.contacts(*jids).each do |contact| contact.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.
39 40 41 42 43 |
# File 'lib/xmpp4r/observable/subscription.rb', line 39 def subscribed_to?(jid) @observable.contacts(jid).each do |contact| return contact.subscribed? end end |