Class: Tecepe::BlockingClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tecepe/blocking_client.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/tecepe/blocking_client.rb', line 28

def connected?
  !! @socket
end