Class: Del::Connection
- Inherits:
-
Object
- Object
- Del::Connection
- Defined in:
- lib/del/connection.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#rooms ⇒ Object
readonly
Returns the value of attribute rooms.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #connect(robot) ⇒ Object
- #deliver(jid, message) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(configuration:, users:, rooms:) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(configuration:, users:, rooms:) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 |
# File 'lib/del/connection.rb', line 5 def initialize(configuration:, users:, rooms:) @configuration = configuration @rooms = rooms @users = users end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/del/connection.rb', line 3 def configuration @configuration end |
#rooms ⇒ Object (readonly)
Returns the value of attribute rooms.
3 4 5 |
# File 'lib/del/connection.rb', line 3 def rooms @rooms end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
3 4 5 |
# File 'lib/del/connection.rb', line 3 def users @users end |
Instance Method Details
#connect(robot) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/del/connection.rb', line 11 def connect(robot) client.on_exception do |error, connection, error_source| disconnect end client.connect(configuration[:host]) sleep 0.0001 until client.is_connected? client.auth(configuration[:password]) roster = Jabber::Roster::Helper.new(client, false) roster.add_update_callback do |old_item, item| users.create(item) if item end roster.get_roster roster.wait_for_roster #@mention_name = roster[jid].attributes["mention_name"] client. do || robot.receive() end client.send(Jabber::Presence.new(:chat)) list_rooms(configuration[:muc_domain]).each do |room| rooms.upsert(room) end end |
#deliver(jid, message) ⇒ Object
34 35 36 37 38 |
# File 'lib/del/connection.rb', line 34 def deliver(jid, ) = Jabber::Message.new(jid, encode_string()) .type = :chat client.send() end |
#disconnect ⇒ Object
40 41 42 43 |
# File 'lib/del/connection.rb', line 40 def disconnect puts "byte me!" client.close end |