adhearsion_sinatra 0.0.1
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/Gemfile +22 -0
- data/README.md +56 -0
- data/Rakefile +10 -0
- data/lib/simon_game.rb +46 -0
- data/spec/call_controllers/simon_game_spec.rb +142 -0
- data/spec/spec_helper.rb +23 -0
- metadata +181 -0
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "adhearsion", "~> 2.3"
|
4
|
+
gem "adhearsion_sinatra", path: 'adhearsion_sinatra'
|
5
|
+
gem "xmarts_web_service", path: 'xmarts_web_service'
|
6
|
+
#
|
7
|
+
# Here are some example plugins you might like to use. Simply
|
8
|
+
# uncomment them and run `bundle install`.
|
9
|
+
#
|
10
|
+
|
11
|
+
gem 'adhearsion-asterisk'
|
12
|
+
# gem 'adhearsion_sequel'
|
13
|
+
|
14
|
+
# gem 'adhearsion-rails'
|
15
|
+
# gem 'adhearsion-activerecord'
|
16
|
+
# gem 'adhearsion-ldap'
|
17
|
+
# gem 'adhearsion-xmpp'
|
18
|
+
# gem 'adhearsion-drb'
|
19
|
+
|
20
|
+
group :development, :test do
|
21
|
+
gem 'rspec'
|
22
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Welcome to Adhearsion
|
2
|
+
|
3
|
+
You've got a fresh app and you're almost ready to get started. Firstly, you'll need to configure your VoIP platform:
|
4
|
+
|
5
|
+
## Asterisk
|
6
|
+
|
7
|
+
Edit `extensions.conf` to include the following:
|
8
|
+
|
9
|
+
```
|
10
|
+
[your_context_name]
|
11
|
+
exten => _.,1,AGI(agi:async)
|
12
|
+
```
|
13
|
+
|
14
|
+
and setup a user in `manager.conf` with read/write access to `all`.
|
15
|
+
|
16
|
+
If you are using Asterisk 1.8, you will need to add an additional context with the name `adhearsion-redirect`. On Asterisk 10 and above this is auto-provisioned.
|
17
|
+
|
18
|
+
## FreeSWITCH
|
19
|
+
|
20
|
+
* Ensure that mod_event_socket is installed, and configure it in autoload_configs/event_socket.conf.xml to taste
|
21
|
+
* Add an extension to your dialplan like so:
|
22
|
+
|
23
|
+
```xml
|
24
|
+
<extension name='Adhearsion'>
|
25
|
+
<condition field="destination_number" expression="^10$">
|
26
|
+
<action application="set" data="hangup_after_bridge=false"/>
|
27
|
+
<action application="set" data="park_after_bridge=true"/>
|
28
|
+
<action application='park'/>
|
29
|
+
</condition>
|
30
|
+
</extension>
|
31
|
+
```
|
32
|
+
|
33
|
+
## Voxeo PRISM
|
34
|
+
|
35
|
+
Install the [rayo-server](https://github.com/rayo/rayo-server) app into PRISM 11 and follow the [configuration guide](https://github.com/rayo/rayo-server/wiki/Single-node-and-cluster-configuration-reference).
|
36
|
+
|
37
|
+
## Configure your app
|
38
|
+
|
39
|
+
In `config/adhearsion.rb` you'll need to set the VoIP platform you're using, along with the correct credentials. You'll find example config there, so follow the comments.
|
40
|
+
|
41
|
+
## Ready, set, go!
|
42
|
+
|
43
|
+
Start your new app with "ahn start". You'll get a lovely console and should be presented with the SimonGame when you call in.
|
44
|
+
|
45
|
+
### Running your app on heroku
|
46
|
+
|
47
|
+
In order to run an adhearsion application on Heroku, you must create the application on the 'cedar' stack (`heroku apps:create --stack cedar`) and re-scale your processes like so:
|
48
|
+
|
49
|
+
```
|
50
|
+
heroku ps:scale web=0
|
51
|
+
heroku ps:scale ahn=1
|
52
|
+
```
|
53
|
+
|
54
|
+
More detail is available in the [deployment documentation](http://adhearsion.com/docs/best-practices/deployment).
|
55
|
+
|
56
|
+
Check out [the Adhearsion website](http://adhearsion.com) for more details of where to go from here.
|
data/Rakefile
ADDED
data/lib/simon_game.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class SimonGame < Adhearsion::CallController
|
4
|
+
|
5
|
+
attr_accessor :number, :attempt
|
6
|
+
|
7
|
+
def run
|
8
|
+
answer
|
9
|
+
reset
|
10
|
+
loop do
|
11
|
+
update_number
|
12
|
+
collect_attempt
|
13
|
+
verify_attempt
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def random_number
|
18
|
+
rand(10).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_number
|
22
|
+
@number << random_number
|
23
|
+
end
|
24
|
+
|
25
|
+
def collect_attempt
|
26
|
+
result = ask @number, :limit => @number.length
|
27
|
+
@attempt = result.response
|
28
|
+
end
|
29
|
+
|
30
|
+
def verify_attempt
|
31
|
+
if attempt_correct?
|
32
|
+
speak 'good'
|
33
|
+
else
|
34
|
+
speak "#{@number.length - 1} times wrong, try again smarty"
|
35
|
+
reset
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def attempt_correct?
|
40
|
+
@attempt == @number
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset
|
44
|
+
@attempt, @number = '', ''
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SimonGame do
|
6
|
+
|
7
|
+
let(:example_response) { OpenStruct.new(:response => "5") }
|
8
|
+
let(:example_number) { "5" }
|
9
|
+
let(:long_response) { OpenStruct.new(:response => "55555") }
|
10
|
+
let(:long_number) { "55555" }
|
11
|
+
|
12
|
+
let(:mock_call) { mock 'Call' }
|
13
|
+
subject { SimonGame.new(mock_call) }
|
14
|
+
|
15
|
+
describe "#random_number" do
|
16
|
+
|
17
|
+
before { subject.stub!(:rand).and_return(example_number) }
|
18
|
+
|
19
|
+
it "generates a random number" do
|
20
|
+
subject.random_number.should eq example_number
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#update_number" do
|
25
|
+
|
26
|
+
before { subject.number = "123" }
|
27
|
+
before { subject.stub!(:random_number).and_return "4" }
|
28
|
+
|
29
|
+
it "adds a digit to the end of the number" do
|
30
|
+
subject.update_number
|
31
|
+
subject.number.should eq "1234"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#collect_attempt" do
|
36
|
+
|
37
|
+
context "when the @number is 1 digit long" do
|
38
|
+
|
39
|
+
before { subject.number = "3" }
|
40
|
+
|
41
|
+
it "asks for a 1 digits number" do
|
42
|
+
subject.should_receive(:ask).with("3", :limit => 1).and_return(example_response)
|
43
|
+
subject.collect_attempt
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the @number is 5 digits long" do
|
48
|
+
|
49
|
+
before { subject.number = long_number }
|
50
|
+
|
51
|
+
it "asks for a 5 digits number" do
|
52
|
+
subject.should_receive(:ask).with(long_number, :limit => 5).and_return(long_response)
|
53
|
+
subject.collect_attempt
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "sets @attempt" do
|
58
|
+
|
59
|
+
before { subject.number = "12345" }
|
60
|
+
|
61
|
+
it "based on the user's response" do
|
62
|
+
subject.should_receive(:ask).with("12345", :limit => 5).and_return(long_response)
|
63
|
+
subject.collect_attempt
|
64
|
+
subject.attempt.should eq long_number
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#attempt_correct?" do
|
70
|
+
|
71
|
+
before { subject.number = "7" }
|
72
|
+
|
73
|
+
context "with a good attempt" do
|
74
|
+
|
75
|
+
before { subject.attempt = "7" }
|
76
|
+
|
77
|
+
it "returns true" do
|
78
|
+
subject.attempt_correct?.should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with a bad attempt" do
|
83
|
+
|
84
|
+
before { subject.attempt = "9" }
|
85
|
+
|
86
|
+
it "returns true" do
|
87
|
+
subject.attempt_correct?.should be_false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#verify_attempt" do
|
93
|
+
context "when the user is a good guesser" do
|
94
|
+
|
95
|
+
before { subject.stub!(:attempt_correct?).and_return true }
|
96
|
+
|
97
|
+
it "congradulates them" do
|
98
|
+
subject.should_receive(:speak).with('good')
|
99
|
+
subject.verify_attempt
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when the user guesses wrong" do
|
104
|
+
|
105
|
+
before { subject.number = "12345" }
|
106
|
+
before { subject.attempt = "12346" }
|
107
|
+
|
108
|
+
it "congradulates them" do
|
109
|
+
subject.should_receive(:speak).with('4 times wrong, try again smarty')
|
110
|
+
subject.verify_attempt
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#reset" do
|
116
|
+
|
117
|
+
before { subject.reset }
|
118
|
+
|
119
|
+
it "sets @number" do
|
120
|
+
subject.number.should eq ''
|
121
|
+
end
|
122
|
+
|
123
|
+
it "sets @attempt" do
|
124
|
+
subject.attempt.should eq ''
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#run" do
|
129
|
+
it "loops the loop" do
|
130
|
+
subject.should_receive :answer
|
131
|
+
subject.should_receive :reset
|
132
|
+
|
133
|
+
subject.should_receive :update_number
|
134
|
+
subject.should_receive :collect_attempt
|
135
|
+
subject.should_receive(:verify_attempt).and_throw :rspec_loop_stop
|
136
|
+
|
137
|
+
catch :rspec_loop_stop do
|
138
|
+
subject.run
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ENV["AHN_ENV"] ||= 'test'
|
4
|
+
require File.expand_path("../../config/environment", __FILE__)
|
5
|
+
require 'adhearsion/rspec'
|
6
|
+
require 'rspec/autorun'
|
7
|
+
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
+
# in spec/support/ and its subdirectories.
|
10
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
# ## Mock Framework
|
14
|
+
#
|
15
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
16
|
+
#
|
17
|
+
# config.mock_with :mocha
|
18
|
+
# config.mock_with :flexmock
|
19
|
+
# config.mock_with :rr
|
20
|
+
|
21
|
+
config.filter_run :focus => true
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adhearsion_sinatra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alvaro Parres
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: adhearsion
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.10
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.10
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sinatra
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.4.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.5'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.5'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: mocha
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: ''
|
143
|
+
email:
|
144
|
+
- aparres@gmail.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- lib/simon_game.rb
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- Gemfile
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/call_controllers/simon_game_spec.rb
|
155
|
+
homepage: ''
|
156
|
+
licenses: []
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ! '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project: adhearsion_sinatra
|
175
|
+
rubygems_version: 1.8.24
|
176
|
+
signing_key:
|
177
|
+
specification_version: 3
|
178
|
+
summary: Sinatra Integration
|
179
|
+
test_files:
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
- spec/call_controllers/simon_game_spec.rb
|