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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5953bb5e6fa27b0deeee4847c2a858ac569fcc0a
4
- data.tar.gz: 55cf2a66637e697c1395e89da1ae2c6d79dd05cf
3
+ metadata.gz: 78ab0e1cb98c4b9cc7937dce36985dd5f928f3b6
4
+ data.tar.gz: b933392977d95722eacbe58881d6a61848f9652c
5
5
  SHA512:
6
- metadata.gz: a98f86436f743270e3d0950a3056ac3ed673df03648379726a86a28717cc059688f94aded13b090c98cb25e7456a2c61af60179d2702dcacd53dd2ed5d4e298f
7
- data.tar.gz: d5a21a2b1bd5e35813a38d724415a3acd519a4461e9690ef0e2bd177a1d74037c3bc2cf62bc34748b4b8c447866130ac996fb7b87763f4901e081c31a8a2a8cb
6
+ metadata.gz: 4e9e1e68b4c7526f2c0943575285f95c19dd8a466d53b514115a524eb2d38806bea6bf962d6a169fc734be01e5d564b00ae1c5a9fdd7bee5e5a8107cfb8a100e
7
+ data.tar.gz: 98128f68562f0971c1b6912b52626fbe5bc6b6ed930dd7c6365640cf515b3ec8337f3eb1478e7e4018b8a7bac95eafda388eb56fe306262dc87f5a5161b29be0
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
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
@@ -1,4 +1,4 @@
1
- guard 'rspec', :cli => '--format documentation' do
1
+ guard 'rspec', cmd: 'bundle exec rspec --format documentation' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec/" }
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
- $stream = RubyAMI::Stream.new '127.0.0.1', 5038, 'manager', 'password',
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
- $stream.async.send_action 'Originate', 'Channel' => 'SIP/foo'
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:
@@ -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 1.0
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 1.0
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
@@ -17,7 +17,7 @@ Given "a new lexer" do
17
17
  end
18
18
 
19
19
  Given "a version header for AMI $version" do |version|
20
- @lexer << "Asterisk Call Manager/1.0\r\n"
20
+ @lexer << "Asterisk Call Manager/#{version}\r\n"
21
21
  end
22
22
 
23
23
  Given "a normal login success with events" do
@@ -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+\.\d+)\r\n/
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
@@ -57,6 +57,10 @@ module RubyAMI
57
57
  login @username, @password if @username && @password
58
58
  end
59
59
 
60
+ def version
61
+ @lexer.ami_version
62
+ end
63
+
60
64
  def send_data(data)
61
65
  @socket.write data
62
66
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RubyAMI
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
  end
@@ -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.3.0
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-06-03 00:00:00.000000000 Z
12
+ date: 2015-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid-io