Class: Dovado::Client Private
- Inherits:
-
Object
- Object
- Dovado::Client
- Includes:
- Celluloid
- Defined in:
- lib/dovado/client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal API client.
Instance Method Summary collapse
-
#authenticate ⇒ Object
private
Authenticate user.
-
#authenticated? ⇒ Boolean
private
Check if we’re authenticated.
-
#command(text = nil) ⇒ Object
private
Run a command on the router.
-
#connect ⇒ Object
private
Connect to the router.
-
#connected? ⇒ Boolean
private
Check if we are connected to the router.
-
#disconnect ⇒ Object
private
Disconnect from the router.
-
#initialize(args = nil) ⇒ Client
constructor
private
Create a new Client object.
Constructor Details
#initialize(args = nil) ⇒ Client
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new Dovado::Client object.
The default options are:
-
Address: 192.168.0.1
-
Port: 6435
-
User: admin
-
Password: password
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dovado/client.rb', line 24 def initialize(args=nil) # Defaults @address = '192.168.0.1' @user = 'admin' @password = 'password' @port = 6435 unless args.nil? @address = args[:server] if args.has_key? :server @port = args[:port] if args.has_key? :port @user = args[:user] if args.has_key? :user @password = args[:password] if args.has_key? :password end end |
Instance Method Details
#authenticate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Verify authentication properly.
Authenticate user.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dovado/client.rb', line 105 def authenticate perform_authentication rescue IOError disconnect connect unless connected? perform_authentication rescue Net::ReadTimeout => ex disconnect connect unless connected? perform_authentication #raise ConnectionError.new "Error connecting to router: #{ex.message}" end |
#authenticated? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if we’re authenticated.
121 122 123 |
# File 'lib/dovado/client.rb', line 121 def authenticated? @authenticated end |
#command(text = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run a command on the router.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dovado/client.rb', line 43 def command(text=nil) perform_command text rescue IOError disconnect connect unless connected? authenticate unless authenticated? perform_command text rescue Net::ReadTimeout => ex disconnect connect unless connected? authenticate unless authenticated? perform_command text #raise ConnectionError.new "Error connecting to router: #{ex.message}" end |
#connect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connect to the router.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dovado/client.rb', line 61 def connect if @server.nil? @server = Net::Telnet.new( 'Host' => @address, 'Port' => @port, 'Telnetmode' => false, 'Prompt' => />>\s/) end rescue Net::OpenTimeout => ex raise ConnectionError.new "Error connecting to router: #{ex.}" rescue IOError => ex disconnect raise ConnectionError.new "Error connecting to router: #{ex.}" rescue Net::ReadTimeout => ex disconnect raise ConnectionError.new "Error connecting to router: #{ex.}" end |
#connected? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if we are connected to the router.
92 93 94 95 96 97 98 |
# File 'lib/dovado/client.rb', line 92 def connected? unless @server.nil? true else false end end |
#disconnect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Disconnect from the router.
80 81 82 83 84 85 86 87 |
# File 'lib/dovado/client.rb', line 80 def disconnect unless @server.nil? @server.cmd "quit" @server.close end @authenticated = false @server = nil end |