class Optimizely::OptimizelyFactory
Public Class Methods
Convenience method for setting timeout to block the config call until config has been initialized.
@param blocking_timeout
Numeric - Time in seconds.
# File lib/optimizely/optimizely_factory.rb, line 82 def self.blocking_timeout(blocking_timeout) @blocking_timeout = blocking_timeout end
Returns a new optimizely instance.
@params sdk_key - Required String uniquely identifying the datafile corresponding to project. @param fallback datafile - Optional JSON string datafile. @param event_dispatcher - Optional EventDispatcherInterface Provides a dispatch_event method which if given a URL and params sends a request to it. @param logger - Optional LoggerInterface Provides a log method to log messages. By default nothing would be logged. @param error_handler - Optional ErrorHandlerInterface which provides a handle_error method to handle exceptions.
By default all exceptions will be suppressed.
@param skip_json_validation - Optional Boolean param to skip JSON schema validation of the provided datafile. @param user_profile_service - Optional UserProfileServiceInterface Provides methods to store and retreive user profiles. @param config_manager - Optional ConfigManagerInterface Responds to 'config' method. @param notification_center - Optional Instance of NotificationCenter
.
if @max_event_batch_size and @max_event_flush_interval are nil then default batchsize and flush_interval will be used to setup batchEventProcessor.
# File lib/optimizely/optimizely_factory.rb, line 132 def self.custom_instance( sdk_key, datafile = nil, event_dispatcher = nil, logger = nil, error_handler = nil, skip_json_validation = false, user_profile_service = nil, config_manager = nil, notification_center = nil ) error_handler ||= NoOpErrorHandler.new logger ||= NoOpLogger.new notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(logger, error_handler) event_processor = BatchEventProcessor.new( event_dispatcher: event_dispatcher || EventDispatcher.new, batch_size: @max_event_batch_size, flush_interval: @max_event_flush_interval, logger: logger, notification_center: notification_center ) config_manager ||= Optimizely::HTTPProjectConfigManager.new( sdk_key: sdk_key, polling_interval: @polling_interval, blocking_timeout: @blocking_timeout, datafile: datafile, logger: logger, error_handler: error_handler, skip_json_validation: skip_json_validation, notification_center: notification_center ) Optimizely::Project.new( datafile, event_dispatcher, logger, error_handler, skip_json_validation, user_profile_service, sdk_key, config_manager, notification_center, event_processor ) end
Returns a new optimizely instance.
@params sdk_key - Required String uniquely identifying the fallback datafile corresponding to project. @param fallback datafile - Optional JSON string datafile.
# File lib/optimizely/optimizely_factory.rb, line 90 def self.default_instance(sdk_key, datafile = nil) error_handler = NoOpErrorHandler.new logger = NoOpLogger.new notification_center = NotificationCenter.new(logger, error_handler) config_manager = Optimizely::HTTPProjectConfigManager.new( sdk_key: sdk_key, polling_interval: @polling_interval, blocking_timeout: @blocking_timeout, datafile: datafile, logger: logger, error_handler: error_handler, notification_center: notification_center ) Optimizely::Project.new( datafile, nil, logger, error_handler, nil, nil, sdk_key, config_manager, notification_center ) end
Returns a new optimizely instance.
@param config_manager - Required ConfigManagerInterface Responds to 'config' method.
# File lib/optimizely/optimizely_factory.rb, line 113 def self.default_instance_with_config_manager(config_manager) Optimizely::Project.new(nil, nil, nil, nil, nil, nil, nil, config_manager) end
Convenience method for setting the maximum number of events contained within a batch. @param batch_size Integer - Sets size of EventQueue. @param logger - Optional LoggerInterface Provides a log method to log messages.
# File lib/optimizely/optimizely_factory.rb, line 31 def self.max_event_batch_size(batch_size, logger = NoOpLogger.new) unless batch_size.is_a? Integer logger.log( Logger::ERROR, "Batch size is invalid, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}." ) return end unless batch_size.positive? logger.log( Logger::ERROR, "Batch size is negative, setting to default batch size #{BatchEventProcessor::DEFAULT_BATCH_SIZE}." ) return end @max_event_batch_size = batch_size end
Convenience method for setting the maximum time interval in milliseconds between event dispatches. @param flush_interval Numeric - Time interval between event dispatches. @param logger - Optional LoggerInterface Provides a log method to log messages.
# File lib/optimizely/optimizely_factory.rb, line 53 def self.max_event_flush_interval(flush_interval, logger = NoOpLogger.new) unless flush_interval.is_a? Numeric logger.log( Logger::ERROR, "Flush interval is invalid, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}." ) return end unless flush_interval.positive? logger.log( Logger::ERROR, "Flush interval is negative, setting to default flush interval #{BatchEventProcessor::DEFAULT_BATCH_INTERVAL}." ) return end @max_event_flush_interval = flush_interval end
Convenience method for setting frequency at which datafile has to be polled and ProjectConfig
updated.
@param polling_interval
Numeric - Time in seconds after which to update datafile.
# File lib/optimizely/optimizely_factory.rb, line 75 def self.polling_interval(polling_interval) @polling_interval = polling_interval end