opensips-mi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZThhYmE0OGQxNWQ4ZTg2MGI0OWU3YTA2NmE1MjllZDJmYjU0YjIyYQ==
4
+ MzI1MTJhNjhmOGRmNTc2OGExN2JmZDcwMjI0YjFlODM2OGQ3M2UzYg==
5
5
  data.tar.gz: !binary |-
6
- MTQ4ZTAyYzViMWE2OGI3YmYzMTRhN2Y4Y2RhYWE3YWFmOTczMTc5Yw==
6
+ OWMzMmJkYjc4ZTA2YmRjMjZmMDY5YTJmZGQ5Zjk3OWVkMzY3NTA5Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWJmODcxMzQyNWM4MmEwNmYzOTkwYzg0MGI3NTJjY2JkZmE5MzZlYjA3OTNi
10
- NmU1YWI0Yjg0NmNlZDI1MmM4NDRjODFhNTRjNTExZDRmYTA0NmEwYjc3YzRi
11
- MjljMDJkOWJiZTJlZWI3MzMzYjY1ZTc3NDNlNTk5MjUzYmE2YjM=
9
+ MWIxZWYyZjRlNDAxZjBiMjg2YjFkM2M5ZmIzOGE2N2E1YzJlNjUwNjQ2Y2Y3
10
+ NzcyN2I1OTBiNGJlOTdjZWFhYWJjNTBhZjVkYjY1OTM5ZGU0Njk5YzMyMDVi
11
+ OTc1Yzk4YmZmODJmNTg0NDE2ZGRjYThhODE4ZmUyYmYzNGNhYjE=
12
12
  data.tar.gz: !binary |-
13
- ZjUwNzE0ZTU2ODJjMTgwMTQ3NzgwZjgyODM5NjA3MWU4MjZjMjUyZGU4MjBk
14
- ZmFlYjZkYmRkMjFkYTdhYmE4YWJmYzYzMzMyNGZhOTE1ZmMzYTllNDgzNzBl
15
- YTc5MGY4MmIyZTlhNGVmNGU1NzhlZWE0M2VkYjI5ZDY2ZTkyNDg=
13
+ YzVjNzQ2OGU1MWU0MzQ4MWE4YmMyMTIxNmM5ZjNmNGRjMDI4NmUxNjBmNzM1
14
+ MjhkNWNkNjA1NmI2OWM3ZTI3NTJlMWIzNGQ5Nzk2ZWM5ZDIxMDc5ZDQ3MjBh
15
+ ODRmMWIzMGZkM2M4ZGRlNjFkNGM3OTU5ZmZmNmJmMDM4ZDg1ZGY=
data/.gitignore CHANGED
@@ -8,6 +8,7 @@ Gemfile*.lock
8
8
  .bundle
9
9
  .config
10
10
  coverage
11
+ log
11
12
  InstalledFiles
12
13
  lib/bundler/man
13
14
  pkg
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
3
2
 
3
+ group :test do
4
+ gem 'coveralls', require: false
5
+ gem 'simplecov' #, :require => false
6
+ gem 'mocha'
7
+ end
4
8
 
