class RubyRobot::GrpcShell

Override all methods inherited from Shell such that they use gRPC to communicate with a remote Robot.

TODO: RPC error handling (more info at grpc.io/docs/guides/error.html).

Public Class Methods

new() click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 28
def initialize
  # TODO: Enable SSL/TLS
  # Totally cheating here: if URI is grpc://netflix.avilla.net,
  # then load up the cert (stored in the gem).
  if @@remote_url.to_s.start_with?("grpcs://netflix.avilla.net")
    ca_path = File.join(File.dirname(__FILE__), "cacerts.crt")
    channel_creds = GRPC::Core::ChannelCredentials.new(File.read(ca_path))
    stub_opts = {
      :creds => channel_creds, 
      GRPC::Core::Channel::SSL_TARGET => @@remote_url.host
    }
    @stub = ::RubyRobot::RubyRobot::Stub.new(
      "#{@@remote_url.host}:#{@@remote_url.port}", channel_creds
    )
  else
    @stub = ::RubyRobot::RubyRobot::Stub.new("#{@@remote_url.host}:#{@@remote_url.port}", :this_channel_is_insecure)
  end
  puts "Checking state of Robot at #{@@remote_url}"
  self.REPORT()
end
remote_url=(new_url) click to toggle source

TODO: Figure out if there's a way to pass args down into ::Bombshell#launch so this isn't a class attr.

# File lib/ruby_robot/grpc_shell.rb, line 24
def self.remote_url=(new_url)
  # Convert to URI if String
  @@remote_url = new_url.kind_of?(String) ? URI.parse(new_url) : new_url
end

Public Instance Methods

LEFT() click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 57
def LEFT
  @stub.left(Google::Protobuf::Empty.new)
end
MOVE() click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 53
def MOVE
  @stub.move(Google::Protobuf::Empty.new)
end
PLACE(x, y, direction) click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 49
def PLACE(x, y, direction)
  @stub.place(::RubyRobot::RubyRobotRequest.new(x: x, y: y, direction: direction.to_s.upcase.to_sym))
end
REMOVE() click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 74
def REMOVE
  @stub.remove(Google::Protobuf::Empty.new)
end
REPORT(to_stderr=false) click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 65
def REPORT(to_stderr=false)
  resp = @stub.report(Google::Protobuf::Empty.new)
  if resp.error
    puts resp.error.message 
  else
    puts resp.current_state.to_json
  end
end
RIGHT() click to toggle source
# File lib/ruby_robot/grpc_shell.rb, line 61
def RIGHT
  @stub.right(Google::Protobuf::Empty.new)
end