Module: Squeezer::Connection
- Included in:
- API
- Defined in:
- lib/squeezer/connection.rb
Class Method Summary collapse
- .close_connection ⇒ Object
- .exec(command, options = {}) ⇒ Object
- .open_connection ⇒ Object
- .retrieve_connection ⇒ Object
Instance Method Summary collapse
-
#exit ⇒ Object
don’t forget to close the connection! Or else the connection stay’s in memory of the eigenclass!.
Class Method Details
.close_connection ⇒ Object
21 22 23 24 |
# File 'lib/squeezer/connection.rb', line 21 def close_connection @connection.sock.close @connection = nil end |
.exec(command, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/squeezer/connection.rb', line 26 def exec(command, ={}) # TODO raise exceptions instead of returning false response = retrieve_connection.cmd(command) puts response if == :debug return false if response.nil? return true if response.strip.eql?(command) result = response.gsub(command.gsub('?', '').strip, '').strip result.force_encoding("UTF-8") unless /^1\.8/ === RUBY_VERSION result end |
.open_connection ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/squeezer/connection.rb', line 41 def open_connection # TODO do authentication and stuff # TODO fix the timeout if we receive a large ammount of data # TODO add error handling when the host is unavailable begin Net::Telnet.new("Host" => Squeezer.server, "Port" => Squeezer.port, "Telnetmode" => false, "Prompt" => /\n/) rescue raise "connection failed" end end |
.retrieve_connection ⇒ Object
37 38 39 |
# File 'lib/squeezer/connection.rb', line 37 def retrieve_connection @connection ||= open_connection end |
Instance Method Details
#exit ⇒ Object
don’t forget to close the connection! Or else the connection stay’s in memory of the eigenclass!
9 10 11 12 |
# File 'lib/squeezer/connection.rb', line 9 def exit cmd("exit") Connection.close_connection end |