Class: Jabber::Protocol::Presence

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber4r/protocol/presence.rb

Overview

The presence class is used to construct presence messages to send to the Jabber service.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, show = nil, status = nil) ⇒ Presence

Constructs a Presence object w/the supplied id

id
String

The message ID

show
String

The state to show

status
String

The status message



29
30
31
32
33
# File 'lib/jabber4r/protocol/presence.rb', line 29

def initialize(id, show=nil, status=nil)
  @id = id
  @show = show if show
  @status = status if status
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



13
14
15
# File 'lib/jabber4r/protocol/presence.rb', line 13

def from
  @from
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/jabber4r/protocol/presence.rb', line 13

def id
  @id
end

#priorityObject

Returns the value of attribute priority.



20
21
22
# File 'lib/jabber4r/protocol/presence.rb', line 20

def priority
  @priority
end

#showObject

The state to show (chat, xa, dnd, away)



16
17
18
# File 'lib/jabber4r/protocol/presence.rb', line 16

def show
  @show
end

#statusObject

The status message



19
20
21
# File 'lib/jabber4r/protocol/presence.rb', line 19

def status
  @status
end

#toObject

Returns the value of attribute to.



13
14
15
# File 'lib/jabber4r/protocol/presence.rb', line 13

def to
  @to
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/jabber4r/protocol/presence.rb', line 13

def type
  @type
end

Class Method Details

.gen_accept_subscription(id, jid) ⇒ Object



122
123
124
125
126
127
# File 'lib/jabber4r/protocol/presence.rb', line 122

def self.gen_accept_subscription(id, jid)
  p = Presence.new(id)
  p.type = "subscribed"
  p.to = jid
  p
end

.gen_accept_unsubscription(id, jid) ⇒ Object



129
130
131
132
133
134
# File 'lib/jabber4r/protocol/presence.rb', line 129

def self.gen_accept_unsubscription(id, jid)
  p = Presence.new(id)
  p.type = "unsubscribed"
  p.to = jid
  p
end

.gen_away(id, status = nil) ⇒ Object

Generate a presence object w/show=“away” (away from resource)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



98
99
100
# File 'lib/jabber4r/protocol/presence.rb', line 98

def self.gen_away(id, status=nil)
  Presence.new(id, "away", status)
end

.gen_chat(id, status = nil) ⇒ Object

Generate a presence object w/show=“chat” (free for chat)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



65
66
67
# File 'lib/jabber4r/protocol/presence.rb', line 65

def self.gen_chat(id, status=nil)
  Presence.new(id, "chat", status)
end

.gen_dnd(id, status = nil) ⇒ Object

Generate a presence object w/show=“dnd” (do not disturb)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



87
88
89
# File 'lib/jabber4r/protocol/presence.rb', line 87

def self.gen_dnd(id, status=nil)
  Presence.new(id, "dnd", status)
end

.gen_initial(id, show = nil, status = nil) ⇒ Object

Generate a presence object for initial presence notification

id
String

The message ID

show
String

The state to show

status
String

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



43
44
45
# File 'lib/jabber4r/protocol/presence.rb', line 43

def self.gen_initial(id, show=nil, status=nil)
  Presence.new(id, show, status)
end

.gen_new_subscription(to) ⇒ Object



115
116
117
118
119
120
# File 'lib/jabber4r/protocol/presence.rb', line 115

def self.gen_new_subscription(to)
  p = Presence.new(Jabber.gen_random_id)
  p.type = "subscribe"
  p.to = to
  p
end

.gen_normal(id, status = nil) ⇒ Object

Generate a presence object w/show=“normal” (normal availability)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



54
55
56
# File 'lib/jabber4r/protocol/presence.rb', line 54

def self.gen_normal(id, status=nil)
  Presence.new(id, "normal", status)
end

.gen_unavailable(id, status = nil) ⇒ Object

Generate a presence object w/show=“unavailable” (not free for chat)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



109
110
111
112
113
# File 'lib/jabber4r/protocol/presence.rb', line 109

def self.gen_unavailable(id, status=nil)
  p = Presence.new(id)
  p.type="unavailable"
  p
end

.gen_xa(id, status = nil) ⇒ Object

Generate a presence object w/show=“xa” (extended away)

id
String

The message ID

status
String=nil

The status message

return
Jabber::Protocol::Presence

The newly created Presence object



76
77
78
# File 'lib/jabber4r/protocol/presence.rb', line 76

def self.gen_xa(id, status=nil)
  Presence.new(id, "xa", status)
end

Instance Method Details

#to_sObject

see _to_xml



156
157
158
# File 'lib/jabber4r/protocol/presence.rb', line 156

def to_s
  to_xml
end

#to_xmlObject

Generates the xml representation of this Presence object

return
String

The presence XML message to send the Jabber service



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jabber4r/protocol/presence.rb', line 141

def to_xml
  e = XMLElement.new("presence")
  e.add_attribute("id", @id) if @id
  e.add_attribute("from", @from) if @from
  e.add_attribute("to", @to) if @to
  e.add_attribute("type", @type) if @type
  e.add_child("show").add_data(@show) if @show
  e.add_child("status").add_data(@status) if @status
  e.add_child("priority") if @priority
  e.to_s
end