Class: RubyAsterisk::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-asterisk/request.rb

Overview

Class responsible of building commands structure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, parameters = {}) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
# File 'lib/ruby-asterisk/request.rb', line 9

def initialize(action, parameters = {})
  self.action = action
  self.action_id = Request.generate_action_id
  self.parameters = parameters
  self.response_data = ''
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



7
8
9
# File 'lib/ruby-asterisk/request.rb', line 7

def action
  @action
end

#action_idObject

Returns the value of attribute action_id.



7
8
9
# File 'lib/ruby-asterisk/request.rb', line 7

def action_id
  @action_id
end

#parametersObject

Returns the value of attribute parameters.



7
8
9
# File 'lib/ruby-asterisk/request.rb', line 7

def parameters
  @parameters
end

#response_dataObject

Returns the value of attribute response_data.



7
8
9
# File 'lib/ruby-asterisk/request.rb', line 7

def response_data
  @response_data
end

Instance Method Details

#commandsObject



16
17
18
19
20
21
22
23
# File 'lib/ruby-asterisk/request.rb', line 16

def commands
  _commands = ["Action: #{self.action}\r\n", "ActionID: #{self.action_id}\r\n"]
  self.parameters.each do |key, value|
    _commands<<"#{key.to_s}: #{value.to_s}\r\n" unless value.nil?
  end
  _commands[_commands.length - 1] << "\r\n"
  _commands
end