Class: RubyAsterisk::Request
- Inherits:
-
Object
- Object
- RubyAsterisk::Request
- Defined in:
- lib/ruby-asterisk/request.rb
Overview
Class responsible of building commands structure
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#action_id ⇒ Object
readonly
Returns the value of attribute action_id.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
-
.generate_action_id ⇒ Object
Monotonic timestamp plus a process-wide atomic counter, so two calls made within the same nanosecond (or across an NTP clock step-back) never collide.
Instance Method Summary collapse
- #commands ⇒ Object
-
#initialize(action, parameters = {}, action_id: nil) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(action, parameters = {}, action_id: nil) ⇒ Request
Returns a new instance of Request.
19 20 21 22 23 24 |
# File 'lib/ruby-asterisk/request.rb', line 19 def initialize(action, parameters = {}, action_id: nil) @action = action.freeze @action_id = (action_id || Request.generate_action_id).to_s.freeze @parameters = deep_freeze_hash(parameters) freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
9 10 11 |
# File 'lib/ruby-asterisk/request.rb', line 9 def action @action end |
#action_id ⇒ Object (readonly)
Returns the value of attribute action_id.
9 10 11 |
# File 'lib/ruby-asterisk/request.rb', line 9 def action_id @action_id end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/ruby-asterisk/request.rb', line 9 def parameters @parameters end |
Class Method Details
.generate_action_id ⇒ Object
Monotonic timestamp plus a process-wide atomic counter, so two calls made within the same nanosecond (or across an NTP clock step-back) never collide.
37 38 39 40 |
# File 'lib/ruby-asterisk/request.rb', line 37 def self.generate_action_id count = @id_mutex.synchronize { @id_counter += 1 } "#{Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond).to_s(36)}-#{count.to_s(36)}" end |
Instance Method Details
#commands ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ruby-asterisk/request.rb', line 26 def commands command_list = ["Action: #{action}\r\n", "ActionID: #{action_id}\r\n"] parameters.each do |key, value| command_list << "#{key}: #{value}\r\n" unless value.nil? end command_list[-1] << "\r\n" command_list end |