Class: Arbi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/arbi/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address = '127.0.0.1', port = 6969) ⇒ Client

Returns a new instance of Client.



28
29
30
31
32
33
# File 'lib/arbi/client.rb', line 28

def initialize(address = '127.0.0.1', port = 6969)
  @address  = address || '127.0.0.1'
  @port     = port || 6969

  self.connect
end

Instance Attribute Details

#sockObject (readonly)

Returns the value of attribute sock.



26
27
28
# File 'lib/arbi/client.rb', line 26

def sock
  @sock
end

Instance Method Details

#connectObject



35
36
37
38
# File 'lib/arbi/client.rb', line 35

def connect
  @sock = TCPSocket.new(@address, @port)
  @sock.gets
end

#get(what = 'help') ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/arbi/client.rb', line 40

def get(what = 'help')
  @sock.print "#{what.strip}\r\n"
  @sock.flush
  JSON.parse(@sock.gets.strip, create_additions: true)
rescue Errno::EPIPE
  self.connect
  retry
rescue NoMethodError
  nil
end