Class: AsteriskManager::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/asterisk-manager/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Connection

Returns a new instance of Connection.



10
11
12
13
14
15
16
# File 'lib/asterisk-manager/connection.rb', line 10

def initialize(arguments = {})
  self.host     = arguments[:host]
  self.port     = arguments[:port]
  self.username = arguments[:username]
  self.password = arguments[:password]
  
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/asterisk-manager/connection.rb', line 5

def host
  @host
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/asterisk-manager/connection.rb', line 5

def password
  @password
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/asterisk-manager/connection.rb', line 5

def port
  @port
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/asterisk-manager/connection.rb', line 5

def username
  @username
end

Instance Method Details

#loginObject



36
37
38
39
40
41
# File 'lib/asterisk-manager/connection.rb', line 36

def 
  send "Action: Login\r\n"
  send "Username: #{username}\r\n"
  send "Secret: #{password}\r\n"
  send "\r\n"
end

#read_lineObject



26
27
28
29
30
31
32
33
34
# File 'lib/asterisk-manager/connection.rb', line 26

def read_line
  if !@socket || (response = socket.gets).nil?
    @socket = nil
    
    read_line
  else
    response
  end
end

#send(value) ⇒ Object



22
23
24
# File 'lib/asterisk-manager/connection.rb', line 22

def send(value)
  socket.write value
end

#socketObject



18
19
20
# File 'lib/asterisk-manager/connection.rb', line 18

def socket
  @socket ||= TCPSocket.new host, port
end