ruby-asterisk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,20 +60,20 @@ module RubyAsterisk
60
60
  end
61
61
 
62
62
  def _parse_data_core_show_channels(response)
63
- self._parse_objects(response,:channels,"Event: CoreShowChannel")
63
+ self._parse_objects(response,:channels,"Event: CoreShowChannel","Event: CoreShowChannelsComplete")
64
64
  end
65
65
 
66
- def _parse_objects(response,symbol_name,search_for)
66
+ def _parse_objects(response,symbol_name,search_for,stop_with=nil)
67
67
  _data = { symbol_name => [] }
68
68
  parsing = false
69
69
  object = nil
70
70
  response.each_line do |line|
71
- if line.start_with?(search_for)
71
+ if line.strip.empty? or (!stop_with.nil? and line.start_with?(stop_with))
72
+ parsing = false
73
+ elsif line.start_with?(search_for)
72
74
  _data[symbol_name] << object unless object.nil?
73
75
  object = {}
74
76
  parsing = true
75
- elsif line.strip.empty?
76
- parsing = false
77
77
  elsif parsing
78
78
  object[line.split(':')[0].strip]=line.split(':')[1].strip unless line.split(':')[1].nil?
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module Rami
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,6 +2,13 @@
2
2
  require 'spec_helper'
3
3
  describe RubyAsterisk::Response do
4
4
 
5
+ def empty_core_show_channels_response
6
+ "Event: CoreShowChannelsComplete
7
+ EventList: Complete
8
+ ListItems: 1
9
+ ActionID: 839"
10
+ end
11
+
5
12
  def core_show_channels_response
6
13
  "Event: CoreShowChannel
7
14
  ActionID: 839
@@ -21,7 +28,12 @@ describe RubyAsterisk::Response do
21
28
  Duration: 00:00:05
22
29
  AccountCode:
23
30
  BridgedChannel:
24
- BridgedUniqueID:"
31
+ BridgedUniqueID:
32
+
33
+ Event: CoreShowChannelsComplete
34
+ EventList: Complete
35
+ ListItems: 1
36
+ ActionID: 839"
25
37
  end
26
38
 
27
39
  def parked_calls_response
@@ -76,6 +88,11 @@ describe RubyAsterisk::Response do
76
88
  @response = RubyAsterisk::Response.new("CoreShowChannels",core_show_channels_response)
77
89
  @response.data[:channels][0]["CallerIDnum"].should eq("123456")
78
90
  end
91
+
92
+ it "should have no channels if answer is empty" do
93
+ @response = RubyAsterisk::Response.new("CoreShowChannels",empty_core_show_channels_response)
94
+ @response.data[:channels].count.should eq(0)
95
+ end
79
96
  end
80
97
 
81
98
  describe "receiving a Parked Calls request" do
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.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Emiliano Della Casa