Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emiliano Della Casa
committed
Nov 11, 2013
1 parent
49a875a
commit da27ed4
Showing
5 changed files
with
65 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
module RubyAsterisk | ||
## | ||
# | ||
# Class responsible of building commands structure | ||
# | ||
class Request | ||
attr_accessor :action, :action_id, :parameters, :response_data | ||
|
||
def initialize(action,parameters={}) | ||
def initialize(action, parameters = {}) | ||
self.action = action | ||
self.action_id = self.generate_action_id | ||
self.action_id = Request.generate_action_id | ||
self.parameters = parameters | ||
self.response_data = '' | ||
end | ||
|
||
def commands | ||
_commands=["Action: #{self.action}\r\n","ActionID: #{self.action_id}\r\n"] | ||
self.parameters.each do |key,value| | ||
_commands<<key+": #{value}\r\n" unless value.nil? | ||
_commands = ["Action: #{self.action}\r\n", "ActionID: #{self.action_id}\r\n"] | ||
self.parameters.each do |key, value| | ||
_commands << key + ": #{value}\r\n" unless value.nil? | ||
end | ||
_commands[_commands.length-1]<<"\r\n" | ||
_commands[_commands.length - 1] << "\r\n" | ||
_commands | ||
end | ||
|
||
protected | ||
|
||
def generate_action_id | ||
if RUBY_VERSION.start_with?("1.9") | ||
def self.generate_action_id | ||
if RUBY_VERSION.start_with?('1.9') | ||
Random.rand(999).to_s | ||
else | ||
rand(999).to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters