Class: Votifier::ConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/votifier/handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(session, key) ⇒ ConnectionHandler

Returns a new instance of ConnectionHandler.



4
5
6
7
# File 'lib/votifier/handler.rb', line 4

def initialize(session, key)
  @session = session
   @key = key
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/votifier/handler.rb', line 9

def run
   # Send the latest compatible plugin version to the list
  @session.puts "VOTIFIER #{Votifier::PLUGIN_VERSION}\n"
   
   # Read and decrypt the 256 byte vote block
   block = @session.read 256
   result = @key.private_decrypt(block).split("\n")
   
   # Perform opcode check
   if result[0] != "VOTE"
     raise ArgumentError, "Incorrect block opcode"
   end
   
   # Create the vote
   Vote.new(result[1], result[2], result[3], result[4])
end