Skip to content

Commit

Permalink
Support for Webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhi591 authored and rohitesh-wingify committed Nov 22, 2024
1 parent 2536040 commit e5b1b55
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion vwo/constants/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions vwo/services/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand All @@ -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,
Expand Down
46 changes: 46 additions & 0 deletions vwo/vwo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e5b1b55

Please sign in to comment.