9
+ gemspec
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Build Status](https://travis-ci.org/staskobzar/opensips-mi.png?branch=master)](https://travis-ci.org/staskobzar/opensips-mi)
3
3
  [![Code Climate](https://codeclimate.com/github/staskobzar/opensips-mi.png)](https://codeclimate.com/github/staskobzar/opensips-mi)
4
4
  [![Gem Version](https://badge.fury.io/rb/opensips-mi.png)](http://badge.fury.io/rb/opensips-mi)
5
+ [![Coverage Status](https://coveralls.io/repos/staskobzar/opensips-mi/badge.png?branch=master)](https://coveralls.io/r/staskobzar/opensips-mi)
5
6
 
6
7
  OpenSIPs management interface library.
7
8
  This library supports following management interfaces OpenSIPs modules:
@@ -26,11 +27,11 @@ Or install it yourself as:
26
27
 
27
28
  ## Connecting management interfaces
28
29
 
29
- ### Generic connection interface
30
+ ### Generic function to connect mi
30
31
 
31
32
  Using generic function to connect management interface:
32
33
  ```ruby
33
- require 'opensips-mi'
34
+ require 'opensips/mi'
34
35
  Opensips::MI.connect INTERFACE, PARAMS
35
36
  ```
36
37
  Parameters:
@@ -53,7 +54,7 @@ Function returns instance of one of the following classes:
53
54
  ### FIFO
54
55
 
55
56
  ```ruby
56
- require 'opensips-mi'
57
+ require 'opensips/mi'
57
58
  opensips = Opensips::MI.connect :fifo,
58
59
  :fifo_name => '/tmp/opensips_fifo',
59
60
  :reply_fifo => 'opensips_reply' . $$,
@@ -69,7 +70,7 @@ opensips = Opensips::MI.connect :fifo,
69
70
 
70
71
  ### Datagram
71
72
  ```ruby
72
- require 'opensips-mi'
73
+ require 'opensips/mi'
73
74
  opensips = Opensips::MI.connect :datagram,
74
75
  :host => "sipproxy.com",
75
76
  :port => 8809
@@ -81,7 +82,7 @@ opensips = Opensips::MI.connect :datagram,
81
82
 
82
83
  ### XMLRPC
83
84
  ```ruby
84
- require 'opensips-mi'
85
+ require 'opensips/mi'
85
86
  opensips = Opensips::MI.connect :xmlrpc,
86
87
  :host => "192.168.2.133",
87
88
  :port => 8080
@@ -98,7 +99,7 @@ Command parameters' description can be found in module documentation. For exampl
98
99
  Usage example:
99
100
 
100
101
  ```ruby
101
- require 'opensips-mi'
102
+ require 'opensips/mi'
102
103
  opensips = Opensips::MI.connect :fifo,
103
104
  :fifo_name => '/tmp/opensips_fifo'
104
105
 
@@ -110,7 +111,7 @@ opensips.command('get_statistics', 'dialog','tm')
110
111
 
111
112
  It is also possible to use command names as a method interface:
112
113
  ```ruby
113
- require 'opensips-mi'
114
+ require 'opensips/mi'
114
115
  opensips = Opensips::MI.connect :datagram,
115
116
  :host => "192.168.122.128",
116
117
  :port => 8809
@@ -12,10 +12,9 @@ require "opensips/mi/transport"
12
12
  module Opensips
13
13
  module MI
14
14
  def self.connect(transport, params)
15
- class_name = transport.to_s.capitalize
16
15
  # send to transport class
17
- Transport.const_get(class_name).init params
18
- rescue NameError => e
16
+ Transport.const_get(transport.to_s.capitalize).init params
17
+ rescue NameError
19
18
  raise NameError, "Unknown transport method: " << transport.to_s
20
19
  end
21
20
  end
@@ -114,7 +114,32 @@ module Opensips
114
114
  self
115
115
  end
116
116
 
117
- end
117
+ def dr_gw_status
118
+ return self if @rawdata.empty?
119
+ if /\AEnabled::\s+(?<status>yes|no)/ =~ @rawdata[0]
120
+ self.class.send(:define_method, :enabled, proc{status.eql?('yes')})
121
+ return self
122
+ end
123
+ @result = dr_gws_hash
124
+ self
125
+ end
126
+
127
+ private
128
+ def dr_gws_hash
129
+ Hash[
130
+ @rawdata.map do |gw|
131
+ if /\AID::\s+(?<id>[^\s]+)\s+IP=(?<ip>[^:]+):(?<port>\d+)\s+Enabled=(?<status>yes|no)/ =~ gw
132
+ [id, {
133
+ enabled: status.eql?('yes'),
134
+ ipaddr: ip,
135
+ port: port
136
+ }]
137
+ end
138
+ end
139
+ ]
140
+ end
141
+
142
+ end # END class
118
143
 
119
144
  class InvalidResponseData < Exception;end
120
145
  class EmptyResponseData < Exception;end
@@ -1,5 +1,5 @@
1
1
  module Opensips
2
2
  module MI
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -20,5 +20,4 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency('bundler', '~> 1.3')
21
21
  gem.add_development_dependency('rdoc')
22
22
  gem.add_development_dependency('rake')
23
- gem.add_development_dependency('mocha')
24
23
  end
@@ -1,12 +1,18 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start
10
+
1
11
  require 'minitest/autorun'
2
12
  require 'mocha/setup'
3
13
  require 'stringio'
4
14
  require 'opensips/mi'
5
15
 
6
-
7
-
8
- require 'pp'
9
-
10
16
  class MiniTest::Unit::TestCase
11
17
 
12
18
  def init_class_fifo
@@ -36,6 +42,36 @@ class MiniTest::Unit::TestCase
36
42
  File.readlines(fix).map{|l| l.chomp}
37
43
  end
38
44
 
45
+ def response_dr_gw_status_cmd
46
+ Array[
47
+ "200 OK",
48
+ ""
49
+ ]
50
+ end
51
+
52
+ def response_dr_gw_status_single
53
+ Array[
54
+ "200 OK",
55
+ "Enabled:: yes",
56
+ ""
57
+ ]
58
+ end
59
+
60
+ def response_dr_gw_status_list
61
+ Array[
62
+ "200 OK",
63
+ "ID:: gw1 IP=212.182.133.202:5060 Enabled=no ",
64
+ "ID:: gw2 IP=213.15.222.97:5060 Enabled=yes",
65
+ "ID:: gw3 IP=200.182.132.201:5060 Enabled=yes",
66
+ "ID:: gw4 IP=200.182.135.204:5060 Enabled=yes",
67
+ "ID:: pstn1 IP=199.18.14.101:5060 Enabled=yes",
68
+ "ID:: pstn2 IP=199.18.14.102:5060 Enabled=no",
69
+ "ID:: pstn3 IP=199.18.12.103:5060 Enabled=yes",
70
+ "ID:: pstn4 IP=199.18.12.104:5060 Enabled=yes",
71
+ ""
72
+ ]
73
+ end
74
+
39
75
  def response_contacts
40
76
  [
41
77
  "200 OK",
@@ -17,6 +17,14 @@ describe Command, "commands for transport classes" do
17
17
  }.must_raise NoMethodError
18
18
  end
19
19
 
20
+ it "must send command" do
21
+ mi = init_class_fifo
22
+ mi.expects(:command).with('which').returns(Opensips::MI::Response.new(response_data_cmd_which))
23
+ mi.expects(:command).with('ul_sync',[]).returns(Opensips::MI::Response.new(["200 OK",""]))
24
+ mi.ul_sync.code.must_equal 200
25
+
26
+ end
27
+
20
28
  it "must raise when missing basic mandatory headers" do
21
29
  mi = init_class_fifo
22
30
  ret = proc {
@@ -96,6 +96,29 @@ describe Response, "response class" do
96
96
  res.size.must_equal 1
97
97
  res["3212:2099935485"][:callid].must_equal "1854719653"
98
98
  end
99
+
100
+ it "must process dr_gw_status response in hash" do
101
+ response = Response.new response_dr_gw_status_list
102
+ drgws = response.dr_gw_status
103
+ drgws.result.size.must_equal 8
104
+ drgws.result["pstn4"][:ipaddr].must_equal "199.18.12.104"
105
+ drgws.result["pstn3"][:port].must_equal "5060"
106
+ drgws.result["gw1"][:enabled].must_equal false
107
+ drgws.result["gw4"][:enabled].must_equal true
108
+ end
109
+
110
+ it "must return raw data if dr_gw_status is run with arguments" do
111
+ response = Response.new response_dr_gw_status_single
112
+ drgws = response.dr_gw_status
113
+ drgws.enabled.must_equal true
114
+ end
115
+
116
+ it "result must be empty if command send to dr_gw_status" do
117
+ response = Response.new response_dr_gw_status_cmd
118
+ drgws = response.dr_gw_status
119
+ drgws.result.must_equal nil
120
+ drgws.success.must_equal true
121
+ end
99
122
  end
100
123
 
101
124
  end
@@ -137,6 +137,21 @@ describe Opensips::MI::Transport, "testing MI transport layers" do
137
137
  res.respond_to?(:uac_dlg).must_equal true
138
138
  end
139
139
 
140
+ it "must send valid command to socket" do
141
+ cmd = 'command'
142
+ params = ["aaa","bbb","ccc"]
143
+
144
+ sock = mock('UDPSocket')
145
+ sock.stubs(:connect)
146
+ sock.stubs(:send).with([":#{cmd}:", *params].join(?\n) + ?\n, 0)
147
+ sock.stubs(:recvfrom).returns( response_data_cmd_which )
148
+ UDPSocket.expects(:new).returns(sock)
149
+ res = Opensips::MI.connect :datagram,
150
+ :host => "192.168.122.128",
151
+ :port => 8809
152
+ res.command(cmd, params).code.must_equal 200
153
+ end
154
+
140
155
  end
141
156
 
142
157
  # XMLRPC
@@ -174,12 +189,19 @@ describe Opensips::MI::Transport, "testing MI transport layers" do
174
189
  it "must connect to xmlrpc server" do
175
190
  host = "192.168.122.128"
176
191
  port = 8080
177
- XMLRPC::Client.stubs(:new_from_uri).
192
+ rpc = mock('XMLRPC::Client')
193
+ rpc.stubs(:new_from_uri).
178
194
  with("http://#{host}:#{port}/#{Opensips::MI::Transport::Xmlrpc::RPCSEG}",nil,3)
179
195
  res = Opensips::MI.connect :xmlrpc,
180
196
  :host => host,
181
197
  :port => port
198
+
182
199
  res.respond_to?(:uac_dlg).must_equal true
200
+
201
+ params = ["aaa","bbb"]
202
+ cmd = "command"
203
+ rpc.stubs(:call).with(cmd, *params).returns( response_data_cmd_which )
204
+ res.command(cmd, params) #.must_be_instance_of Opensips::MI::Response
183
205
  end
184
206
 
185
207
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensips-mi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Kobzar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-17 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: mocha
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  description: Ruby module for interacting with OpenSIPs management interface
70
56
  email:
71
57
  - stas@modulis.ca
@@ -114,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
100
  version: '0'
115
101
  requirements: []
116
102
  rubyforge_project:
117
- rubygems_version: 2.0.2
103
+ rubygems_version: 2.0.3
118
104
  signing_key:
119
105
  specification_version: 4
120
106
  summary: OpenSIPs management interface