ruby_ami 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +3 -0
- data/Guardfile +1 -1
- data/README.md +30 -2
- data/features/lexer.feature +2 -2
- data/features/step_definitions/lexer_steps.rb +1 -1
- data/lib/ruby_ami/lexer.rb +1 -1
- data/lib/ruby_ami/stream.rb +4 -0
- data/lib/ruby_ami/version.rb +1 -1
- data/spec/ruby_ami/stream_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ab0e1cb98c4b9cc7937dce36985dd5f928f3b6
|
4
|
+
data.tar.gz: b933392977d95722eacbe58881d6a61848f9652c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e9e1e68b4c7526f2c0943575285f95c19dd8a466d53b514115a524eb2d38806bea6bf962d6a169fc734be01e5d564b00ae1c5a9fdd7bee5e5a8107cfb8a100e
|
7
|
+
data.tar.gz: 98128f68562f0971c1b6912b52626fbe5bc6b6ed930dd7c6365640cf515b3ec8337f3eb1478e7e4018b8a7bac95eafda388eb56fe306262dc87f5a5161b29be0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# [develop](https://github.com/adhearsion/ruby_ami)
|
2
2
|
|
3
|
+
# [2.4.0](https://github.com/adhearsion/ruby_ami/compare/v2.3.0...v2.4.0) - [2015-12-07](https://rubygems.org/gems/ruby_ami/versions/2.4.0)
|
4
|
+
# Feature: Reveal the AMI version for a `Stream` via `Stream#version`
|
5
|
+
|
3
6
|
# [2.3.0](https://github.com/adhearsion/ruby_ami/compare/v2.2.1...v2.3.0) - [2015-06-01](https://rubygems.org/gems/ruby_ami/versions/2.3.0)
|
4
7
|
* Feature: Allow optional error handler when calling `send_action`
|
5
8
|
* Bugfix: Catch for Errno::HOSTUNREACH error when connecting to AMI
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -15,23 +15,51 @@ NB: If you're looking to develop an application on Asterisk, you should take a l
|
|
15
15
|
gem install ruby_ami
|
16
16
|
|
17
17
|
## Usage
|
18
|
+
|
19
|
+
In order to setup a connection to listen for AMI events, one can do:
|
20
|
+
|
18
21
|
```ruby
|
19
22
|
require 'ruby_ami'
|
20
23
|
|
21
|
-
|
24
|
+
stream = RubyAMI::Stream.new '127.0.0.1', 5038, 'manager', 'password',
|
22
25
|
->(e) { handle_event e },
|
23
26
|
Logger.new(STDOUT), 10
|
24
27
|
|
25
28
|
def handle_event(event)
|
26
29
|
case event.name
|
27
30
|
when 'FullyBooted'
|
28
|
-
|
31
|
+
puts "The server booted and is available for commands."
|
32
|
+
else
|
33
|
+
puts "Received an event from Asterisk: #{event.inspect}"
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
37
|
$stream.run # This will block until the actor is terminated elsewhere. $stream.async.run is also available if you need to do other things in the main thread.
|
33
38
|
```
|
34
39
|
|
40
|
+
It is also possible to execute actions in response to events:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'ruby_ami'
|
44
|
+
|
45
|
+
$stream = RubyAMI::Stream.new '127.0.0.1', 5038, 'manager', 'password',
|
46
|
+
->(e) { handle_event e },
|
47
|
+
Logger.new(STDOUT), 10
|
48
|
+
|
49
|
+
def handle_event(event)
|
50
|
+
case event.name
|
51
|
+
when 'FullyBooted'
|
52
|
+
puts "The connection was successful. Originating a call."
|
53
|
+
response = $stream.send_action 'Originate', 'Channel' => 'SIP/foo'
|
54
|
+
puts "The call origination resulted in #{response.inspect}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
$stream.run
|
59
|
+
```
|
60
|
+
|
61
|
+
Executing actions does not strictly have to be done within the event handler, but it is not valid to send AMI events before receiving a `FullyBooted` event. If you attempt to execute an action prior to this, it may fail, and `RubyAMI::Stream` will not help you recover or queue the action until the connection is `FullyBooted`; you must manage this timing yourself. That said, assuming you take care of this, you may invoke `RubyAMI::Stream#send_action` from anywhere in your code and it will return the response of the action.
|
62
|
+
|
35
63
|
RubyAMI also has a class called `RubyAMI::Client` which used to be the main usage method. The purpose of this class was to tie together two AMI connections and separate events and action execution between the two in order to avoid some issues present in Asterisk < 1.8 with regards to separating overlapping events and executing multiple actions simultaneously. These issues are no longer present, and so **`RubyAMI::Client` is now deprecated and will be removed in RubyAMI 3.0**.
|
36
64
|
|
37
65
|
## Links:
|
data/features/lexer.feature
CHANGED
@@ -5,10 +5,10 @@ Feature: Lexing AMI
|
|
5
5
|
|
6
6
|
Scenario: Lexing only the initial AMI version header
|
7
7
|
Given a new lexer
|
8
|
-
And a version header for AMI
|
8
|
+
And a version header for AMI 2.8.0
|
9
9
|
|
10
10
|
Then the protocol should have lexed without syntax errors
|
11
|
-
And the version should be set to
|
11
|
+
And the version should be set to 2.8.0
|
12
12
|
|
13
13
|
Scenario: Lexing the initial AMI header and a login attempt
|
14
14
|
Given a new lexer
|
data/lib/ruby_ami/lexer.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module RubyAMI
|
4
4
|
class Lexer
|
5
5
|
STANZA_BREAK = "\r\n\r\n"
|
6
|
-
PROMPT = /Asterisk Call Manager\/(\d
|
6
|
+
PROMPT = /Asterisk Call Manager\/(\d+(\.\d+)*)\r\n/
|
7
7
|
KEYVALUEPAIR = /^([[[:alnum:]]-_ ]+): *(.*)\r\n/
|
8
8
|
FOLLOWSDELIMITER = /\r?\n?--END COMMAND--\r\n\r\n/
|
9
9
|
SUCCESS = /response: *success/i
|
data/lib/ruby_ami/stream.rb
CHANGED
data/lib/ruby_ami/version.rb
CHANGED
@@ -59,6 +59,25 @@ module RubyAMI
|
|
59
59
|
mocked_server 0, -> { @stream.started?.should be_true }
|
60
60
|
end
|
61
61
|
|
62
|
+
it "stores the reported AMI version" do
|
63
|
+
expect_connected_event
|
64
|
+
expect_disconnected_event
|
65
|
+
mocked_server(1, lambda {
|
66
|
+
@stream.send_action('Command') # Just to get the server kicked in to replying using the below block
|
67
|
+
expect(@stream.version).to eq('2.8.0')
|
68
|
+
}) do |val, server|
|
69
|
+
server.send_data "Asterisk Call Manager/2.8.0\n"
|
70
|
+
|
71
|
+
# Just to unblock the above command before the actor shuts down
|
72
|
+
server.send_data <<-EVENT
|
73
|
+
Response: Success
|
74
|
+
ActionID: #{RubyAMI.new_uuid}
|
75
|
+
Message: Recording started
|
76
|
+
|
77
|
+
EVENT
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
62
81
|
it "can send an action" do
|
63
82
|
expect_connected_event
|
64
83
|
expect_disconnected_event
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Langfeld
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid-io
|