Class: Jabber::Protocol::Presence
- Inherits:
-
Object
- Object
- Jabber::Protocol::Presence
- Defined in:
- lib/jabber4r/protocol.rb
Overview
The presence class is used to construct presence messages to send to the Jabber service.
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#id ⇒ Object
Returns the value of attribute id.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#show ⇒ Object
The state to show (chat, xa, dnd, away).
-
#status ⇒ Object
The status message.
-
#to ⇒ Object
Returns the value of attribute to.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .gen_accept_subscription(id, jid) ⇒ Object
- .gen_accept_unsubscription(id, jid) ⇒ Object
-
.gen_away(id, status = nil) ⇒ Object
Generate a presence object w/show=“away” (away from resource).
-
.gen_chat(id, status = nil) ⇒ Object
Generate a presence object w/show=“chat” (free for chat).
-
.gen_dnd(id, status = nil) ⇒ Object
Generate a presence object w/show=“dnd” (do not disturb).
-
.gen_initial(id, show = nil, status = nil) ⇒ Object
Generate a presence object for initial presence notification.
- .gen_new_subscription(to) ⇒ Object
-
.gen_normal(id, status = nil) ⇒ Object
Generate a presence object w/show=“normal” (normal availability).
-
.gen_unavailable(id, status = nil) ⇒ Object
Generate a presence object w/show=“unavailable” (not free for chat).
-
.gen_xa(id, status = nil) ⇒ Object
Generate a presence object w/show=“xa” (extended away).
Instance Method Summary collapse
-
#initialize(id, show = nil, status = nil) ⇒ Presence
constructor
Constructs a Presence object w/the supplied id.
-
#to_s ⇒ Object
see _to_xml.
-
#to_xml ⇒ Object
Generates the xml representation of this Presence object.
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
258 259 260 261 262 |
# File 'lib/jabber4r/protocol.rb', line 258 def initialize(id, show=nil, status=nil) @id = id @show = show if show @status = status if status end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
242 243 244 |
# File 'lib/jabber4r/protocol.rb', line 242 def from @from end |
#id ⇒ Object
Returns the value of attribute id.
242 243 244 |
# File 'lib/jabber4r/protocol.rb', line 242 def id @id end |
#priority ⇒ Object
Returns the value of attribute priority.
249 250 251 |
# File 'lib/jabber4r/protocol.rb', line 249 def priority @priority end |
#show ⇒ Object
The state to show (chat, xa, dnd, away)
245 246 247 |
# File 'lib/jabber4r/protocol.rb', line 245 def show @show end |
#status ⇒ Object
The status message
248 249 250 |
# File 'lib/jabber4r/protocol.rb', line 248 def status @status end |
#to ⇒ Object
Returns the value of attribute to.
242 243 244 |
# File 'lib/jabber4r/protocol.rb', line 242 def to @to end |
#type ⇒ Object
Returns the value of attribute type.
242 243 244 |
# File 'lib/jabber4r/protocol.rb', line 242 def type @type end |
Class Method Details
.gen_accept_subscription(id, jid) ⇒ Object
351 352 353 354 355 356 |
# File 'lib/jabber4r/protocol.rb', line 351 def Presence.gen_accept_subscription(id, jid) p = Presence.new(id) p.type = "subscribed" p.to = jid p end |
.gen_accept_unsubscription(id, jid) ⇒ Object
358 359 360 361 362 363 |
# File 'lib/jabber4r/protocol.rb', line 358 def Presence.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
327 328 329 |
# File 'lib/jabber4r/protocol.rb', line 327 def Presence.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
294 295 296 |
# File 'lib/jabber4r/protocol.rb', line 294 def Presence.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
316 317 318 |
# File 'lib/jabber4r/protocol.rb', line 316 def Presence.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
272 273 274 |
# File 'lib/jabber4r/protocol.rb', line 272 def Presence.gen_initial(id, show=nil, status=nil) Presence.new(id, show, status) end |
.gen_new_subscription(to) ⇒ Object
344 345 346 347 348 349 |
# File 'lib/jabber4r/protocol.rb', line 344 def Presence.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
283 284 285 |
# File 'lib/jabber4r/protocol.rb', line 283 def Presence.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
338 339 340 341 342 |
# File 'lib/jabber4r/protocol.rb', line 338 def Presence.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
305 306 307 |
# File 'lib/jabber4r/protocol.rb', line 305 def Presence.gen_xa(id, status=nil) Presence.new(id, "xa", status) end |
Instance Method Details
#to_s ⇒ Object
see _to_xml
385 386 387 |
# File 'lib/jabber4r/protocol.rb', line 385 def to_s to_xml end |
#to_xml ⇒ Object
Generates the xml representation of this Presence object
- return
- String
-
The presence XML message to send the Jabber service
370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/jabber4r/protocol.rb', line 370 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 |