class Cinc::Client

Public Class Methods

new(host: 'localhost', port: 9001) click to toggle source
# File lib/cinc/client.rb, line 7
def initialize(host: 'localhost', port: 9001)
  @host = host
  @port = port
end

Public Instance Methods

connect() click to toggle source
# File lib/cinc/client.rb, line 12
def connect
  @socket = Socket.tcp(@host, @port, connect_timeout: 10)
  rescue StandardError => e
    raise ConnectionError.new(e.message)
end
get_airbases() click to toggle source
# File lib/cinc/client.rb, line 18
def get_airbases
  command = Command.new('get_airbases', {})

  return process_command(command)
end

Private Instance Methods

process_command(command) click to toggle source
# File lib/cinc/client.rb, line 26
def process_command(command)
  @socket.puts command.to_json
  response = @socket.gets
  raise ConnectionError.new("Connection terminated by server") unless response
  JSON.parse(response)
  rescue StandardError => e
    raise ConnectionError.new(e.message)
end