Skip to content

Commit

Permalink
Ensure that the AMI version is reported on the Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Dec 7, 2015
1 parent 1a1f4f5 commit 5a383a1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# [develop](https://github.com/adhearsion/ruby_ami)
# Feature: Reveal the AMI version for a `Stream` via `Stream#version`

# [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)
* Feature: Allow optional error handler when calling `send_action`
Expand Down
4 changes: 2 additions & 2 deletions features/lexer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Feature: Lexing AMI

Scenario: Lexing only the initial AMI version header
Given a new lexer
And a version header for AMI 1.0
And a version header for AMI 2.8.0

Then the protocol should have lexed without syntax errors
And the version should be set to 1.0
And the version should be set to 2.8.0

Scenario: Lexing the initial AMI header and a login attempt
Given a new lexer
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/lexer_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

Given "a version header for AMI $version" do |version|
@lexer << "Asterisk Call Manager/1.0\r\n"
@lexer << "Asterisk Call Manager/#{version}\r\n"
end

Given "a normal login success with events" do
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_ami/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RubyAMI
class Lexer
STANZA_BREAK = "\r\n\r\n"
PROMPT = /Asterisk Call Manager\/(\d+\.\d+)\r\n/
PROMPT = /Asterisk Call Manager\/(\d+(\.\d+)*)\r\n/
KEYVALUEPAIR = /^([[[:alnum:]]-_ ]+): *(.*)\r\n/
FOLLOWSDELIMITER = /\r?\n?--END COMMAND--\r\n\r\n/
SUCCESS = /response: *success/i
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_ami/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def post_init
login @username, @password if @username && @password
end

def version
@lexer.ami_version
end

def send_data(data)
@socket.write data
end
Expand Down
19 changes: 19 additions & 0 deletions spec/ruby_ami/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ def expect_disconnected_event
mocked_server 0, -> { @stream.started?.should be_true }
end

it "stores the reported AMI version" do
expect_connected_event
expect_disconnected_event
mocked_server(1, lambda {
@stream.send_action('Command') # Just to get the server kicked in to replying using the below block
expect(@stream.version).to eq('2.8.0')
}) do |val, server|
server.send_data "Asterisk Call Manager/2.8.0\n"

# Just to unblock the above command before the actor shuts down
server.send_data <<-EVENT
Response: Success
ActionID: #{RubyAMI.new_uuid}
Message: Recording started
EVENT
end
end

it "can send an action" do
expect_connected_event
expect_disconnected_event
Expand Down

0 comments on commit 5a383a1

Please sign in to comment.