|
| 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 |
0 commit comments