diff --git a/CHANGELOG.md b/CHANGELOG.md index 27ca9ee..59fff05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.3.0] - 2024-11-22 + +### Added + +- added new method `update_settings` to update settings on the vwo client instance. + ## [1.2.0] - 2024-09-25 ### Added diff --git a/setup.py b/setup.py index a11032a..d49fd4f 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,7 @@ def run(self): setup( name="vwo-fme-python-sdk", - version="1.2.0", + version="1.3.0", description="VWO Feature Management and Experimentation SDK for Python", long_description=long_description, long_description_content_type="text/markdown", diff --git a/vwo/constants/Constants.py b/vwo/constants/Constants.py index 0e8b712..15ae481 100644 --- a/vwo/constants/Constants.py +++ b/vwo/constants/Constants.py @@ -17,7 +17,7 @@ class Constants: # Mock package_file equivalent package_file = { "name": "vwo-fme-python-sdk", # Replace with actual package name - "version": "1.2.0", # Replace with actual package version + "version": "1.3.0", # Replace with actual package version } # Constants @@ -47,6 +47,7 @@ class Constants: HOST_NAME = "dev.visualwebsiteoptimizer.com" # TODO: change as needed SETTINGS_ENDPOINT = "/server-side/v2-settings" + WEBHOOK_SETTINTS_ENDPOINT = "/server-side/v2-pull" LOCATION_ENDPOINT = "/getLocation" VWO_FS_ENVIRONMENT = "vwo_fs_environment" diff --git a/vwo/services/settings_manager.py b/vwo/services/settings_manager.py index cc5c813..aee9057 100644 --- a/vwo/services/settings_manager.py +++ b/vwo/services/settings_manager.py @@ -88,7 +88,7 @@ def fetch_settings_and_cache_in_storage(self, update=False): ) return None - def fetch_settings(self): + def fetch_settings(self, is_via_webhook=False): if not self.sdk_key or not self.account_id: raise ValueError( "sdk_key is required for fetching account settings. Aborting!" @@ -101,11 +101,17 @@ def fetch_settings(self): if not network_instance.get_config().get_development_mode(): options["s"] = "prod" + endpoint = ( + Constants.SETTINGS_ENDPOINT + if not is_via_webhook + else Constants.WEBHOOK_SETTINTS_ENDPOINT + ) + try: request = RequestModel( self.hostname, "GET", - Constants.SETTINGS_ENDPOINT, + endpoint, options, None, None, diff --git a/vwo/vwo_client.py b/vwo/vwo_client.py index d5da415..c6a94de 100644 --- a/vwo/vwo_client.py +++ b/vwo/vwo_client.py @@ -284,3 +284,49 @@ def set_attribute(self, attribute_key: str, attribute_value: Any, context: Dict) ) ) return + + def update_settings(self, settings: Dict = None, is_via_webhook=True): + """ + Updates the settings for the client. + :param settings: The settings to update. + :param is_via_webhook: Whether the settings are being updated via webhook. + """ + + api_name = "update_settings" + + try: + LogManager.get_instance().debug( + debug_messages.get("API_CALLED").format(apiName=api_name) + ) + + # check if settings are None or empty + settings_to_update = settings + if settings_to_update is None or settings_to_update == {}: + # fetch the latest settings + settings_to_update = SettingsManager.get_instance().fetch_settings( + is_via_webhook + ) + + # validate the settings + if not SettingsManager.is_settings_valid(settings_to_update): + LogManager.get_instance().error( + error_messages.get("API_SETTING_INVALID") + ) + raise ValueError("TypeError: Invalid Settings schema") + + # update the settings + set_settings_and_add_campaigns_to_rules(settings_to_update, self) + LogManager.get_instance().info( + info_messages.get("SETTINGS_UPDATED").format( + apiName=api_name, isViaWebhook=is_via_webhook + ) + ) + return + + except Exception as err: + LogManager.get_instance().error( + error_messages.get("SETTINGS_FETCH_FAILED").format( + apiName=api_name, isViaWebhook=is_via_webhook, err=str(err) + ) + ) + return