Class: Baleen::Client
- Inherits:
-
Object
- Object
- Baleen::Client
- Includes:
- Celluloid::IO
- Defined in:
- lib/baleen/client.rb
Instance Method Summary collapse
- #close ⇒ Object
- #handle_response(response) ⇒ Object
-
#initialize(host, port = 12345) ⇒ Client
constructor
A new instance of Client.
- #request(request) ⇒ Object
- #response ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize(host, port = 12345) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/baleen/client.rb', line 9 def initialize(host, port=12345) @socket = TCPSocket.open(host, port) @result = "running" async.response end |
Instance Method Details
#close ⇒ Object
23 24 25 26 27 28 |
# File 'lib/baleen/client.rb', line 23 def close @socket.close if @socket info "connection closed" rescue IOError; nil end |
#handle_response(response) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/baleen/client.rb', line 30 def handle_response(response) if response.nil? raise RuntimeError, 'Connection closed by server' end info "Got response" @result = Baleen::Message::Decoder.new(response).decode true end |
#request(request) ⇒ Object
15 16 17 |
# File 'lib/baleen/client.rb', line 15 def request(request) @socket.puts(request.to_json) end |
#response ⇒ Object
19 20 21 |
# File 'lib/baleen/client.rb', line 19 def response loop { break if handle_response(@socket.gets) } end |
#result ⇒ Object
40 41 42 |
# File 'lib/baleen/client.rb', line 40 def result @result end |