ruby-asterisk 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -63,9 +63,10 @@ To get a list of all parked calls on your Asterisk PBX, use the following comman
63
63
  To start a new call use the following command
64
64
 
65
65
  ```ruby
66
- @ami.originate("SIP/9100","OUTGOING","123456","1") # CALLER, CONTEXT, CALLEE, PRIORITY
66
+ @ami.originate("SIP/9100","OUTGOING","123456","1","var1=12,var2=99") # CALLER, CONTEXT, CALLEE, PRIORITY, VARIABLE
67
67
  ```
68
68
 
69
+
69
70
  ### COMMAND
70
71
 
71
72
  To execute a cli command use the following code
@@ -82,9 +83,13 @@ To get a list of all active conferences use the following command
82
83
  @ami.meet_me_list
83
84
  ```
84
85
 
86
+ ### EXTENSION STATE
85
87
 
88
+ To get the state of an extension use the following command
86
89
 
87
-
90
+ ```ruby
91
+ @ami.extension_state(@exten,@context)
92
+ ```
88
93
 
89
94
  ### THE RESPONSE OBJECT
90
95
 
@@ -92,6 +92,17 @@ module RubyAsterisk
92
92
  Response.new("ParkedCalls",request.response_data)
93
93
  end
94
94
 
95
+ def extension_state(exten,context)
96
+ request = Request.new("ExtensionState",{"Exten" => exten, "Context" => context})
97
+ request.commands.each do |command|
98
+ @session.write(command)
99
+ end
100
+ @session.waitfor("String" => "ActionID: "+request.action_id, "Timeout" => 3) do |data|
101
+ request.response_data << data
102
+ end
103
+ Response.new("ExtensionState",request.response_data)
104
+ end
105
+
95
106
  def originate(caller,context,callee,priority,variable=nil)
96
107
  request = Request.new("Originate",{"Channel" => caller, "Context" => context, "Exten" => callee, "Priority" => priority, "Callerid" => caller, "Timeout" => "30000", "Variable" => variable })
97
108
  request.commands.each do |command|
@@ -44,6 +44,8 @@ module RubyAsterisk
44
44
  self._parse_originate(response)
45
45
  when "MeetMeList"
46
46
  self._parse_meet_me_list(response)
47
+ when "ExtensionState"
48
+ self._parse_extension_state(response)
47
49
  end
48
50
  end
49
51
 
@@ -63,6 +65,33 @@ module RubyAsterisk
63
65
  self._parse_objects(response,:channels,"Event: CoreShowChannel","Event: CoreShowChannelsComplete")
64
66
  end
65
67
 
68
+ def _parse_extension_state(response)
69
+ _data = self._parse_objects(response,:hints,"Response:")
70
+ self._convert_status(_data)
71
+ end
72
+
73
+ def _convert_status(_data)
74
+ _data[:hints].each do |hint|
75
+ case hint["Status"]
76
+ when "-1"
77
+ hint["Status"] = "Extension not found"
78
+ when "0"
79
+ hint["Status"] = "Idle"
80
+ when "1"
81
+ hint["Status"] = "In Use"
82
+ when "2"
83
+ hint["Status"] = "Busy"
84
+ when "4"
85
+ hint["Status"] = "Unavailable"
86
+ when "8"
87
+ hint["Status"] = "Ringing"
88
+ when "16"
89
+ hint["Status"] = "On Hold"
90
+ end
91
+ end
92
+ _data
93
+ end
94
+
66
95
  def _parse_objects(response,symbol_name,search_for,stop_with=nil)
67
96
  _data = { symbol_name => [] }
68
97
  parsing = false
@@ -1,3 +1,3 @@
1
1
  module Rami
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -76,6 +76,16 @@ describe RubyAsterisk::Response do
76
76
  Talking: Not monitored"
77
77
  end
78
78
 
79
+ def extension_state_response
80
+ "Response: Success
81
+ ActionID: 180
82
+ Message: Extension Status
83
+ Exten: 9100
84
+ Context: HINT
85
+ Hint: SIP/9100
86
+ Status: 0"
87
+ end
88
+
79
89
  describe ".new" do
80
90
 
81
91
  describe "receiving a Core Show Channels request" do
@@ -130,5 +140,17 @@ describe RubyAsterisk::Response do
130
140
  @response.data[:rooms][0]["Conference"].should eq("1234")
131
141
  end
132
142
  end
143
+
144
+ describe "receiving a ExtensionState request" do
145
+ it "should parse correctly data coming from Asterisk about the state of the extension" do
146
+ @response = RubyAsterisk::Response.new("ExtensionState",extension_state_response)
147
+ @response.data[:hints].should_not be_empty
148
+ end
149
+
150
+ it "should correctly fill the fields" do
151
+ @response = RubyAsterisk::Response.new("ExtensionState",extension_state_response)
152
+ @response.data[:hints][0]["Status"].should eq("Idle")
153
+ end
154
+ end
133
155
  end
134
156
  end
@@ -131,5 +131,12 @@ describe RubyAsterisk do
131
131
  @session.login("mark","mysecret")
132
132
  @session.meet_me_list.should be_kind_of(RubyAsterisk::Response)
133
133
  end
134
+ end
135
+
136
+ describe ".extension_state" do
137
+ it "should return a response object" do
138
+ @session.login("mark","mysecret")
139
+ @session.extension_state("9100","HINT").should be_kind_of(RubyAsterisk::Response)
140
+ end
134
141
  end
135
142
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby-asterisk
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Emiliano Della Casa
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-02 00:00:00 Z
13
+ date: 2012-05-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake