class Conreality::Session

An authenticated session.

Attributes

client[R]

The client connection this session belongs to.

@return [Client]

id[R]

The session ID.

@return [Integer]

Public Class Methods

new(client, id) click to toggle source

@param client [Client] @param id [Integer]

# File lib/conreality/session.rb, line 26
def initialize(client, id)
  @client, @id = client, id.to_i
end

Public Instance Methods

_execute(&block) click to toggle source

@yield [action] @yieldparam action [Action] @yieldreturn [void] @return [void]

# File lib/conreality/session.rb, line 116
def _execute(&block)
  action = Action.new(self)
  if @client.connection.transaction_status.zero?
    # not yet in transaction scope
    @client.connection.transaction { |_| block.call(action) }
  else
    # already in transaction scope
    block.call(action)
  end
end
game() click to toggle source

TODO

@return [Game]

# File lib/conreality/session.rb, line 105
def game
  Game.new(self)
end
inspect() click to toggle source

Returns a developer-friendly representation of this session.

@return [String]

# File lib/conreality/session.rb, line 34
def inspect
  sprintf("#<%s:%#0x>", self.class.name, self.__id__)
end
logout!() click to toggle source

Terminates this session.

@return [void]

# File lib/conreality/session.rb, line 96
def logout!
  # TODO
  @client = nil
end
ping() click to toggle source

Invokes the session-scoped `Ping` method on the server.

@return [void]

# File lib/conreality/session.rb, line 42
def ping
  @client.rpc_session.ping(RPC::PingRequest.new)
end
send_event(predicate, subject, object) click to toggle source

Invokes the session-scoped `SendEvent` method on the server.

@param [String, to_s] predicate @param [Object] subject @param [Object] object @return [Event]

# File lib/conreality/session.rb, line 53
def send_event(predicate, subject, object)
  response = @client.rpc_session.send_event(
    RPC::SendEventRequest.new(
      session_id: @id,
      predicate: predicate,
      subject: subject,
      object: object,
    )
  )
  Event.new(self, response.id)
end
send_message(text) click to toggle source

Invokes the session-scoped `SendMessage` method on the server.

@param [String, to_s] text @return [Message]

# File lib/conreality/session.rb, line 70
def send_message(text)
  response = @client.rpc_session.send_message(
    RPC::SendMessageRequest.new(
      session_id: @id,
      text: text.to_s,
    )
  )
  Message.new(self, response.id)
end
update_player() click to toggle source

Invokes the session-scoped `UpdatePlayer` method on the server.

@return [void]

# File lib/conreality/session.rb, line 84
def update_player()
  @client.rpc_session.update_player(
    RPC::UpdatePlayerRequest.new(
      session_id: @id,
    )
  )
end