10000 feat(epmodel): Event Processor datamodel by msohailhussain · Pull Request #184 · optimizely/ruby-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat(epmodel): Event Processor datamodel #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Metrics/ParameterLists:
- 'lib/optimizely/config_manager/http_project_config_manager.rb'
- 'lib/optimizely.rb'
- 'lib/optimizely/optimizely_factory.rb'
- 'lib/optimizely/event/entity/snapshot_event.rb'

Naming/AccessorMethodName:
Exclude:
Expand Down
39 changes: 39 additions & 0 deletions lib/optimizely/event/entity/conversion_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require_relative 'user_event'
module Optimizely
class ConversionEvent < UserEvent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are other attributes?
bot filter?

attr_reader :event_context, :event, :user_id, :visitor_attributes, :tags, :bot_filtering

def initialize(
event_context,
event,
user_id,
visitor_attributes,
tags,
bot_filtering = nil
)
@event_context = event_context
@event = event
@user_id = user_id
@visitor_attributes = visitor_attributes
@tags = tags
@bot_filtering = bot_filtering
end
end
end
36 changes: 36 additions & 0 deletions lib/optimizely/event/entity/decision.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class Decision
attr_reader :campaign_id, :experiment_id, :variation_id

def initialize(campaign_id, experiment_id, variation_id)
@campaign_id = campaign_id
@experiment_id = experiment_id
@variation_id = variation_id
end

def as_json
{
campaign_id: @campaign_id,
experiment_id: @experiment_id,
variation_id: @variation_id
}
end
end
end
86 changes: 86 additions & 0 deletions lib/optimizely/event/entity/event_batch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class EventBatch
attr_accessor :account_id, :project_id, :revision, :client_name, :client_version,
:anonymize_ip, :enrich_decisions, :visitors

def as_json
{
account_id: @account_id,
project_id: @project_id,
revision: @revision,
client_name: @client_name,
client_version: @client_version,
anonymize_ip: @anonymize_ip,
enrich_decisions: @enrich_decisions,
visitors: @visitors
}
end

class Builder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need builder classes in ruby ?

attr_reader :account_id, :project_id, :revision, :client_name, :client_version,
:anonymize_ip, :enrich_decisions, :visitors

def build
event_batch = EventBatch.new
event_batch.account_id = @account_id
event_batch.project_id = @project_id
event_batch.revision = @revision
event_batch.client_name = @client_name
event_batch.client_version = @client_version
event_batch.anonymize_ip = @anonymize_ip
event_batch.enrich_decisions = @enrich_decisions
event_batch.visitors = @visitors
event_batch
end

def with_account_id(account_id)
@account_id = account_id
end

def with_project_id(project_id)
@project_id = project_id
end

def with_revision(revision)
@revision = revision
end

def with_client_name(client_name)
@client_name = client_name
end

def with_client_version(client_version)
@client_version = client_version
end

def with_anonymize_ip(anonymize_ip)
@anonymize_ip = anonymize_ip
end

def with_enrich_decisions(enrich_decisions)
@enrich_decisions = enrich_decisions
end

def with_visitors(visitors)
@visitors = visitors
end
end
end
end
38 changes: 38 additions & 0 deletions lib/optimizely/event/entity/event_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class EventContext
attr_reader :account_id, :project_id, :revision, :client_name,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how you will set these values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialized

:client_version, :anonymize_ip
def initialize(
account_id,
project_id,
revision,
client_name,
client_version,
anonymize_ip
)
@account_id = account_id
@project_id = project_id
@revision = revision
@client_name = client_name
@client_version = client_version
@anonymize_ip = anonymize_ip
end
end
end
40 changes: 40 additions & 0 deletions lib/optimizely/event/entity/impression_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require_relative 'user_event'
module Optimizely
class ImpressionEvent < UserEvent
attr_reader :event_context, :user_id, :experiment, :variation, :visitor_attributes,
:bot_filtering

def initialize(
event_context,
user_id,
experiment,
variation,
visitor_attributes,
bot_filtering
)
@event_context = event_context
@user_id = user_id
@experiment = experiment
@variation = variation
@visitor_attributes = visitor_attributes
@bot_filtering = bot_filtering
end
end
end
36 changes: 36 additions & 0 deletions lib/optimizely/event/entity/snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class Snapshot
attr_reader :decisions, :events

def initialize(events, decisions = nil)
@decisions = decisions
@events = events
end

def as_json
hash = {
events: @events,
decisions: @decisions
}
hash.delete_if { |_key, value| value.nil? }
hash
end
end
end
54 changes: 54 additions & 0 deletions lib/optimizely/event/entity/snapshot_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class SnapshotEvent
attr_reader :entity_id, :uuid, :key, :timestamp, :revenue, :value, :tags

def initialize(
entity_id: nil,
uuid: nil,
key: nil,
timestamp: nil,
revenue: nil,
value: nil,
tags: nil
)
@entity_id = entity_id
@uuid = uuid
@key = key
@timestamp = timestamp
@revenue = revenue
@value = value
@tags = tags
end

def as_json
hash = {
entity_id: @entity_id,
uuid: @uuid,
key: @key,
timestamp: @timestamp,
revenue: @revenue,
value: @value,
tags: @tags
}
hash.delete_if { |_key, value| value.nil? }
hash
end
end
end
22 changes: 22 additions & 0 deletions lib/optimizely/event/entity/user_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

#
# Copyright 2019, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Optimizely
class UserEvent
attr_reader :event_context, :uuid, :timestamp
end
end
Loading
0