Class: FSR::EventSocket
- Inherits:
-
Object
- Object
- FSR::EventSocket
- Defined in:
- lib/fsr/event_socket.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
-
#<<(cmd) ⇒ Object
Send a command, do not return response.
-
#get_header_and_body ⇒ Object
Grab result from command and create a hash, simple but works.
-
#initialize(socket) ⇒ EventSocket
constructor
A new instance of EventSocket.
-
#response ⇒ Object
Scrub result into a hash.
-
#say(cmd) ⇒ Object
Send a command and return response.
Constructor Details
#initialize(socket) ⇒ EventSocket
Returns a new instance of EventSocket.
5 6 7 |
# File 'lib/fsr/event_socket.rb', line 5 def initialize(socket) @socket = socket end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
3 4 5 |
# File 'lib/fsr/event_socket.rb', line 3 def socket @socket end |
Instance Method Details
#<<(cmd) ⇒ Object
Send a command, do not return response
16 17 18 |
# File 'lib/fsr/event_socket.rb', line 16 def <<(cmd) @socket.send("#{cmd}\n\n",0) end |
#get_header_and_body ⇒ Object
Grab result from command and create a hash, simple but works.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fsr/event_socket.rb', line 21 def get_header_and_body headers, body = {}, "" until line = @socket.gets and line.chomp.empty? if (kv = line.chomp.split(/:\s+/,2)).size == 2 headers.store *kv end end if (content_length = headers["Content-Length"].to_i) > 0 Log.debug "content_length is #{content_length}, grabbing from socket" body << @socket.read(content_length) end headers.merge("body" => body.strip) end |
#response ⇒ Object
Scrub result into a hash
36 37 38 |
# File 'lib/fsr/event_socket.rb', line 36 def response get_header_and_body end |
#say(cmd) ⇒ Object
Send a command and return response
10 11 12 13 |
# File 'lib/fsr/event_socket.rb', line 10 def say(cmd) @socket.send("#{cmd}\n\n",0) response end |