Class: RubyRobot::GrpcShell

Inherits:
Bombshell::Environment
  • Object
show all
Includes:
Bombshell::Shell
Defined in:
lib/ruby_robot/grpc_shell.rb

Overview

Constant Summary

Constants included from Bombshell::Shell

Bombshell::Shell::EAST, Bombshell::Shell::NORTH, Bombshell::Shell::REMOVE, Bombshell::Shell::SOUTH, Bombshell::Shell::WEST

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrpcShell

Returns a new instance of GrpcShell.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

Class Method Details

.remote_url=(new_url) ⇒ Object

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



24
25
26
27
# 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

Instance Method Details

#LEFTObject



57
58
59
# File 'lib/ruby_robot/grpc_shell.rb', line 57

def LEFT
  @stub.left(Google::Protobuf::Empty.new)
end

#MOVEObject



53
54
55
# File 'lib/ruby_robot/grpc_shell.rb', line 53

def MOVE
  @stub.move(Google::Protobuf::Empty.new)
end

#PLACE(x, y, direction) ⇒ Object



49
50
51
# 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

#REMOVEObject



74
75
76
# File 'lib/ruby_robot/grpc_shell.rb', line 74

def REMOVE
  @stub.remove(Google::Protobuf::Empty.new)
end

#REPORT(to_stderr = false) ⇒ Object



65
66
67
68
69
70
71
72
# 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

#RIGHTObject



61
62
63
# File 'lib/ruby_robot/grpc_shell.rb', line 61

def RIGHT
  @stub.right(Google::Protobuf::Empty.new)
end