云眼配置
云眼配置
本主题介绍如何使用云眼灰度发布(特性标帜)AB实验 Ruby SDK 的 EyeofcloudConfig 访问数据文件中的项目配置数据。
概述
云眼灰度发布(特性标帜)AB实验 SDK 打开一组定义良好的公共 API,隐藏所有实现详细信息。但是,某些客户端可能需要访问数据文件中的项目配置数据。
在本文档中,我们扩展了公共 API 以定义数据模型和访问方法,客户端可以使用这些模型和方法访问项目配置数据。
EyeofcloudConfig API
公共配置数据模型(EyeofcloudConfig)在下面定义为静态Eyeofcloud项目数据的结构化格式。
获取云眼配置
EyeofcloudConfig可以通过以下公共API调用从EyeofcloudClient(顶级)访问:
Rubby
def get_eyeofcloud_config
getEyeofcloudConfig
返回一个实例,其中包括EyeofcloudConfig
- 环境键
- 开发工具包密钥
- 数据文件修订号
- 按其键值映射的所有实验
- 所有属性
- 所有受众
- 所有活动
- 按其键值映射的灰度发布(特性标帜)
- 检索项目配置(数据文件)的函数
📘 注意
当 SDK 数据文件更新时(客户端可以添加通知侦听器以获取通知),客户端应调用该方法以获取更新的 EyeofcloudConfig 数据。请参阅以下示例。
EYEOFCLOUD_CONFIG_UPDATE
获取数据文件
要在多个 SDK 实例之间共享同一数据文件(例如,在客户端/服务器方案中),可以在实例之间传递配置(数据文件)的 JSON 字符串表示形式。若要获取数据文件,请使用对象的方法。有关更多信息,请参阅与多个 SDK 实现共享数据文件。EyeofcloudConfig``getDatafile
对象模型
下面显示了 EyeofcloudConfig 的对象模型。
Ruby - 对象模型
# [EyeofcloudConfig] is a hash describing the current project configuration data # being used by this SDK instance. The hash consists of: revision - string sdkKey - string environmentKey - string # This experimentsMap is for experiments of legacy projects only. # For flag projects, experiment keys are not guaranteed to be unique # across multiple flags, so this map may not include all experiments # when keys conflict. experimentsMap - hash of experiment key to EyeofcloudExperiment featuresMap - hash of feature flag key to EyeofcloudFeature attributes - list of attributes audiences - list of all audiences events - list of events # [EyeofcloudFeature] is a hash describing a feature flag. The hash consists of: id - string key - string experimentRules - list of eyeofcloud feature experiments deliveryRules - list of eyeofcloud rollout experiments # Deprecated. Use experimentRules and deliveryRules instead. experimentsMap - hash of experiment key to EyeofcloudExperiment variablesMap - hash of variable key to EyeofcloudVariable # [EyeofcloudExperiment] is a hash describing an experiment. The hash consists of: id - string key - string audiences - list of serialized audiences variationMap - hash of variation key to EyeofcloudVariation # [EyeofcloudVariation] is a hash describing a variation in an experiment. The hash consists of: id - string key - string featureEnabled - bool variablesMap - hash of variable key to EyeofcloudVariable # [EyeofcloudVariable] is a hash describing a feature flag variable. The hash consists of: id - string key - string type - string value - string # [EyeofcloudAttribute] is a hash describing an attribute. The hash consists of: id - string key - string # [EyeofcloudAudience] is a hash describing an audience. The hash consists of: id - string name - string conditions - string # [EyeofcloudEvent] is a hash describing an event. The hash consists of: id - string key - string experimentIds - list of experiemnt ids
例子
EyeofcloudConfig可以从EyeofcloudClient(顶级)访问,如下所示:
Rubby
config = eyeofcloud_instance.get_eyeofcloud_config revision = config['revision'] sdk_key = config['sdkKey'] evironnment_key = config['environmentKey'] #all audiences audiences = config['audiences'] #all attributes attributes = config['attributes'] #all events events = config['events'] # all feature flags features_map = config['featuresMap'] features = features_map.values feature_keys = features_map.keys feature_keys.each do |flag_key| flag = features_map[flag_key] delivery_rules = flag['deliveryRules'] experiment_rules = flag['experimentRules'] # use experiment rules and delivery rules and other flag data here... experiment_rules.each do |experiment| experiment_key = experiment['key'] audiences = experiment['audiences'] variations_map = experiment['variationsMap'] variations_keys = variations_map.keys variations_keys.each do |variation_key| variation = variations_map[variation_key] variables_map = variation['variablesMap'] variables_map.each do |variable_key| variable = variables_map[variable_key] end end end delivery_rules.each do |delivery| delivery_key = delivery['key'] audiences = delivery['audiences'] # use delivery rule data here... end end # listen to EYEOFCLOUD_CONFIG_UPDATE to get updated data eyeofcloud_instance.notification_center.add_notification_listener( Eyeofcloud::NotificationCenter::NOTIFICATION_TYPES[:EYEOFCLOUD_CONFIG_UPDATE] ) do |*args| config = eyeofcloud_instance.get_eyeofcloud_config end