a_b 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/config/hoptoad.txt +1 -0
- data/features/api.feature +25 -0
- data/features/step_definitions/given.rb +7 -0
- data/features/step_definitions/then.rb +19 -0
- data/features/step_definitions/when.rb +11 -0
- data/gemspec.rb +2 -1
- data/lib/a_b.rb +3 -1
- data/lib/a_b/boot.rb +6 -1
- data/lib/a_b/controller/api.rb +2 -10
- data/lib/a_b/controller/pulse.rb +7 -0
- data/lib/a_b/helper/api.rb +9 -0
- metadata +18 -4
- data/features/example.feature +0 -10
- data/public/js/visit.js +0 -59
data/config/hoptoad.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
8e1bcc6760ff89ff94bad4b1dc282cb0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature: API
|
2
|
+
|
3
|
+
As a client
|
4
|
+
I want to retrieve test and variant data
|
5
|
+
I want retrieve a security token for use in JSON-P calls from the end user
|
6
|
+
In order to begin running tests
|
7
|
+
|
8
|
+
Scenario: An authorized client performs a GET request on /boot.json
|
9
|
+
Given an authorized token
|
10
|
+
When GET request /boot.json
|
11
|
+
Then return test names
|
12
|
+
And return variant names with visit counts
|
13
|
+
And return a JSON-P security token
|
14
|
+
|
15
|
+
Scenario: An authorized client performs a GET request on /convert.js
|
16
|
+
Given an authorized token
|
17
|
+
And a list of variant names
|
18
|
+
When GET request /convert.js
|
19
|
+
Then increment conversions for each variant
|
20
|
+
|
21
|
+
Scenario: An authorized client performs a GET request on /visit.js
|
22
|
+
Given an authorized token
|
23
|
+
And a list of variant names
|
24
|
+
When GET request /visit.js
|
25
|
+
Then increment visitors for each variant
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Then /^return test names$/ do
|
2
|
+
pending
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^return variant names with visit counts$/ do
|
6
|
+
pending
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^return a JSON\-P security token$/ do
|
10
|
+
pending
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^increment conversions for each variant$/ do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^increment visitors for each variant$/ do
|
18
|
+
pending
|
19
|
+
end
|
data/gemspec.rb
CHANGED
@@ -26,6 +26,7 @@ GEM_SPEC = Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency('haml', '=2.2.13')
|
27
27
|
s.add_dependency('rack', '=1.0.1')
|
28
28
|
s.add_dependency('rack-flash', '=0.1.1')
|
29
|
+
s.add_dependency('rack_hoptoad', '=0.0.3')
|
29
30
|
s.add_dependency('rack-test', '=0.5.1')
|
30
31
|
s.add_dependency('rspec', '=1.2.9')
|
31
32
|
s.add_dependency('shotgun', '=0.4')
|
@@ -37,5 +38,5 @@ GEM_SPEC = Gem::Specification.new do |s|
|
|
37
38
|
s.name = GEM_NAME
|
38
39
|
s.platform = Gem::Platform::RUBY
|
39
40
|
s.require_path = "lib"
|
40
|
-
s.version = "0.1.
|
41
|
+
s.version = "0.1.1"
|
41
42
|
end
|
data/lib/a_b.rb
CHANGED
@@ -5,7 +5,8 @@ gems = [
|
|
5
5
|
[ 'sinatra', '=0.9.4' ],
|
6
6
|
[ 'active_wrapper', '=0.2.1' ],
|
7
7
|
[ 'rack-flash', '=0.1.1' ],
|
8
|
-
[ 'authlogic', '=2.1.3' ]
|
8
|
+
[ 'authlogic', '=2.1.3' ],
|
9
|
+
[ 'rack_hoptoad', '=0.0.3' ]
|
9
10
|
]
|
10
11
|
|
11
12
|
gems.each do |name, version|
|
@@ -22,6 +23,7 @@ require 'sinatra/base'
|
|
22
23
|
require 'active_wrapper'
|
23
24
|
require 'rack-flash'
|
24
25
|
require 'authlogic'
|
26
|
+
require 'rack_hoptoad'
|
25
27
|
|
26
28
|
class Application < Sinatra::Base
|
27
29
|
end
|
data/lib/a_b/boot.rb
CHANGED
@@ -25,6 +25,11 @@ Application.class_eval do
|
|
25
25
|
use Rack::Flash, :accessorize => %w(error notice success)
|
26
26
|
|
27
27
|
# Generate token
|
28
|
-
require
|
28
|
+
require "#{root}/lib/a_b/model/token"
|
29
29
|
Token.generate!
|
30
|
+
|
31
|
+
# Hoptoad notifier
|
32
|
+
if File.exists?(hoptoad = "#{root}/config/hoptoad.txt")
|
33
|
+
use Rack::HoptoadNotifier, File.read(hoptoad)
|
34
|
+
end
|
30
35
|
end
|
data/lib/a_b/controller/api.rb
CHANGED
@@ -14,19 +14,11 @@ Application.class_eval do
|
|
14
14
|
|
15
15
|
get '/convert.js' do
|
16
16
|
return nil unless valid_token?
|
17
|
-
|
18
|
-
variant.increment!(:conversions)
|
19
|
-
end
|
20
|
-
'true'
|
17
|
+
increment :conversions
|
21
18
|
end
|
22
19
|
|
23
20
|
get '/visit.js' do
|
24
21
|
return nil unless valid_token?
|
25
|
-
|
26
|
-
variants.each do |variant|
|
27
|
-
variant.increment!(:visitors)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
redirect '/js/visit.js'
|
22
|
+
increment :visitors
|
31
23
|
end
|
32
24
|
end
|
data/lib/a_b/helper/api.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
Application.class_eval do
|
2
2
|
helpers do
|
3
3
|
|
4
|
+
def increment(attribute)
|
5
|
+
if params[:variants] && variants = ABVariant.find_all_by_name(params[:variants])
|
6
|
+
variants.each do |variant|
|
7
|
+
variant.increment! attribute
|
8
|
+
end
|
9
|
+
end
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
|
4
13
|
def valid_token?
|
5
14
|
Digest::SHA256.hexdigest(params[:session_id] + Token.cached) == params[:token]
|
6
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a_b
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,16 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 0.1.1
|
64
64
|
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rack_hoptoad
|
67
|
+
type: :runtime
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.0.3
|
74
|
+
version:
|
65
75
|
- !ruby/object:Gem::Dependency
|
66
76
|
name: rack-test
|
67
77
|
type: :runtime
|
@@ -123,13 +133,17 @@ extra_rdoc_files:
|
|
123
133
|
files:
|
124
134
|
- config/database.example.yml
|
125
135
|
- config/externals.yml
|
136
|
+
- config/hoptoad.txt
|
126
137
|
- config/mail.example.yml
|
127
138
|
- config.ru
|
128
139
|
- db/migrate/001_a_b_tests.rb
|
129
140
|
- db/migrate/002_a_b_variants.rb
|
130
141
|
- db/migrate/003_a_b_users.rb
|
131
142
|
- db/migrate/004_a_b_tokens.rb
|
132
|
-
- features/
|
143
|
+
- features/api.feature
|
144
|
+
- features/step_definitions/given.rb
|
145
|
+
- features/step_definitions/then.rb
|
146
|
+
- features/step_definitions/when.rb
|
133
147
|
- features/support/env.rb
|
134
148
|
- features/support/rspec.rb
|
135
149
|
- features/support/webrat.rb
|
@@ -138,6 +152,7 @@ files:
|
|
138
152
|
- lib/a_b/controller/api.rb
|
139
153
|
- lib/a_b/controller/application.rb
|
140
154
|
- lib/a_b/controller/index.rb
|
155
|
+
- lib/a_b/controller/pulse.rb
|
141
156
|
- lib/a_b/controller/sessions.rb
|
142
157
|
- lib/a_b/controller/tests.rb
|
143
158
|
- lib/a_b/controller/variants.rb
|
@@ -162,7 +177,6 @@ files:
|
|
162
177
|
- public/css/blueprint/screen.css
|
163
178
|
- public/js/index.js
|
164
179
|
- public/js/jquery.js
|
165
|
-
- public/js/visit.js
|
166
180
|
- Rakefile
|
167
181
|
- README.markdown
|
168
182
|
- script/console
|
data/features/example.feature
DELETED
data/public/js/visit.js
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
How this should work:
|
3
|
-
* Plugin generates visit() calls based on @a_b_selections
|
4
|
-
* convert() with a test looks
|
5
|
-
*/
|
6
|
-
|
7
|
-
window.A_B = new function() {
|
8
|
-
|
9
|
-
var $ = jQuery;
|
10
|
-
var conversions = {};
|
11
|
-
var visits = {};
|
12
|
-
var session_id, tests, token, url, visits;
|
13
|
-
|
14
|
-
$.extend(this, {
|
15
|
-
convert: convert,
|
16
|
-
setup: setup
|
17
|
-
});
|
18
|
-
|
19
|
-
window.a_b = function(variant) {
|
20
|
-
// TODO: Make this work like the Rails version
|
21
|
-
}
|
22
|
-
|
23
|
-
function convert(test_or_variant) {
|
24
|
-
var pair = test_variant_pair(test_or_variant);
|
25
|
-
console.log(pair);
|
26
|
-
if (!pair || !session_id || !token || !url)
|
27
|
-
return;
|
28
|
-
var params = [
|
29
|
-
'session_id=' + session_id,
|
30
|
-
'token=' + token,
|
31
|
-
'variant=' + pair[1].name
|
32
|
-
];
|
33
|
-
$.getJSON(url + '/convert.js?' + params.join('&'));
|
34
|
-
}
|
35
|
-
|
36
|
-
// Returns a [ test, variant ] pair given a test or variant
|
37
|
-
// Only returns if the variant has been used in a test (visited)
|
38
|
-
function test_variant_pair(test_or_variant) {
|
39
|
-
var result;
|
40
|
-
var v = visits[test_or_variant] || test_or_variant;
|
41
|
-
$.each(tests, function(i, test) {
|
42
|
-
$.each(test.variants, function(i, variant) {
|
43
|
-
if (variant.name == v && visits[test.name] == v) {
|
44
|
-
result = [ test, variant ];
|
45
|
-
return false;
|
46
|
-
}
|
47
|
-
});
|
48
|
-
});
|
49
|
-
return result;
|
50
|
-
}
|
51
|
-
|
52
|
-
function setup(options) {
|
53
|
-
session_id = options.session_id;
|
54
|
-
tests = options.tests;
|
55
|
-
token = options.token;
|
56
|
-
url = options.url;
|
57
|
-
visits = options.visits;
|
58
|
-
}
|
59
|
-
}
|