Class: Conreality::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/conreality/client.rb

Overview

Client for accessing a Conreality master server.

Instance Attribute Summary collapse

Connection management collapse

Public interface collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master_host) ⇒ Client

Returns a new instance of Client.

Parameters:

  • master_host (String)


24
25
26
27
28
29
# File 'lib/conreality/client.rb', line 24

def initialize(master_host)
  channel_creds = :this_channel_is_insecure
  @channel      = RPC::Session::Stub.setup_channel(nil, master_host, channel_creds)
  @rpc_public   = RPC::Public::Stub.new(master_host, channel_creds, channel_override: @channel)
  @rpc_session  = RPC::Session::Stub.new(master_host, channel_creds, channel_override: @channel)
end

Instance Attribute Details

#rpc_publicObject (readonly)

Returns the value of attribute rpc_public.



13
14
15
# File 'lib/conreality/client.rb', line 13

def rpc_public
  @rpc_public
end

#rpc_sessionObject (readonly)

Returns the value of attribute rpc_session.



14
15
16
# File 'lib/conreality/client.rb', line 14

def rpc_session
  @rpc_session
end

Class Method Details

.connect(master_host, *args) ⇒ Object

Parameters:

  • master_host (String)


18
19
20
# File 'lib/conreality/client.rb', line 18

def self.connect(master_host, *args)
  self.new(master_host, *args).connect
end

Instance Method Details

#authenticate(agent_uuid, secret = nil) ⇒ Session

Invokes the public ‘Authenticate` method on the server.

Parameters:

  • agent_uuid (String)
  • secret (String) (defaults to: nil)

Returns:



67
68
69
# File 'lib/conreality/client.rb', line 67

def authenticate(agent_uuid, secret = nil)
  Session.new(self, 1) # TODO
end

#byevoid

This method returns an undefined value.

Invokes the public ‘Bye` method on the server.



75
76
77
# File 'lib/conreality/client.rb', line 75

def bye
  @rpc_public.bye(RPC::EmptyRequest.new)
end

#connectClient

Connects to the server.

Returns:



45
46
47
# File 'lib/conreality/client.rb', line 45

def connect
  self
end

#disconnect!void

This method returns an undefined value.

Disconnects from the server.



53
54
55
# File 'lib/conreality/client.rb', line 53

def disconnect!
  @channel = @rpc_public = @rpc_session = nil
end

#helloHash

Invokes the public ‘Hello` method on the server.

Returns:

  • (Hash)


83
84
85
# File 'lib/conreality/client.rb', line 83

def hello
  {version: @rpc_public.hello(RPC::HelloRequest.new(version: Conreality::VERSION.to_s)).version}.freeze
end

#inspectString

Returns a developer-friendly representation of this client.

Returns:

  • (String)


35
36
37
# File 'lib/conreality/client.rb', line 35

def inspect
  sprintf("#<%s:%#0x>", self.class.name, self.__id__)
end

#pingvoid

This method returns an undefined value.

Invokes the public ‘Ping` method on the server.



91
92
93
# File 'lib/conreality/client.rb', line 91

def ping
  @rpc_public.ping(RPC::PingRequest.new)
end