Class: Del::XMPPConnection
- Inherits:
-
Object
- Object
- Del::XMPPConnection
- Defined in:
- lib/del/xmpp_connection.rb
Overview
An XMPP Connection
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #connect(robot) ⇒ Object
- #deliver(jid, message) ⇒ Object
- #deliver_to_room(jid, message) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(configuration:) ⇒ XMPPConnection
constructor
A new instance of XMPPConnection.
-
#update_status(show = :chat, message: nil) ⇒ Object
:chat, :away, :dnd, :xa.
Constructor Details
#initialize(configuration:) ⇒ XMPPConnection
Returns a new instance of XMPPConnection.
8 9 10 11 |
# File 'lib/del/xmpp_connection.rb', line 8 def initialize(configuration:) @configuration = configuration @rooms = {} end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/del/xmpp_connection.rb', line 6 def configuration @configuration end |
Instance Method Details
#connect(robot) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/del/xmpp_connection.rb', line 13 def connect(robot) record_exceptions connect_to_xmpp_server roster = discover_users (robot) update_status(:chat) discover_rooms(robot, roster) end |
#deliver(jid, message) ⇒ Object
22 23 24 25 26 |
# File 'lib/del/xmpp_connection.rb', line 22 def deliver(jid, ) = Jabber::Message.new(jid, encode_string()) .type = :chat client.send() end |
#deliver_to_room(jid, message) ⇒ Object
28 29 30 |
# File 'lib/del/xmpp_connection.rb', line 28 def deliver_to_room(jid, ) @rooms[jid.strip.to_s]&.say(encode_string()) end |
#disconnect ⇒ Object
32 33 34 35 36 37 |
# File 'lib/del/xmpp_connection.rb', line 32 def disconnect Del.logger.info('byte me!') client.close rescue IOError, SystemCallError => error Del.logger.error(error) end |
#update_status(show = :chat, message: nil) ⇒ Object
:chat, :away, :dnd, :xa
40 41 42 |
# File 'lib/del/xmpp_connection.rb', line 40 def update_status(show = :chat, message: nil) client.send(Jabber::Presence.new(show, )) end |