Skip to content

Commit eeea135

Browse files
msohailhussainMichael Ng
authored andcommitted
feat(epmodel): Event Processor datamodel (#184)
1 parent c51968f commit eeea135

File tree

12 files changed

+594
-0
lines changed

12 files changed

+594
-0
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Metrics/ParameterLists:
2424
- 'lib/optimizely/config_manager/http_project_config_manager.rb'
2525
- 'lib/optimizely.rb'
2626
- 'lib/optimizely/optimizely_factory.rb'
27+
- 'lib/optimizely/event/entity/snapshot_event.rb'
2728

2829
Naming/AccessorMethodName:
2930
Exclude:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
require_relative 'user_event'
19+
module Optimizely
20+
class ConversionEvent < UserEvent
21+
attr_reader :event_context, :event, :user_id, :visitor_attributes, :tags, :bot_filtering
22+
23+
def initialize(
24+
event_context,
25+
event,
26+
user_id,
27+
visitor_attributes,
28+
tags,
29+
bot_filtering = nil
30+
)
31+
@event_context = event_context
32+
@event = event
33+
@user_id = user_id
34+
@visitor_attributes = visitor_attributes
35+
@tags = tags
36+
@bot_filtering = bot_filtering
37+
end
38+
end
39+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class Decision
20+
attr_reader :campaign_id, :experiment_id, :variation_id
21+
22+
def initialize(campaign_id, experiment_id, variation_id)
23+
@campaign_id = campaign_id
24+
@experiment_id = experiment_id
25+
@variation_id = variation_id
26+
end
27+
28+
def as_json
29+
{
30+
campaign_id: @campaign_id,
31+
experiment_id: @experiment_id,
32+
variation_id: @variation_id
33+
}
34+
end
35+
end
36+
end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class EventBatch
20+
attr_accessor :account_id, :project_id, :revision, :client_name, :client_version,
21+
:anonymize_ip, :enrich_decisions, :visitors
22+
23+
def as_json
24+
{
25+
account_id: @account_id,
26+
project_id: @project_id,
27+
revision: @revision,
28+
client_name: @client_name,
29+
client_version: @client_version,
30+
anonymize_ip: @anonymize_ip,
31+
enrich_decisions: @enrich_decisions,
32+
visitors: @visitors
33+
}
34+
end
35+
36+
class Builder
37+
attr_reader :account_id, :project_id, :revision, :client_name, :client_version,
38+
:anonymize_ip, :enrich_decisions, :visitors
39+
40+
def build
41+
event_batch = EventBatch.new
42+
event_batch.account_id = @account_id
43+
event_batch.project_id = @project_id
44+
event_batch.revision = @revision
45+
event_batch.client_name = @client_name
46+
event_batch.client_version = @client_version
47+
event_batch.anonymize_ip = @anonymize_ip
48+
event_batch.enrich_decisions = @enrich_decisions
49+
event_batch.visitors = @visitors
50+
event_batch
51+
end
52+
53+
def with_account_id(account_id)
54+
@account_id = account_id
55+
end
56+
57+
def with_project_id(project_id)
58+
@project_id = project_id
59+
end
60+
61+
def with_revision(revision)
62+
@revision = revision
63+
end
64+
65+
def with_client_name(client_name)
66+
@client_name = client_name
67+
end
68+
69+
def with_client_version(client_version)
70+
@client_version = client_version
71+
end
72+
73+
def with_anonymize_ip(anonymize_ip)
74+
@anonymize_ip = anonymize_ip
75+
end
76+
77+
def with_enrich_decisions(enrich_decisions)
78+
@enrich_decisions = enrich_decisions
79+
end
80+
81+
def with_visitors(visitors)
82+
@visitors = visitors
83+
end
84+
end
85+
end
86+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class EventContext
20+
attr_reader :account_id, :project_id, :revision, :client_name,
21+
:client_version, :anonymize_ip
22+
def initialize(
23+
account_id,
24+
project_id,
25+
revision,
26+
client_name,
27+
client_version,
28+
anonymize_ip
29+
)
30+
@account_id = account_id
31+
@project_id = project_id
32+
@revision = revision
33+
@client_name = client_name
34+
@client_version = client_version
35+
@anonymize_ip = anonymize_ip
36+
end
37+
end
38+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
require_relative 'user_event'
19+
module Optimizely
20+
class ImpressionEvent < UserEvent
21+
attr_reader :event_context, :user_id, :experiment, :variation, :visitor_attributes,
22+
:bot_filtering
23+
24+
def initialize(
25+
event_context,
26+
user_id,
27+
experiment,
28+
variation,
29+
visitor_attributes,
30+
bot_filtering
31+
)
32+
@event_context = event_context
33+
@user_id = user_id
34+
@experiment = experiment
35+
@variation = variation
36+
@visitor_attributes = visitor_attributes
37+
@bot_filtering = bot_filtering
38+
end
39+
end
40+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class Snapshot
20+
attr_reader :decisions, :events
21+
22+
def initialize(events, decisions = nil)
23+
@decisions = decisions
24+
@events = events
25+
end
26+
27+
def as_json
28+
hash = {
29+
events: @events,
30+
decisions: @decisions
31+
}
32+
hash.delete_if { |_key, value| value.nil? }
33+
hash
34+
end
35+
end
36+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class SnapshotEvent
20+
attr_reader :entity_id, :uuid, :key, :timestamp, :revenue, :value, :tags
21+
22+
def initialize(
23+
entity_id: nil,
24+
uuid: nil,
25+
key: nil,
26+
timestamp: nil,
27+
revenue: nil,
28+
value: nil,
29+
tags: nil
30+
)
31+
@entity_id = entity_id
32+
@uuid = uuid
33+
@key = key
34+
@timestamp = timestamp
35+
@revenue = revenue
36+
@value = value
37+
@tags = tags
38+
end
39+
40+
def as_json
41+
hash = {
42+
entity_id: @entity_id,
43+
uuid: @uuid,
44+
key: @key,
45+
timestamp: @timestamp,
46+
revenue: @revenue,
47+
value: @value,
48+
tags: @tags
49+
}
50+
hash.delete_if { |_key, value| value.nil? }
51+
hash
52+
end
53+
end
54+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Copyright 2019, Optimizely and contributors
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
module Optimizely
19+
class UserEvent
20+
attr_reader :event_context, :uuid, :timestamp
21+
end
22+
end

0 commit comments

Comments
 (0)