Sha256: 33f4f2cea4e3868ab002141af65d80c4049df5ede27ed54d413dd449fb6b1850
Contents?: true
Size: 853 Bytes
Versions: 1
Compression:
Stored size: 853 Bytes
Contents
require 'socket' require 'json' module Cinc class Client def initialize(server = 'localhost', port = 9001) @socket = TCPSocket.new(server, port) rescue StandardError => e raise ConnectionError.new(e.message) end def get_airbases command = Command.new('get_airbases', {}) return process_command(command) end private def process_command(command) @socket.puts command.to_json return JSON.parse @socket.gets rescue StandardError => e raise ConnectionError.new(e.message) end class Command attr_accessor :name, :arguments def initialize(name, arguments) @name = name @arguments = arguments end def to_json { name: name, arguments: arguments }.to_json end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cinc-0.1.0 | lib/cinc/client.rb |