Class: Lita::Adapters::HipChat::Connector
- Inherits:
-
Object
- Object
- Lita::Adapters::HipChat::Connector
- Defined in:
- lib/lita/adapters/hipchat/connector.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#robot ⇒ Object
readonly
Returns the value of attribute robot.
-
#roster ⇒ Object
readonly
Returns the value of attribute roster.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(robot, jid, password, server, debug: false) ⇒ Connector
constructor
A new instance of Connector.
- #jid ⇒ Object
- #join(muc_domain, room) ⇒ Object
- #join_rooms(muc_domain, rooms) ⇒ Object
- #list_rooms(muc_domain) ⇒ Object
- #message_jid(user_jid, strings) ⇒ Object
- #message_muc(room_jid, strings) ⇒ Object
- #mucs ⇒ Object
- #part(muc_domain, room) ⇒ Object
- #set_topic(room_jid, topic) ⇒ Object
- #shut_down ⇒ Object
Constructor Details
#initialize(robot, jid, password, server, debug: false) ⇒ Connector
Returns a new instance of Connector.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 14 def initialize(robot, jid, password, server, debug: false) @robot = robot @jid = normalized_jid(jid, "chat.hipchat.com", "bot") @password = password @server = server @client = Jabber::Client.new(@jid) if debug Lita.logger.info("Enabling Jabber log.") Jabber.debug = true end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 12 def client @client end |
#robot ⇒ Object (readonly)
Returns the value of attribute robot.
12 13 14 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 12 def robot @robot end |
#roster ⇒ Object (readonly)
Returns the value of attribute roster.
12 13 14 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 12 def roster @roster end |
Instance Method Details
#connect ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 30 def connect register_exception_handler client_connect load_roster send_presence end |
#jid ⇒ Object
26 27 28 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 26 def jid @jid.to_s end |
#join(muc_domain, room) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 38 def join(muc_domain, room) room_jid = normalized_jid(room, muc_domain, robot.name) if mucs[room_jid..to_s] Lita.logger.debug "Already in room with JID #{room_jid..to_s}" return end muc = Jabber::MUC::SimpleMUCClient.new(client) mucs[room_jid..to_s] = muc (muc) Lita.logger.info("Joining room: #{room_jid}.") muc.join(room_jid) end |
#join_rooms(muc_domain, rooms) ⇒ Object
54 55 56 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 54 def join_rooms(muc_domain, rooms) rooms.each { |room| join(muc_domain, room) } end |
#list_rooms(muc_domain) ⇒ Object
58 59 60 61 62 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 58 def list_rooms(muc_domain) Lita.logger.debug("Querying server for list of rooms.") browser = Jabber::MUC::MUCBrowser.new(client) browser.muc_rooms(muc_domain).map { |jid, name| jid.to_s } end |
#message_jid(user_jid, strings) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 64 def (user_jid, strings) strings.each do |s| Lita.logger.debug("Sending message to JID #{user_jid}: #{s}") = Jabber::Message.new(user_jid, encode_string(s)) .type = :chat client.send() end end |
#message_muc(room_jid, strings) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 73 def (room_jid, strings) muc = mucs[room_jid] strings.each do |s| Lita.logger.debug("Sending message to MUC #{room_jid}: #{s}") muc.say(encode_string(s)) end if muc end |
#mucs ⇒ Object
81 82 83 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 81 def mucs @mucs ||= {} end |
#part(muc_domain, room) ⇒ Object
85 86 87 88 89 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 85 def part(muc_domain, room) room_jid = normalized_jid(room, muc_domain, robot.name) muc = mucs.delete(room_jid..to_s) muc.exit if muc end |
#set_topic(room_jid, topic) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/lita/adapters/hipchat/connector.rb', line 91 def set_topic(room_jid, topic) muc = mucs[room_jid] if muc Lita.logger.debug("Setting topic for MUC #{room_jid}: #{topic}") muc.subject = topic end end |