rami 0.2 → 0.3
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/CHANGELOG +5 -0
- data/bin/example1.rb +2 -0
- data/bin/example2.rb +1 -0
- data/lib/rami.rb +20 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/bin/example1.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/local/bin/ruby
|
|
2
2
|
|
|
3
|
+
## This shows how to use the Server and Client classes together, without using Server to create a separate proxy server.
|
|
3
4
|
require 'rubygems'
|
|
4
5
|
require 'rami'
|
|
5
6
|
include Rami
|
|
@@ -31,3 +32,4 @@ print_results(t)
|
|
|
31
32
|
t = client.get_events
|
|
32
33
|
print_results(t)
|
|
33
34
|
|
|
35
|
+
client.stop
|
data/bin/example2.rb
CHANGED
data/lib/rami.rb
CHANGED
|
@@ -102,6 +102,14 @@ class Client
|
|
|
102
102
|
@client = client
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
+
|
|
106
|
+
# Closes the socket connection to Asterisk. If your client was created using a Server instance instead of a DrbObject, then
|
|
107
|
+
# the connection will be left open as long as your client instance is still valid. If for example you are making calls from
|
|
108
|
+
# a webserver this is bad as you will end up with a lot of open connections to Asterisk. So make sure to use stop.
|
|
109
|
+
def stop
|
|
110
|
+
@client.stop
|
|
111
|
+
end
|
|
112
|
+
|
|
105
113
|
def absolute_timeout(channel=nil,tout=nil)
|
|
106
114
|
increment_action_id
|
|
107
115
|
return @client.send_action({'ActionID' => @action_id, 'Action' => 'AbsoluteTimeout', 'Channel' => channel, 'Timeout' => tout},@timeout)
|
|
@@ -361,6 +369,8 @@ def logger(type,msg)
|
|
|
361
369
|
end
|
|
362
370
|
end
|
|
363
371
|
|
|
372
|
+
|
|
373
|
+
|
|
364
374
|
def connect
|
|
365
375
|
@sock = TCPSocket.new(@host,@port)
|
|
366
376
|
login = {'Action' => 'login', 'Username' => @username, 'Secret' => @secret, 'Events' => 'On'}
|
|
@@ -394,8 +404,10 @@ def mainloop
|
|
|
394
404
|
|
|
395
405
|
ast_reader = Thread.new do
|
|
396
406
|
Thread.current.abort_on_exception=true
|
|
407
|
+
begin
|
|
397
408
|
linecount = 0
|
|
398
409
|
loop do
|
|
410
|
+
|
|
399
411
|
event = {}
|
|
400
412
|
@sock.each("\r\n") do |line|
|
|
401
413
|
linecount += 1
|
|
@@ -440,6 +452,9 @@ def mainloop
|
|
|
440
452
|
end
|
|
441
453
|
end
|
|
442
454
|
end
|
|
455
|
+
rescue IOError => e
|
|
456
|
+
puts "Socket disconnected #{e}"
|
|
457
|
+
end
|
|
443
458
|
end
|
|
444
459
|
end
|
|
445
460
|
|
|
@@ -471,6 +486,7 @@ end
|
|
|
471
486
|
|
|
472
487
|
public
|
|
473
488
|
|
|
489
|
+
|
|
474
490
|
# Starts the server and connects to asterisk.
|
|
475
491
|
def run
|
|
476
492
|
if connect
|
|
@@ -482,6 +498,10 @@ def run
|
|
|
482
498
|
mainloop
|
|
483
499
|
end
|
|
484
500
|
|
|
501
|
+
def stop
|
|
502
|
+
@sock.close
|
|
503
|
+
end
|
|
504
|
+
|
|
485
505
|
# Should only be called via Client
|
|
486
506
|
def find_events(key=nil,value=nil)
|
|
487
507
|
logger('find_events',"#{key}: #{value}")
|
metadata
CHANGED
|
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: rami
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: "0.
|
|
7
|
-
date: 2005-
|
|
6
|
+
version: "0.3"
|
|
7
|
+
date: 2005-11-02 00:00:00 -08:00
|
|
8
8
|
summary: A proxy server/client api for the Asterisk Manager Interface
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|