Class: Tecepe::BlockingClient
- Inherits:
-
Object
- Object
- Tecepe::BlockingClient
- Defined in:
- lib/tecepe/blocking_client.rb
Instance Method Summary collapse
- #call(event_name, payload) ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(host, port, cid = Process.pid) ⇒ BlockingClient
constructor
A new instance of BlockingClient.
Constructor Details
#initialize(host, port, cid = Process.pid) ⇒ BlockingClient
Returns a new instance of BlockingClient.
21 22 23 24 25 26 |
# File 'lib/tecepe/blocking_client.rb', line 21 def initialize(host, port, cid = Process.pid) @host, @port, @cid = host, port, cid @socket = nil @reconnect = true connect end |
Instance Method Details
#call(event_name, payload) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/tecepe/blocking_client.rb', line 32 def call(event_name, payload) json = JSON.generate(event: event_name, cid: @cid, payload: payload) ensure_connected do @socket.print "#{json}\n" JSON.parse(@socket.gets) end end |
#connected? ⇒ Boolean
28 29 30 |
# File 'lib/tecepe/blocking_client.rb', line 28 def connected? !! @socket end |