Class: ProcessBot::ClientSocket
- Inherits:
-
Object
- Object
- ProcessBot::ClientSocket
- Defined in:
- lib/process_bot/client_socket.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #client ⇒ Object
- #close ⇒ Object
-
#initialize(options:) ⇒ ClientSocket
constructor
A new instance of ClientSocket.
- #send_command(data) ⇒ Object
Constructor Details
#initialize(options:) ⇒ ClientSocket
Returns a new instance of ClientSocket.
6 7 8 |
# File 'lib/process_bot/client_socket.rb', line 6 def initialize(options:) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/process_bot/client_socket.rb', line 4 def @options end |
Instance Method Details
#client ⇒ Object
10 11 12 |
# File 'lib/process_bot/client_socket.rb', line 10 def client @client ||= TCPSocket.new("localhost", .fetch(:port).to_i) end |
#close ⇒ Object
14 15 16 |
# File 'lib/process_bot/client_socket.rb', line 14 def close client.close end |
#send_command(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/process_bot/client_socket.rb', line 18 def send_command(data) client.puts(JSON.generate(data)) response_raw = client.gets # Happens if process is interrupted return :nil if response_raw.nil? response = JSON.parse(response_raw) return :success if response.fetch("type") == "success" raise "Command raised an error: #{response.fetch("message")}" if response.fetch("type") == "error" end |