Class: Jabber::Protocol::Presence

Inherits:
Object
  • Object
show all
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

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



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

#fromObject

Returns the value of attribute from.



242
243
244
# File 'lib/jabber4r/protocol.rb', line 242

def from
  @from
end

#idObject

Returns the value of attribute id.



242
243
244
# File 'lib/jabber4r/protocol.rb', line 242

def id
  @id
end

#priorityObject

Returns the value of attribute priority.



249
250
251
# File 'lib/jabber4r/protocol.rb', line 249

def priority
  @priority
end

#showObject

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



245
246
247
# File 'lib/jabber4r/protocol.rb', line 245

def show
  @show
end

#statusObject

The status message



248
249
250
# File 'lib/jabber4r/protocol.rb', line 248

def status
  @status
end

#toObject

Returns the value of attribute to.



242
243
244
# File 'lib/jabber4r/protocol.rb', line 242

def to
  @to
end

#typeObject

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_sObject

see _to_xml



385
386
387
# File 'lib/jabber4r/protocol.rb', line 385

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



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