Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bklang committed Oct 31, 2014
2 parents 8b4e411 + 68c00d6 commit 1eef7a2
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 215 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
.bundle
pkg
Gemfile.lock
.*.sw*
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,5 @@
# develop
# Version 0.3.0
* Switch to Rackup-style app management

# Version 0.2.1
* Removed Octarine from dependencies
Expand Down
162 changes: 0 additions & 162 deletions Gemfile.lock

This file was deleted.

71 changes: 46 additions & 25 deletions README.md
@@ -1,42 +1,63 @@
# Virginia

Virginia is a Reel interface to Adhearsion, named after a dance originating in the 17th century, the Virginia Reel.
Virginia is a Reel interface to Adhearsion, named after a dance originating in the 17th century, the Virginia Reel. Now your web apps can dance with your voice apps!

It allows you to bundle a simple, Sinatra-style web interface with your Adhearsion application, enabling use of all the available APIs.
Virginia allows you to bundle a simple web interface in your Adhearsion application. You can use any Rack-compatible framework with Reel.

## Configuration

The plugin defines three configuration keys.

* host: Which IP to bind on (defaults to 0.0.0.0)
* port: Which port to listen on (defaults to 8080)
* handler: the Reel::Server class to use (see below)

## Handler
Virginia bundles a simple logging handler class that will answer to GET on "/" with OK and prints a log message in the Adhearsion console.

An example handler, implementing click-to-call, would be built as follows:

```ruby
require 'reel'

class RequestHandler
def initialize(host, port)
Reel::Server.supervise(host, port) do |connection|
connection.each_request do |request|
Adhearsion::OutboundCall.originate "SIP/100" do
invoke ConnectingController
end
[200, {}, "200 OK"]
end
end
end
* rackup: Location of the Rackup configuration file (defaults to config.ru)

## Sinatra Example

This example uses Sinatra, but this should work with any Rack-compatible framework.

### Update Gemfile

Add the framework gem to your Gemfile, in our case, Sinatra:

```Ruby
gem 'sinatra'
```

Don't forget to run `bundle install`.

### Create the app

Here is a simple "Hello World" app in Sinatra. Place this in `lib/sinatra_app.rb`:

```Ruby
require 'sinatra'

get '/' do
'Hello world!'
end
```

### Author
### Configure Rack

Finally, tell Rack how to start your web app. Place this in `config.ru`:

```Ruby
require "#{Adhearsion.root}/lib/sinatra_app.rb"
run Sinatra::Application
```

### Test the app

Start Adhearsion. You should be able to visit `http://localhost:8080/` in your browser and see "Hello world!"

### Contributors

Original author: [Luca Pradovera](https://github.com/polysics)

Contributors:
* [Ben Klang](https://github.com/bklang)

### Links

* [Adhearsion](http://adhearsion.com)
Expand All @@ -55,4 +76,4 @@ Original author: [Luca Pradovera](https://github.com/polysics)

### Copyright

Copyright (c) 2012 Adhearsion Foundation Inc. MIT license (see LICENSE for details).
Copyright (c) 2012-2014 Adhearsion Foundation Inc. MIT license (see LICENSE for details).
10 changes: 10 additions & 0 deletions Rakefile
@@ -1 +1,11 @@
# encoding: utf-8
require "bundler/gem_tasks"

require "rspec/core"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rspec_opts = '--color'
end

task :default => :spec
1 change: 0 additions & 1 deletion lib/virginia.rb
@@ -1,7 +1,6 @@
require "adhearsion"
require "active_support/dependencies/autoload"
require "virginia/version"
require "virginia/logging_handler"
require "virginia/plugin"

module Virginia
Expand Down
13 changes: 0 additions & 13 deletions lib/virginia/logging_handler.rb

This file was deleted.

8 changes: 5 additions & 3 deletions lib/virginia/plugin.rb
@@ -1,15 +1,17 @@
# encoding: utf-8

module Virginia
class Plugin < Adhearsion::Plugin

init :virginia do
logger.warn "Virginia has been loaded"
run :virginia do
logger.info "Virginia has been loaded"
Service.start
end

config :virginia do
host "0.0.0.0", :desc => "IP to bind the listener to"
port "8080", :desc => "The port to bind the listener to"
handler Virginia::LoggingHandler, :desc => "The object that will be handling the requests. Must be a Reel:App."
rackup 'config.ru', desc: 'Rack configuration file (relative to Adhearsion application root)'
end
end
end
18 changes: 17 additions & 1 deletion lib/virginia/service.rb
@@ -1,9 +1,25 @@
# encoding: utf-8
require 'reel'
require 'reel/rack'

module Virginia
class Service
def self.start
Adhearsion.config[:virginia].handler.new Adhearsion.config[:virginia].host, Adhearsion.config[:virginia].port
config = Adhearsion.config.virginia

# Rack-compatible options
app, options = ::Rack::Builder.parse_file File.join(Adhearsion.root, config[:rackup])
options = {
Host: config[:host],
Port: config[:port]
}.merge(options)

app = Rack::CommonLogger.new(app, Adhearsion.logger)
supervisor = ::Reel::Rack::Server.supervise_as(:reel_rack_server, app, options)

Adhearsion::Events.register_callback :shutdown do
supervisor.terminate
end
end
end
end
2 changes: 1 addition & 1 deletion lib/virginia/version.rb
@@ -1,3 +1,3 @@
module Virginia
VERSION = "0.2.1"
VERSION = "0.3.0"
end
1 change: 1 addition & 0 deletions spec/fixtures/config.ru
@@ -0,0 +1 @@
run TestApp
21 changes: 14 additions & 7 deletions spec/virginia/service_spec.rb
Expand Up @@ -6,17 +6,24 @@ def initialize(host, port)
end
end

let(:host) { "127.0.0.1" }
let(:port) { 8989 }
let(:handler) { DummyHandler }
let(:host) { "127.0.0.1" }
let(:port) { 8989 }
let(:options) { {Host: host, Port: port} }

before :each do
Adhearsion.config.virginia.host = host
Adhearsion.config.virginia.port = port
Adhearsion.config.virginia.handler = handler
Adhearsion.stub(:root).and_return '.'
Adhearsion.config.virginia.host = host
Adhearsion.config.virginia.port = port
Adhearsion.config.virginia.rackup = 'spec/fixtures/config.ru'
end

it "should instantiate the handler" do
handler.should_receive(:new).with(host, port)
rack_logger = mock 'Rack::CommonLogger'
::Rack::CommonLogger.should_receive(:new).once.with(TestApp, Adhearsion.logger).and_return rack_logger
::Reel::Rack::Server.should_receive(:supervise_as).once.with(:reel_rack_server, rack_logger, options)
Virginia::Service.start
end
end

class TestApp
end

0 comments on commit 1eef7a2

Please sign in to comment.