prismic.io 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/prismic.rb +1 -0
- data/lib/prismic/api.rb +2 -1
- data/lib/prismic/experiments.rb +82 -0
- data/lib/prismic/version.rb +1 -1
- data/spec/experiments_spec.rb +52 -0
- data/spec/responses_mocks/experiments.json +39 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a922f0e6ee8a7f0deabb7e1c6e9d301634b82c
|
4
|
+
data.tar.gz: aeba97f56cd7799118b38779eb244fd544157b66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36746c2c5c6dd0238e04c1b42fc933853a60785bb64c6019c30eaa81f0a283e4b4f652163db79f810c46cc5f35a84e410f7e437fc6dd5fab6ca6a69276278d8
|
7
|
+
data.tar.gz: 5c16360d81add7976f534ba3a5fa479bb503be2eb49e346e90bc72160291b8d485984ac53a77a348678bdb007faea611e2de69905b6023fc9f8508469ad7b249
|
data/Gemfile.lock
CHANGED
data/lib/prismic.rb
CHANGED
data/lib/prismic/api.rb
CHANGED
@@ -7,7 +7,7 @@ module Prismic
|
|
7
7
|
@@warned_oauth_initiate_url = false
|
8
8
|
@@warned_oauth_check_token = false
|
9
9
|
attr_reader :json, :access_token, :http_client
|
10
|
-
attr_accessor :refs, :bookmarks, :forms, :tags, :types, :oauth, :cache
|
10
|
+
attr_accessor :refs, :bookmarks, :forms, :tags, :types, :experiments, :oauth, :cache
|
11
11
|
|
12
12
|
# Is the cache enabled on this API object?
|
13
13
|
#
|
@@ -150,6 +150,7 @@ module Prismic
|
|
150
150
|
api.tags = data['tags']
|
151
151
|
api.types = data['types']
|
152
152
|
api.oauth = OAuth.new(data['oauth_initiate'], data['oauth_token'], http_client)
|
153
|
+
api.experiments = Experiments.parse(data['experiments'])
|
153
154
|
}
|
154
155
|
end
|
155
156
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Prismic
|
3
|
+
|
4
|
+
class Experiments
|
5
|
+
attr_reader :draft, :running
|
6
|
+
|
7
|
+
def initialize(draft, running)
|
8
|
+
@draft = draft
|
9
|
+
@running = running
|
10
|
+
end
|
11
|
+
|
12
|
+
def current
|
13
|
+
running.first
|
14
|
+
end
|
15
|
+
|
16
|
+
def ref_from_cookie(cookie)
|
17
|
+
if cookie == nil
|
18
|
+
return nil
|
19
|
+
end
|
20
|
+
splitted = cookie.strip.split('%20')
|
21
|
+
if splitted.size >= 2
|
22
|
+
experiment = running.find { |exp| exp.google_id == splitted[0] }
|
23
|
+
if experiment == nil
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
var_index = splitted[1].to_i
|
27
|
+
if var_index > -1 && var_index < experiment.variations.size
|
28
|
+
return experiment.variations[var_index].ref
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse(data)
|
35
|
+
draft = []
|
36
|
+
running = []
|
37
|
+
if data != nil
|
38
|
+
draft = data['draft'].map { |exp|
|
39
|
+
Experiment.parse(exp)
|
40
|
+
}
|
41
|
+
running = data['running'].map { |exp|
|
42
|
+
Experiment.parse(exp)
|
43
|
+
}
|
44
|
+
end
|
45
|
+
new(draft, running)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class Experiment
|
51
|
+
attr_reader :id, :google_id, :name, :variations
|
52
|
+
|
53
|
+
def initialize(id, google_id, name, variations)
|
54
|
+
@id = id
|
55
|
+
@google_id = google_id
|
56
|
+
@name = name
|
57
|
+
@variations = variations
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.parse(data)
|
61
|
+
new(data['id'], data['googleId'], data['name'], data['variations'].map { |variation|
|
62
|
+
Variation.parse(variation)
|
63
|
+
})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Variation
|
68
|
+
attr_reader :id, :ref, :label
|
69
|
+
|
70
|
+
def initialize(id, ref, label)
|
71
|
+
@id = id
|
72
|
+
@ref = ref
|
73
|
+
@label = label
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.parse(data)
|
77
|
+
new(data['id'], data['ref'], data['label'])
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
data/lib/prismic/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Experiments'" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@raw_json_experiments = File.read("#{File.dirname(__FILE__)}/responses_mocks/experiments.json")
|
8
|
+
@json_experiments = JSON.load(@raw_json_experiments)
|
9
|
+
@experiments = Prismic::Experiments.parse(@json_experiments)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'response is properly parsed' do
|
13
|
+
first = @experiments.running[0]
|
14
|
+
first.id.should == 'VDUBBawGAKoGelsX'
|
15
|
+
first.google_id.should == '_UQtin7EQAOH5M34RQq6Dg'
|
16
|
+
first.name.should == 'Exp 1'
|
17
|
+
|
18
|
+
base = first.variations[0]
|
19
|
+
base.id.should == 'VDUBBawGAKoGelsZ'
|
20
|
+
base.label.should == 'Base'
|
21
|
+
base.ref.should == 'VDUBBawGALAGelsa'
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'cookies' do
|
25
|
+
it 'is empty' do
|
26
|
+
@experiments.ref_from_cookie('').should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'invalid content' do
|
30
|
+
@experiments.ref_from_cookie('Ponyes are awesome').should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'actual running variation index' do
|
34
|
+
@experiments.ref_from_cookie('_UQtin7EQAOH5M34RQq6Dg%200').should == 'VDUBBawGALAGelsa'
|
35
|
+
@experiments.ref_from_cookie('_UQtin7EQAOH5M34RQq6Dg%201').should == 'VDUUmHIKAZQKk9uq'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'index overflow' do
|
39
|
+
@experiments.ref_from_cookie('_UQtin7EQAOH5M34RQq6Dg%209').should be_nil
|
40
|
+
@experiments.ref_from_cookie('_UQtin7EQAOH5M34RQq6Dg%20-1').should be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'unknown Google ID' do
|
44
|
+
@experiments.ref_from_cookie('NotAGoodLookingId%200').should be_nil
|
45
|
+
@experiments.ref_from_cookie('NotAGoodLookingId%201').should be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"draft": [
|
3
|
+
{
|
4
|
+
"id": "xxxxxxxxxxoGelsX",
|
5
|
+
"name": "Exp 2",
|
6
|
+
"variations": [
|
7
|
+
{
|
8
|
+
"id": "VDUBBawGAKoGelsZ",
|
9
|
+
"label": "Base",
|
10
|
+
"ref": "VDUBBawGALAGelsa"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"id": "VDUE-awGALAGemME",
|
14
|
+
"label": "var 1",
|
15
|
+
"ref": "VDUUmHIKAZQKk9uq"
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
19
|
+
],
|
20
|
+
"running": [
|
21
|
+
{
|
22
|
+
"googleId": "_UQtin7EQAOH5M34RQq6Dg",
|
23
|
+
"id": "VDUBBawGAKoGelsX",
|
24
|
+
"name": "Exp 1",
|
25
|
+
"variations": [
|
26
|
+
{
|
27
|
+
"id": "VDUBBawGAKoGelsZ",
|
28
|
+
"label": "Base",
|
29
|
+
"ref": "VDUBBawGALAGelsa"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"id": "VDUE-awGALAGemME",
|
33
|
+
"label": "var 1",
|
34
|
+
"ref": "VDUUmHIKAZQKk9uq"
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prismic.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Étienne Vallette d'Osia
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-10-
|
14
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/prismic/api.rb
|
90
90
|
- lib/prismic/cache/basic.rb
|
91
91
|
- lib/prismic/cache/lru.rb
|
92
|
+
- lib/prismic/experiments.rb
|
92
93
|
- lib/prismic/form.rb
|
93
94
|
- lib/prismic/fragments.rb
|
94
95
|
- lib/prismic/fragments/color.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- prismic.gemspec
|
113
114
|
- spec/cache_spec.rb
|
114
115
|
- spec/doc_spec.rb
|
116
|
+
- spec/experiments_spec.rb
|
115
117
|
- spec/fragments_spec.rb
|
116
118
|
- spec/json_parsers_spec.rb
|
117
119
|
- spec/lesbonneschoses_spec.rb
|
@@ -122,6 +124,7 @@ files:
|
|
122
124
|
- spec/responses_mocks/api.json
|
123
125
|
- spec/responses_mocks/document.json
|
124
126
|
- spec/responses_mocks/document_with_unknown_fragment.json
|
127
|
+
- spec/responses_mocks/experiments.json
|
125
128
|
- spec/responses_mocks/fragments.json
|
126
129
|
- spec/responses_mocks/structured_text_heading.json
|
127
130
|
- spec/responses_mocks/structured_text_linkfile.json
|
@@ -156,6 +159,7 @@ summary: Prismic.io development kit
|
|
156
159
|
test_files:
|
157
160
|
- spec/cache_spec.rb
|
158
161
|
- spec/doc_spec.rb
|
162
|
+
- spec/experiments_spec.rb
|
159
163
|
- spec/fragments_spec.rb
|
160
164
|
- spec/json_parsers_spec.rb
|
161
165
|
- spec/lesbonneschoses_spec.rb
|
@@ -166,6 +170,7 @@ test_files:
|
|
166
170
|
- spec/responses_mocks/api.json
|
167
171
|
- spec/responses_mocks/document.json
|
168
172
|
- spec/responses_mocks/document_with_unknown_fragment.json
|
173
|
+
- spec/responses_mocks/experiments.json
|
169
174
|
- spec/responses_mocks/fragments.json
|
170
175
|
- spec/responses_mocks/structured_text_heading.json
|
171
176
|
- spec/responses_mocks/structured_text_linkfile.json
|