Class: Msn::Switchboard
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Msn::Switchboard
- Includes:
- Protocol
- Defined in:
- lib/msn/switchboard.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(messenger) ⇒ Switchboard
constructor
A new instance of Switchboard.
- #send_message(text) ⇒ Object
Methods included from Protocol
#answer_challenge, #clear_event, #handle_event, #handle_normal_command, #handle_payload_command, #method_missing, #on_event, #post_init, #receive_binary_data, #receive_line, #send_command, #send_command_internal, #send_payload_command, #send_payload_command_and_wait
Constructor Details
#initialize(messenger) ⇒ Switchboard
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/msn/switchboard.rb', line 5 def initialize(messenger) @messenger = messenger on_event 'MSG' do |header, data| email = header[1] display_name = header[2] head, body = data.split "\r\n\r\n", 2 headers = Hash[head.split("\r\n").map { |line| line.split ':', 2 }] if headers['Content-Type'] =~ %r(text/plain) @messenger. Msn::Message.new(email, display_name, body) end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Msn::Protocol
Instance Method Details
#send_message(text) ⇒ Object
20 21 22 |
# File 'lib/msn/switchboard.rb', line 20 def (text) send_payload_command "MSG", "A", "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nUser-Agent: pidgin/2.10.5devel\r\nX-MMS-IM-Format: FN=Segoe%20UI; EF=; CO=0; PF=0; RL=0\r\n\r\n#{text}" end |