Class: AsteriskManager::Connection
- Inherits:
-
Object
- Object
- AsteriskManager::Connection
- Defined in:
- lib/asterisk-manager/connection.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(arguments = {}) ⇒ Connection
constructor
A new instance of Connection.
- #login ⇒ Object
- #read_line ⇒ Object
- #send(value) ⇒ Object
- #socket ⇒ Object
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] login end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/asterisk-manager/connection.rb', line 5 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/asterisk-manager/connection.rb', line 5 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/asterisk-manager/connection.rb', line 5 def port @port end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/asterisk-manager/connection.rb', line 5 def username @username end |
Instance Method Details
#login ⇒ Object
36 37 38 39 40 41 |
# File 'lib/asterisk-manager/connection.rb', line 36 def login send "Action: Login\r\n" send "Username: #{username}\r\n" send "Secret: #{password}\r\n" send "\r\n" end |
#read_line ⇒ Object
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 login 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 |
#socket ⇒ Object
18 19 20 |
# File 'lib/asterisk-manager/connection.rb', line 18 def socket @socket ||= TCPSocket.new host, port end |