Class: Wine::Session
- Inherits:
-
Object
- Object
- Wine::Session
- Defined in:
- lib/wine/session.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #get(key, timeout = Connection::DEFAULT_TIMEOUT) ⇒ Object
-
#initialize(connection) ⇒ Session
constructor
A new instance of Session.
- #login(username, password, timeout = Connection::DEFAULT_TIMEOUT) ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Session
Returns a new instance of Session.
20 21 22 |
# File 'lib/wine/session.rb', line 20 def initialize(connection) @connection = connection end |
Class Method Details
.connect(host, port) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wine/session.rb', line 9 def self.connect(host, port) begin socket = TCPSocket.new(host, port) connection = Connection.new(socket) new(connection) rescue Errno::ECONNREFUSED raise ConnectionRefused end end |
Instance Method Details
#close ⇒ Object
61 62 63 |
# File 'lib/wine/session.rb', line 61 def close @connection.close end |
#get(key, timeout = Connection::DEFAULT_TIMEOUT) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wine/session.rb', line 41 def get(key, timeout = Connection::DEFAULT_TIMEOUT) request = Message::Get.new(:key_data => key) @connection.send(request) response = @connection.recv(timeout) raise ResponseTimeout unless response case response.msg_type when Message::VALUE response.value_data else raise ProtocolError end end |
#login(username, password, timeout = Connection::DEFAULT_TIMEOUT) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wine/session.rb', line 24 def login(username, password, timeout = Connection::DEFAULT_TIMEOUT) request = Message::Login.new(:username => username, :password => password) @connection.send(request) response = @connection.recv(timeout) raise ResponseTimeout unless response case response.msg_type when Message::LOGIN_ACCEPTED true when Message::LOGIN_REJECTED false else raise ProtocolError end end |