Class: IbmAppconfigurationRubySdk::AppConfiguration
- Inherits:
-
Object
- Object
- IbmAppconfigurationRubySdk::AppConfiguration
- Includes:
- Singleton
- Defined in:
- lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb
Overview
AppConfiguration client class implementing singleton pattern
Constant Summary collapse
- REGION_US_SOUTH =
Region constants
"us-south"- REGION_EU_GB =
"eu-gb"- REGION_AU_SYD =
"au-syd"- REGION_US_EAST =
"us-east"- REGION_EU_DE =
"eu-de"- REGION_CA_TOR =
"ca-tor"- REGION_JP_TOK =
"jp-tok"- REGION_JP_OSA =
"jp-osa"
Class Method Summary collapse
-
.current_instance ⇒ AppConfiguration
Get the current instance without creating a new one.
-
.override_service_url(url) ⇒ Object
Override the default App Configuration URL This method should be invoked before the SDK initialization NOTE: To be used for development purposes only.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Check if the SDK is connected to the service.
-
#get_feature(feature_id) ⇒ Feature?
Returns the Feature object with the details of the feature specified by the feature_id.
-
#get_features ⇒ Hash?
Returns all features associated with the collection_id.
-
#get_properties ⇒ Hash?
Returns all properties associated with the collection_id.
-
#get_property(property_id) ⇒ Property?
Returns the Property object with the details of the property specified by the property_id.
-
#get_secret(property_id, secrets_manager_service) ⇒ SecretProperty?
Returns the SecretProperty object corresponding to the given property_id.
-
#init(region, guid, apikey) ⇒ Object
Initialize the SDK to connect with your App Configuration service instance.
-
#initialize ⇒ AppConfiguration
constructor
A new instance of AppConfiguration.
-
#register_configuration_update_listener(&block) ⇒ void
Register a configuration update listener The listener will be invoked whenever configurations are updated (initial load or live updates).
-
#set_context(collection_id, environment_id, options = {}) ⇒ Object
Set the context of the SDK.
-
#set_debug(value = false) ⇒ Object
Enable or disable the logger By default, logger is disabled.
-
#track(event_key, entity_id) ⇒ Object
Record custom metric events for an entity_id while running an experiment.
-
#use_private_endpoint(use_private_endpoint_param) ⇒ Object
Set the SDK to connect to App Configuration service using a private endpoint This function must be called before calling the init function.
Constructor Details
#initialize ⇒ AppConfiguration
Returns a new instance of AppConfiguration.
62 63 64 65 66 67 68 69 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 62 def initialize @is_initialized = false @is_initialized_config = false @use_private_endpoint = false @configuration_handler = nil @logger = Logger.instance @url_builder = UrlBuilder.instance end |
Class Method Details
.current_instance ⇒ AppConfiguration
Get the current instance without creating a new one
43 44 45 46 47 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 43 def current_instance raise Constants::SINGLETON_EXCEPTION unless @singleton__instance__ instance end |
.override_service_url(url) ⇒ Object
Override the default App Configuration URL This method should be invoked before the SDK initialization NOTE: To be used for development purposes only
54 55 56 57 58 59 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 54 def override_service_url(url) return unless url url_builder = UrlBuilder.instance url_builder.set_base_service_url(url) end |
Instance Method Details
#connected? ⇒ Boolean
Check if the SDK is connected to the service
253 254 255 256 257 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 253 def connected? return @configuration_handler.connected? if @is_initialized && @is_initialized_config false end |
#get_feature(feature_id) ⇒ Feature?
Returns the Feature object with the details of the feature specified by the feature_id
177 178 179 180 181 182 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 177 def get_feature(feature_id) return @configuration_handler.get_feature(feature_id) if @is_initialized && @is_initialized_config @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#get_features ⇒ Hash?
Returns all features associated with the collection_id
187 188 189 190 191 192 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 187 def get_features return @configuration_handler.get_features if @is_initialized && @is_initialized_config @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#get_properties ⇒ Hash?
Returns all properties associated with the collection_id
208 209 210 211 212 213 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 208 def get_properties return @configuration_handler.get_properties if @is_initialized && @is_initialized_config @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#get_property(property_id) ⇒ Property?
Returns the Property object with the details of the property specified by the property_id
198 199 200 201 202 203 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 198 def get_property(property_id) return @configuration_handler.get_property(property_id) if @is_initialized && @is_initialized_config @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#get_secret(property_id, secrets_manager_service) ⇒ SecretProperty?
Returns the SecretProperty object corresponding to the given property_id
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 220 def get_secret(property_id, secrets_manager_service) if @is_initialized && @is_initialized_config return @configuration_handler.get_secret(property_id, secrets_manager_service) if secrets_manager_service @logger.error(Constants::INVALID_SECRET_MANAGER_CLIENT_MESSAGE) return nil end @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#init(region, guid, apikey) ⇒ Object
Initialize the SDK to connect with your App Configuration service instance
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 77 def init(region, guid, apikey) # init is a SDK initialization method. It is expected to be called only once. # This condition ensures the init inputs are taken only once even if called multiple times. return if @is_initialized unless region && guid && apikey if !region report_error(Constants::REGION_ERROR) elsif !guid report_error(Constants::GUID_ERROR) else report_error(Constants::APIKEY_ERROR) end end @configuration_handler = ConfigurationHandler.instance @configuration_handler.init(region, guid, apikey, @use_private_endpoint) @is_initialized = true end |
#register_configuration_update_listener(&block) ⇒ void
This method returns an undefined value.
Register a configuration update listener The listener will be invoked whenever configurations are updated (initial load or live updates). Only one listener can be registered at a time - calling this method multiple times will replace the previous listener.
272 273 274 275 276 277 278 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 272 def register_configuration_update_listener(&block) if @is_initialized && @is_initialized_config @configuration_handler.register_configuration_update_listener(&block) return end @logger.error(Constants::COLLECTION_INIT_ERROR) end |
#set_context(collection_id, environment_id, options = {}) ⇒ Object
Set the context of the SDK
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 106 def set_context(collection_id, environment_id, = {}) # setContext is also a SDK initialization method. It is expected to be called only once. # This condition ensures the setContext inputs are taken only once even if called multiple times. return if @is_initialized_config report_error(Constants::COLLECTION_ID_ERROR) unless @is_initialized report_error(Constants::COLLECTION_ID_VALUE_ERROR) unless collection_id report_error(Constants::ENVIRONMENT_ID_VALUE_ERROR) unless environment_id = { persistent_cache_directory: nil, bootstrap_file: nil, live_config_update_enabled: true } if report_error(Constants::INVALID_OPTIONS_PARAMETER.to_s) unless .is_a?(Hash) if .key?(:persistent_cache_directory) given_dir_path = [:persistent_cache_directory] if given_dir_path.is_a?(String) && !given_dir_path.empty? [:persistent_cache_directory] = given_dir_path else report_error("#{Constants::PERSISTENT_CACHE_OPTION_ERROR} #{given_dir_path}") end end if .key?(:bootstrap_file) given_file_path = [:bootstrap_file] if given_file_path.is_a?(String) && !given_file_path.empty? && File.extname(given_file_path) == ".json" [:bootstrap_file] = given_file_path else report_error("#{Constants::BOOTSTRAP_FILEPATH_OPTION_ERROR} #{given_file_path}") end end if .key?(:live_config_update_enabled) given_flag_value = [:live_config_update_enabled] if [true, false].include?(given_flag_value) [:live_config_update_enabled] = given_flag_value else report_error("#{Constants::LIVE_CONFIG_UPDATE_OPTION_ERROR} #{given_flag_value}") end end report_error(Constants::CONFIGURATION_FILE_NOT_FOUND_ERROR) if [:live_config_update_enabled] == false && [:bootstrap_file].nil? end @is_initialized_config = true @configuration_handler = ConfigurationHandler.instance @configuration_handler.set_context(collection_id, environment_id, ) end |
#set_debug(value = false) ⇒ Object
Enable or disable the logger By default, logger is disabled
246 247 248 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 246 def set_debug(value = false) Logger.set_debug(value) end |
#track(event_key, entity_id) ⇒ Object
Record custom metric events for an entity_id while running an experiment
235 236 237 238 239 240 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 235 def track(event_key, entity_id) return @configuration_handler.track(event_key, entity_id) if @is_initialized && @is_initialized_config @logger.error(Constants::COLLECTION_INIT_ERROR) nil end |
#use_private_endpoint(use_private_endpoint_param) ⇒ Object
Set the SDK to connect to App Configuration service using a private endpoint This function must be called before calling the init function
165 166 167 168 169 170 171 |
# File 'lib/ibm_appconfiguration_ruby_sdk/app_configuration.rb', line 165 def use_private_endpoint(use_private_endpoint_param) if [true, false].include?(use_private_endpoint_param) @use_private_endpoint = use_private_endpoint_param return end @logger.error(Constants::INPUT_PARAMETER_NOT_BOOLEAN) end |