Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions lib/optimizely/event/entity/conversion_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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_accessor :event, :event_tags
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't we just define attr_reader and pass it in a constructor?

attr_reader :user_id, :user_attributes
end
end
37 changes: 37 additions & 0 deletions lib/optimizely/event/entity/decision.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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(_options = {})
{
campaign_id: @campaign_id,
experiment_id: @experiment_id,
variation_id: @variation_id
}
end
end
end
88 changes: 88 additions & 0 deletions lib/optimizely/event/entity/event_batch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# 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 'json'
module Optimizely
class EventBatch
attr_accessor :account_id, :project_id, :revision, :client_name, :client_version,
:anonymize_ip, :enrich_decisions, :visitors

def as_json(_options = {})
{
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
35 changes: 35 additions & 0 deletions lib/optimizely/event/entity/event_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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
end

def as_json(_options = {})
{
account_id: @account_id,
project_id: @project_id,
revision: @revision,
client_name: @client_name,
client_version: @client_version,
anonymize_ip: @anonymize_ip
}
end
end
24 changes: 24 additions & 0 deletions lib/optimizely/event/entity/impression_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 :user_id, :user_attributes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not user_attributes, it's visitor_attributes

attr_accessor :experiment, :variation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why accessor?

Copy link
Contributor

Choose a reason for hiding this comment

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

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(_options = {})
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, :event_tags

def initialize(
entity_id: nil,
uuid: nil,
key: nil,
timestamp: nil,
revenue: nil,
value: nil,
event_tags: nil
)
@entity_id = entity_id
@uuid = uuid
@key = key
@timestamp = timestamp
@revenue = revenue
@value = value
@event_tags = event_tags
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are just tags?

end

def as_json(_options = {})
hash = {
entity_id: @entity_id,
uuid: @uuid,
key: @key,
timestamp: @timestamp,
revenue: @revenue,
value: @value,
event_tags: @event_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 :context, :uuid, :timestamp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

write it as event_context

end
end
35 changes: 35 additions & 0 deletions lib/optimizely/event/entity/visitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 Visitor
attr_reader :snapshots, :attributes, :visitor_id
def initialize(snapshots, attributes, visitor_id)
@snapshots = snapshots
@attributes = attributes
@visitor_id = visitor_id
end

def as_json(_options = {})
{
snapshots: @snapshots,
attributes: @attributes,
visitor_id: @visitor_id
}
end
end
end
Loading