Module: Wingify
- Defined in:
- lib/wingify.rb
Constant Summary collapse
- @@wingify_builder =
nil- @@instance =
nil
Class Method Summary collapse
- .get_uuid(user_id, account_id) ⇒ Object
- .init(options) ⇒ Object
- .instance ⇒ Object
- .set_instance(options) ⇒ Object
Class Method Details
.get_uuid(user_id, account_id) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/wingify.rb', line 115 def self.get_uuid(user_id, account_id) if !user_id.is_a?(String) || user_id.empty? || !account_id.is_a?(String) || account_id.empty? puts "User ID and account ID must be non-empty strings" return nil end UUIDUtil.get_uuid(user_id, account_id) end |
.init(options) ⇒ Object
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/wingify.rb', line 63 def self.init() begin unless .is_a?(Hash) brand = BrandUtil.get_brand_name([:is_via_vwo] || false) log_prefix = BrandUtil.get_log_prefix([:is_via_vwo] || false) puts "[ERROR]: #{log_prefix}: Please provide the options as a hash" return nil end brand = BrandUtil.get_brand_name([:is_via_vwo] || false) log_prefix = BrandUtil.get_log_prefix([:is_via_vwo] || false) unless [:sdk_key]&.is_a?(String) && ![:sdk_key].empty? puts "[ERROR]: #{log_prefix}: Please provide the sdkKey in the options and should be a of type string" end unless [:account_id] && ([:account_id].is_a?(Integer) || ([:account_id].is_a?(String) && ![:account_id].empty?)) puts "[ERROR]: #{log_prefix}: Please provide #{brand} account ID in the options and should be a of type string|number" end sdk_init_start_time = (Time.now.to_f * 1000).to_i new_instance = set_instance() sdk_init_end_time = (Time.now.to_f * 1000).to_i time_taken_for_init = sdk_init_end_time - sdk_init_start_time was_initialized_earlier = false begin if new_instance && new_instance.original_settings && new_instance.original_settings.is_a?(Hash) = new_instance.original_settings["sdkMetaInfo"] was_initialized_earlier = && .is_a?(Hash) ? ["wasInitializedEarlier"] : false end rescue StandardError => e was_initialized_earlier = false end if !was_initialized_earlier && SettingsService.instance.is_settings_valid send_sdk_init_event(SettingsService.instance.settings_fetch_time, time_taken_for_init.to_s) end usage_stats_account_id = new_instance&.original_settings&.dig("usageStatsAccountId") if usage_stats_account_id send_sdk_usage_stats_event(usage_stats_account_id) end new_instance rescue StandardError => e brand = BrandUtil.get_brand_name([:is_via_vwo] || false) rescue 'SDK' log_prefix = BrandUtil.get_log_prefix([:is_via_vwo] || false) rescue 'SDK' puts "[ERROR]: #{log_prefix}: Got error while initializing #{brand}: #{e.}" end end |
.instance ⇒ Object
59 60 61 |
# File 'lib/wingify.rb', line 59 def self.instance @@instance end |
.set_instance(options) ⇒ Object
28 29 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 |
# File 'lib/wingify.rb', line 28 def self.set_instance() # Set brand flag FIRST — before any service initializes BrandContext.set_is_via_vwo([:is_via_vwo] || false) = [:wingify_builder] || [:vwo_builder] @@wingify_builder = || WingifyBuilder.new() @@instance = @@wingify_builder .set_logger .set_settings_service .set_storage .set_network_manager .set_segmentation .init_polling .init_usage_stats .init_batch if [:settings] if SettingsSchema.new.is_settings_valid([:settings]) SettingsService.instance.is_settings_valid = true else LoggerService.log(LogLevelEnum::ERROR, "INVALID_SETTINGS_SCHEMA", { accountId: [:account_id], sdkKey: [:sdk_key], settings: [:settings], an: ApiEnum::INIT}, false) end return @@wingify_builder.build([:settings]) end settings = @@wingify_builder.get_settings @@instance = @@wingify_builder.build(settings) @@instance end |