Class: Dovado::Client Private

Inherits:
Object
  • Object
show all
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.

Since:

  • 1.0.0

Instance Method Summary collapse

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

Parameters:

  • args (Hash) (defaults to: nil)

    option arguments.

Options Hash (args):

  • :server (String)

    The server (router) address.

  • :port (Integer)

    The server (router) port.

  • :user (String)

    The user name.

  • :password (String)

    The user password.

Since:

  • 1.0.0



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

#authenticateObject

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.

TODO:

Verify authentication properly.

Authenticate user.

Raises:

  • (ConnectionError)

    if there is an error in the communication with the router.

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

    true or false.

Since:

  • 1.0.0



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.

Parameters:

  • text (String) (defaults to: nil)

    the command to run.

Raises:

  • (ConnectionError)

    if there is an error in the communication with the router.

Since:

  • 1.0.0



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

#connectObject

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.

Raises:

  • (ConnectionError)

    if there is an error in the communication with the router.

Since:

  • 1.0.0



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.message}"
rescue IOError => ex
  disconnect
  raise ConnectionError.new "Error connecting to router: #{ex.message}"
rescue Net::ReadTimeout => ex
  disconnect
  raise ConnectionError.new "Error connecting to router: #{ex.message}"
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.

Returns:

  • (Boolean)

    true or false.

Since:

  • 1.0.0



92
93
94
95
96
97
98
# File 'lib/dovado/client.rb', line 92

def connected?
  unless @server.nil?
    true
  else
    false
  end
end

#disconnectObject

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.

Since:

  • 1.0.0



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