Class: Jabber::Observable::Contact

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

Overview

Jabber::Observable::Contact - Convenience subclass to deal with Contacts

Instance Method Summary collapse

Constructor Details

#initialize(jid, observable) ⇒ Contact

Creates a new Jabber::Observable::Contact

jid

jid to be used

observable

observable to be used


16
17
18
19
# File 'lib/xmpp4r/observable/contact.rb', line 16

def initialize(jid, observable)
  @jid = jid.respond_to?(:resource) ? jid : JID.new(jid)
  @observable = observable
end

Instance Method Details

#ask_for_authorization!Object

Send a request asking for authorization


41
42
43
# File 'lib/xmpp4r/observable/contact.rb', line 41

def ask_for_authorization!
  request!(:subscribe)
end

#inspectObject

:nodoc:


24
25
26
# File 'lib/xmpp4r/observable/contact.rb', line 24

def inspect #:nodoc:
  sprintf("#<%s:0x%x @jid=%s>", self.class.name, __id__, @jid.to_s)
end

#jidObject

Returns the stripped version of the JID


22
# File 'lib/xmpp4r/observable/contact.rb', line 22

def jid; @jid.strip; end

#subscribed?Boolean

Are e subscribed?

Returns:

  • (Boolean)

29
30
31
# File 'lib/xmpp4r/observable/contact.rb', line 29

def subscribed?
  [:to, :both].include?(subscription)
end

#subscriptionObject

Get the subscription from the roster_item


34
35
36
37
38
# File 'lib/xmpp4r/observable/contact.rb', line 34

def subscription
  items = @observable.roster.items
  return false unless items.include?(jid)
  items[jid].subscription
end

#unsubscribe!Object

Sends a request asking for unsubscription


46
47
48
# File 'lib/xmpp4r/observable/contact.rb', line 46

def unsubscribe!
  request!(:unsubscribe)
end