Class: Jabber::Contact

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(client, jid) ⇒ Contact

Returns a new instance of Contact.



43
44
45
46
# File 'lib/xmpp4r-observable.rb', line 43

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

Instance Method Details

#ask_for_authorization!Object



60
61
62
63
64
# File 'lib/xmpp4r-observable.rb', line 60

def ask_for_authorization!
	subscription_request = Jabber::Presence.new.set_type(:subscribe)
	subscription_request.to = jid
	client.send!(subscription_request)
end

#inspectObject



48
49
50
# File 'lib/xmpp4r-observable.rb', line 48

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

#jid(bare = true) ⇒ Object



73
74
75
# File 'lib/xmpp4r-observable.rb', line 73

def jid(bare=true)
	bare ? @jid.strip : @jid
end

#subscribed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/xmpp4r-observable.rb', line 52

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

#subscriptionObject



56
57
58
# File 'lib/xmpp4r-observable.rb', line 56

def subscription
	roster_item && roster_item.subscription
end

#unsubscribe!Object



66
67
68
69
70
71
# File 'lib/xmpp4r-observable.rb', line 66

def unsubscribe!
	unsubscription_request = Jabber::Presence.new.set_type(:unsubscribe)
	unsubscription_request.to = jid
	client.send!(unsubscription_request)
	client.send!(unsubscription_request.set_type(:unsubscribed))
end