Class: Del::XMPPConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/del/xmpp_connection.rb

Overview

An XMPP Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configurationObject (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
  listen_for_direct_messages(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, message)
  message = Jabber::Message.new(jid, encode_string(message))
  message.type = :chat
  client.send(message)
end

#deliver_to_room(jid, message) ⇒ Object



28
29
30
# File 'lib/del/xmpp_connection.rb', line 28

def deliver_to_room(jid, message)
  @rooms[jid.strip.to_s]&.say(encode_string(message))
end

#disconnectObject



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, message))
end