Class: VWO::Services::EventDispatcher

Inherits:
Object
  • Object
show all
Includes:
CONSTANTS, Enums, Utils::Utility
Defined in:
lib/vwo/services/event_dispatcher.rb

Constant Summary collapse

EXCLUDE_KEYS =
['url'].freeze

Constants included from CONSTANTS

CONSTANTS::API_VERSION, CONSTANTS::DEFAULT_EVENTS_PER_REQUEST, CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL, CONSTANTS::GOAL_TYPES, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_EVENTS_PER_REQUEST, CONSTANTS::MAX_RANGE, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::MIN_EVENTS_PER_REQUEST, CONSTANTS::MIN_REQUEST_TIME_INTERVAL, CONSTANTS::PLATFORM, CONSTANTS::RUBY_VARIABLE_TYPES, CONSTANTS::SDK_NAME, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE, CONSTANTS::VWO_DELIMITER

Instance Method Summary collapse

Methods included from Utils::Utility

#convert_to_symbol_hash, #get_url, #get_variation_identifiers, #prepare_push_response, #remove_sensitive_properties

Methods included from Utils

#valid_campaign_for_track_api?, #valid_track_api_params?

Methods included from Utils::Validations

#invalid_config_log, #valid_basic_data_type?, #valid_batch_event_settings, #valid_boolean?, #valid_config_log, #valid_goal?, #valid_hash?, #valid_number?, #valid_settings_file?, #valid_string?, #valid_value?, #validate_sdk_config?

Constructor Details

#initialize(is_development_mode = false) ⇒ EventDispatcher

Initialize the dispatcher with logger and development mode

Parameters:

  • : (Boolean)

    To specify whether the request to our server should be made or not.



35
36
37
38
# File 'lib/vwo/services/event_dispatcher.rb', line 35

def initialize(is_development_mode = false)
  @logger = VWO::Utils::Logger
  @is_development_mode = is_development_mode
end

Instance Method Details

#dispatch(impression, main_keys, end_point) ⇒ Object

Dispatch the impression event having properties object only if dev-mode is OFF

@param :properties hash having impression properties

the request to be dispatched to the VWO server

@return



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vwo/services/event_dispatcher.rb', line 46

def dispatch(impression, main_keys, end_point)
  return true if @is_development_mode

  modified_event = impression.reject do |key, _value|
    EXCLUDE_KEYS.include?(key)
  end

  resp = VWO::Utils::Request.get(impression['url'], modified_event)
  if resp.code == '200'
    @logger.log(
      LogLevelEnum::INFO,
      'IMPRESSION_SUCCESS',
      {
        '{file}' => FILE,
        '{endPoint}' => end_point,
        '{accountId}' => impression['account_id'] || impression[:account_id],
        '{mainKeys}' => JSON.generate(main_keys)
      }
    )
    true
  else
    @logger.log(
      LogLevelEnum::ERROR,
      'IMPRESSION_FAILED',
      {
        '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
        '{err}' => resp.message,
        '{endPoint}' => impression['url']
      }
    )
    false
  end
rescue StandardError => e
  @logger.log(
    LogLevelEnum::ERROR,
    'IMPRESSION_FAILED',
    {
      '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
      '{err}' => e.message,
      '{endPoint}' => impression['url']
    }
  )
  false
end

#dispatch_event_arch_post(params, post_data, options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vwo/services/event_dispatcher.rb', line 91

def dispatch_event_arch_post(params, post_data, options = {})
  return true if @is_development_mode

  url = HTTPS_PROTOCOL + get_url(ENDPOINTS::EVENTS)
  resp = VWO::Utils::Request.event_post(url, params, post_data, SDK_NAME, options)
  if resp.code == '200'
    @logger.log(
      LogLevelEnum::INFO,
      'IMPRESSION_SUCCESS_FOR_EVENT_ARCH',
      {
        '{file}' => FileNameEnum::BATCH_EVENTS_DISPATCHER,
        '{event}' => "visitor property:#{JSON.generate(post_data[:d][:visitor][:props])}",
        '{endPoint}' => url,
        '{accountId}' => params[:a]
      }
    )
    true
  else
    @logger.log(
      LogLevelEnum::ERROR,
      'IMPRESSION_FAILED',
      {
        '{file}' => FileNameEnum::EVENT_DISPATCHER,
        '{err}' => resp.message,
        '{endPoint}' => url
      }
    )
    false
  end
rescue StandardError => e
  @logger.log(
    LogLevelEnum::ERROR,
    'IMPRESSION_FAILED',
    {
      '{file}' => FileNameEnum::EVENT_DISPATCHER,
      '{err}' => e.message,
      '{endPoint}' => url
    }
  )
  false
end