Class: VWO::EventDispatcher

Inherits:
Object
  • Object
show all
Includes:
Common::Enums
Defined in:
lib/vwo/event_dispatcher.rb

Constant Summary collapse

EXCLUDE_KEYS =
['url'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(is_development_mode = false) ⇒ EventDispatcher

Initialize the dispatcher with logger

Parameters:

  • : (Boolean)

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



19
20
21
22
# File 'lib/vwo/event_dispatcher.rb', line 19

def initialize(is_development_mode = false)
  @logger = CustomLogger.get_instance
  @is_development_mode = is_development_mode
end

Instance Method Details

#dispatch(properties) ⇒ Object

Dispatch the event being represented in the properties object.

@param :properties Object holding information about

the request to be dispatched to the VWO backend.

@return



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vwo/event_dispatcher.rb', line 30

def dispatch(properties)
  return true if @is_development_mode

  modified_properties = properties.reject do |key, _value|
    EXCLUDE_KEYS.include?(key)
  end

  resp = VWO::Common::Requests.get(properties['url'], modified_properties)
  if resp.code == '200'
    @logger.log(
      LogLevelEnum::INFO,
      format(
        LogMessageEnum::InfoMessages::IMPRESSION_SUCCESS,
        file: FileNameEnum::EventDispatcher,
        end_point: properties[:url],
        campaign_id: properties[:experiment_id],
        user_id: properties[:uId],
        account_id: properties[:account_id],
        variation_id: properties[:combination]
      )
    )
    return true
  else
    @logger.log(
      LogLevelEnum::ERROR,
      format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum.EventDispatcher, end_point: properties['url'])
    )
    return false
  end
rescue StandardError
  @logger.log(
    LogLevelEnum::ERROR,
    format(LogMessageEnum::ErrorMessages::IMPRESSION_FAILED, file: FileNameEnum::EventDispatcher, end_point: properties['url'])
  )
  false
end