Class: Jabber::MUC::HipchatClient
- Inherits:
-
Object
- Object
- Jabber::MUC::HipchatClient
- Defined in:
- lib/xmpp4r/muc/helper/hipchat_client.rb
Constant Summary collapse
- CALLBACKS =
Callbacks
%w(lobby_presence room_presence room_message private_message room_invite room_topic error)
Instance Attribute Summary collapse
-
#my_jid ⇒ Object
readonly
Returns the value of attribute my_jid.
Instance Method Summary collapse
- #activate_callbacks ⇒ Object
-
#connect(password) ⇒ Object
Connection.
- #deactivate_callbacks ⇒ Object
- #exit(room_id, reason = nil) ⇒ Object
-
#get_rooms ⇒ Object
Fetching.
- #get_user_details(user_id) ⇒ Object
- #get_users ⇒ Object
-
#initialize(jid, conference_host = nil) ⇒ HipchatClient
constructor
A new instance of HipchatClient.
- #invite(user_ids, room_id) ⇒ Object
-
#join(room_id, fetch_history = false) ⇒ Object
Actions.
- #keep_alive(password) ⇒ Object
- #kick(user_ids, room_id) ⇒ Object
- #name ⇒ Object
- #name=(resource) ⇒ Object
- #send_message(type, recipient_id, text, subject = nil) ⇒ Object
- #set_presence(status = nil, type = :available, room_id = nil) ⇒ Object
Constructor Details
#initialize(jid, conference_host = nil) ⇒ HipchatClient
Returns a new instance of HipchatClient.
6 7 8 9 10 11 12 13 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 6 def initialize jid, conference_host = nil @my_jid = JID.new(jid) @presence = HipChat::Presence.new(my_jid) = HipChat::Message.new(my_jid) @conference_host = conference_host end |
Instance Attribute Details
#my_jid ⇒ Object (readonly)
Returns the value of attribute my_jid.
4 5 6 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 4 def my_jid @my_jid end |
Instance Method Details
#activate_callbacks ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 105 def activate_callbacks stream.add_stanza_callback(0, self) do |stanza| case stanza.name when 'message' (HipChat::ReceivedMessage.new(stanza)) when 'presence' handle_presence(HipChat::ReceivedPresence.new(stanza, chat_host)) end end Jabber::debuglog "Callbacks activated" end |
#connect(password) ⇒ Object
Connection
78 79 80 81 82 83 84 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 78 def connect password stream.connect Jabber::debuglog "Connected to stream" stream.auth(password) Jabber::debuglog "Authenticated" true end |
#deactivate_callbacks ⇒ Object
117 118 119 120 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 117 def deactivate_callbacks stream.delete_stanza_callback(self) Jabber::debuglog "Callbacks deactivated" end |
#exit(room_id, reason = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 31 def exit room_id, reason = nil jid = JID.new(room_id, conference_host) Jabber::debuglog "Exiting #{jid}" @presence.get_leave(jid, reason).send_to(stream) end |
#get_rooms ⇒ Object
Fetching
64 65 66 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 64 def get_rooms HipChat::RoomData.get_rooms_data(stream, conference_host) end |
#get_user_details(user_id) ⇒ Object
72 73 74 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 72 def get_user_details user_id HipChat::VCard.get_details(stream, user_id) end |
#get_users ⇒ Object
68 69 70 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 68 def get_users HipChat::UserData.get_users_data(stream) end |
#invite(user_ids, room_id) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 50 def invite user_ids, room_id room_jid = JID.new(room_id, conference_host) user_jids = user_ids.map{ |id| JID.new(id, chat_host) } Jabber::debuglog "Inviting #{user_jids} to #{room_jid}" .get_invite(room_jid, user_jids).send_to(stream) end |
#join(room_id, fetch_history = false) ⇒ Object
Actions
25 26 27 28 29 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 25 def join room_id, fetch_history = false jid = JID.new(room_id, conference_host) Jabber::debuglog "Joining #{jid}" @presence.get_join(jid, fetch_history).send_to(stream) end |
#keep_alive(password) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 86 def keep_alive password if stream.is_disconnected? Jabber::debuglog "Stream disconnected. Connecting again..." connect(password) end end |
#kick(user_ids, room_id) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 43 def kick user_ids, room_id room_jid = JID.new(room_id, conference_host) user_jids = user_ids.map{ |id| JID.new(id, chat_host) } Jabber::debuglog "Kicking #{user_jids} from #{room_jid}" HipChat::KickMessage.new(my_jid).make(room_jid, user_jids).send_to(stream) end |
#name ⇒ Object
15 16 17 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 15 def name my_jid.resource end |
#name=(resource) ⇒ Object
19 20 21 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 19 def name= resource my_jid.resource = resource end |
#send_message(type, recipient_id, text, subject = nil) ⇒ Object
57 58 59 60 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 57 def type, recipient_id, text, subject = nil jid = JID.new(recipient_id, type == :chat ? chat_host : conference_host) .get_text(type, jid, text, subject).send_to(stream) end |
#set_presence(status = nil, type = :available, room_id = nil) ⇒ Object
37 38 39 40 41 |
# File 'lib/xmpp4r/muc/helper/hipchat_client.rb', line 37 def set_presence status = nil, type = :available, room_id = nil room_jid = room_id ? JID.new(room_id, conference_host) : nil Jabber::debuglog "Setting presence to #{type} in #{room_jid} with #{status}" @presence.get_status(type, room_jid, status).send_to(stream) end |