Class: Warchat::Chat::Client
- Inherits:
-
Object
- Object
- Warchat::Chat::Client
- Defined in:
- lib/warchat/chat/client.rb
Instance Attribute Summary collapse
-
#character_name ⇒ Object
readonly
Returns the value of attribute character_name.
-
#character_realm ⇒ Object
readonly
Returns the value of attribute character_realm.
-
#last_whisper ⇒ Object
readonly
Returns the value of attribute last_whisper.
-
#on_ack ⇒ Object
Returns the value of attribute on_ack.
-
#on_chat_logout ⇒ Object
Returns the value of attribute on_chat_logout.
-
#on_establish ⇒ Object
Returns the value of attribute on_establish.
-
#on_fail ⇒ Object
Returns the value of attribute on_fail.
-
#on_logout ⇒ Object
Returns the value of attribute on_logout.
-
#on_message ⇒ Object
Returns the value of attribute on_message.
-
#on_message_afk ⇒ Object
Returns the value of attribute on_message_afk.
-
#on_message_dnd ⇒ Object
Returns the value of attribute on_message_dnd.
-
#on_message_guild_chat ⇒ Object
Returns the value of attribute on_message_guild_chat.
-
#on_message_motd ⇒ Object
Returns the value of attribute on_message_motd.
-
#on_message_officer_chat ⇒ Object
Returns the value of attribute on_message_officer_chat.
-
#on_message_whisper ⇒ Object
Returns the value of attribute on_message_whisper.
-
#on_presence ⇒ Object
Returns the value of attribute on_presence.
-
#on_presence_change ⇒ Object
Returns the value of attribute on_presence_change.
-
#online_characters ⇒ Object
readonly
Returns the value of attribute online_characters.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #chat(response) ⇒ Object
- #chat_login(response) ⇒ Object
- #chat_logout(response) ⇒ Object
- #chat_presence(presence) ⇒ Object
- #close ⇒ Object
- #close_nonblock ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #keep_alive ⇒ Object
- #login(*args) ⇒ Object
- #logout ⇒ Object
- #message(msg, chat_type = Message.CHAT_MSG_TYPE_GUILD_CHAT) ⇒ Object
- #session_error(response) ⇒ Object
- #session_establish(response) ⇒ Object
- #session_receive(response) ⇒ Object
- #start(account_name, account_password, host = "m.us.wowarmory.com", port = 8780) ⇒ Object
- #whisper(msg, name) ⇒ Object
Constructor Details
Instance Attribute Details
#character_name ⇒ Object (readonly)
Returns the value of attribute character_name.
8 9 10 |
# File 'lib/warchat/chat/client.rb', line 8 def character_name @character_name end |
#character_realm ⇒ Object (readonly)
Returns the value of attribute character_realm.
8 9 10 |
# File 'lib/warchat/chat/client.rb', line 8 def character_realm @character_realm end |
#last_whisper ⇒ Object (readonly)
Returns the value of attribute last_whisper.
8 9 10 |
# File 'lib/warchat/chat/client.rb', line 8 def last_whisper @last_whisper end |
#on_ack ⇒ Object
Returns the value of attribute on_ack.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_ack @on_ack end |
#on_chat_logout ⇒ Object
Returns the value of attribute on_chat_logout.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def on_chat_logout @on_chat_logout end |
#on_establish ⇒ Object
Returns the value of attribute on_establish.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_establish @on_establish end |
#on_fail ⇒ Object
Returns the value of attribute on_fail.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_fail @on_fail end |
#on_logout ⇒ Object
Returns the value of attribute on_logout.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_logout @on_logout end |
#on_message ⇒ Object
Returns the value of attribute on_message.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def @on_message end |
#on_message_afk ⇒ Object
Returns the value of attribute on_message_afk.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_afk end |
#on_message_dnd ⇒ Object
Returns the value of attribute on_message_dnd.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_dnd end |
#on_message_guild_chat ⇒ Object
Returns the value of attribute on_message_guild_chat.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_guild_chat end |
#on_message_motd ⇒ Object
Returns the value of attribute on_message_motd.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_motd end |
#on_message_officer_chat ⇒ Object
Returns the value of attribute on_message_officer_chat.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_officer_chat end |
#on_message_whisper ⇒ Object
Returns the value of attribute on_message_whisper.
6 7 8 |
# File 'lib/warchat/chat/client.rb', line 6 def @on_message_whisper end |
#on_presence ⇒ Object
Returns the value of attribute on_presence.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_presence @on_presence end |
#on_presence_change ⇒ Object
Returns the value of attribute on_presence_change.
5 6 7 |
# File 'lib/warchat/chat/client.rb', line 5 def on_presence_change @on_presence_change end |
#online_characters ⇒ Object (readonly)
Returns the value of attribute online_characters.
8 9 10 |
# File 'lib/warchat/chat/client.rb', line 8 def online_characters @online_characters end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/warchat/chat/client.rb', line 8 def session @session end |
Instance Method Details
#chat(response) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/warchat/chat/client.rb', line 63 def chat response response.extend(Warchat::Chat::ChatResponse) if response.ack? on_ack and on_ack.call response elsif response. = Warchat::Chat::Message.new(response) @last_whisper = if .whisper? [,send("on_message_#{.type}".to_sym)].compact.each do |m| m.call() end elsif response.presence? chat_presence Warchat::Chat::Presence.new(response) else Warchat.debug "unhandled chat type: #{response.chat_type}" end end |
#chat_login(response) ⇒ Object
54 55 56 57 |
# File 'lib/warchat/chat/client.rb', line 54 def chat_login response Warchat.debug "Logged into chat" @chat_session_id = response["chatSessionId"] end |
#chat_logout(response) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/warchat/chat/client.rb', line 47 def chat_logout response Warchat.debug 'Logged out of chat' @timer and @timer.stop on_chat_logout and on_chat_logout.call response session.close end |
#chat_presence(presence) ⇒ Object
59 60 61 |
# File 'lib/warchat/chat/client.rb', line 59 def chat_presence presence on_presence and on_presence.call(presence) end |
#close ⇒ Object
83 84 85 86 |
# File 'lib/warchat/chat/client.rb', line 83 def close close_nonblock sleep(0.1) until session.is_closed? end |
#close_nonblock ⇒ Object
78 79 80 81 |
# File 'lib/warchat/chat/client.rb', line 78 def close_nonblock request = Warchat::Network::Request.new("/chat-logout",:chatSessionId=>@chat_session_id) session.send_request(request) end |
#keep_alive ⇒ Object
88 89 90 91 92 |
# File 'lib/warchat/chat/client.rb', line 88 def keep_alive Warchat.debug 'keep alive' request = Warchat::Network::Request.new("/ah-mail",:n=>character_name,:r=>character_realm) session.send_request(request) end |
#login(*args) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/warchat/chat/client.rb', line 35 def login *args @character_name,@character_realm = args [character_name,character_realm].each do |s| s.respond_to? :force_encoding and s.force_encoding(__ENCODING__) end request = Warchat::Network::Request.new("/chat-login",:options=>{:mature_filter=>'false'},:n=>character_name,:r=>character_realm) session.send_request(request) @timer = Warchat::Timer.new(60) do keep_alive end end |
#logout ⇒ Object
43 44 45 |
# File 'lib/warchat/chat/client.rb', line 43 def logout request = Warchat::Network::Request.new('/chat-logout',:chatSessionId=>@chat_session_id) end |
#message(msg, chat_type = Message.CHAT_MSG_TYPE_GUILD_CHAT) ⇒ Object
94 95 96 97 |
# File 'lib/warchat/chat/client.rb', line 94 def (msg, chat_type = Message.CHAT_MSG_TYPE_GUILD_CHAT) request = Warchat::Network::Request.new("/chat-guild",:type=>chat_type,:body=>msg,:chatSessionId=>@chat_session_id) session.send_request(request) end |
#session_error(response) ⇒ Object
22 23 24 |
# File 'lib/warchat/chat/client.rb', line 22 def session_error response on_fail and on_fail.call(response["body"]) if response.target == "/chat-login" end |
#session_establish(response) ⇒ Object
26 27 28 |
# File 'lib/warchat/chat/client.rb', line 26 def session_establish response on_establish and on_establish.call(response) end |
#session_receive(response) ⇒ Object
30 31 32 33 |
# File 'lib/warchat/chat/client.rb', line 30 def session_receive response m = response.target.gsub('/','').underscore.to_sym send(m,response) if respond_to? m end |
#start(account_name, account_password, host = "m.us.wowarmory.com", port = 8780) ⇒ Object
17 18 19 20 |
# File 'lib/warchat/chat/client.rb', line 17 def start account_name, account_password,host="m.us.wowarmory.com",port=8780 [username,password].each do |s| s.respond_to? :force_encoding and s.force_encoding(__ENCODING__) end self.session.start(account_name,account_password,host,port) end |