Skip to content

Commit 080531d

Browse files
oakbaniMichael Ng
authored andcommitted
docs: update readme for dfm (#180)
1 parent af1a544 commit 080531d

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,111 @@ gem install optimizely-sdk
2323
To access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely account executive.
2424

2525
### Using the SDK
26+
27+
You can initialize the Optimizely instance in two ways: directly with a datafile, or by using a factory class, `OptimizelyFactory`, which provides methods to create an Optimizely instance with the default configuration.
28+
29+
#### Initialization with datafile
30+
31+
Initialize Optimizely with a datafile. This datafile will be used as ProjectConfig throughout the life of the Optimizely instance.
32+
33+
```
34+
optimizely_instance = Optimizely::Project.new(datafile)
35+
```
36+
37+
#### Initialization by OptimizelyFactory
38+
39+
1. Initialize Optimizely by providing an `sdk_key` and an optional `datafile`. This will initialize an HTTPConfigManager that makes an HTTP GET request to the URL (formed using your provided `sdk_key` and the default datafile CDN url template) to asynchronously download the project datafile at regular intervals and update ProjectConfig when a new datafile is recieved.
40+
41+
```
42+
optimizely_instance = Optimizely::OptimizelyFactory.default_instance('put_your_sdk_key_here', datafile)
43+
```
44+
45+
When the `datafile` is given then it will be used initially before any update.
46+
47+
2. Initialize Optimizely by providing a Config Manager that implements a 'get_config' method. You can customize our `HTTPConfigManager` as needed.
48+
49+
```
50+
custom_config_manager = CustomConfigManager.new
51+
optimizely_instance = Optimizely::OptimizelyFactory.default_instance_with_config_manager(custom_config_manager)
52+
```
53+
54+
3. Initialize Optimizely with required `sdk_key` and other optional arguments.
55+
56+
```
57+
optimizely_instance = Optimizely::OptimizelyFactory.custom_instance(
58+
sdk_key,
59+
datafile,
60+
event_dispatcher,
61+
logger,
62+
error_handler,
63+
skip_json_validation,
64+
user_profile_service,
65+
config_manager,
66+
notification_center
67+
)
68+
```
69+
70+
71+
#### HTTP Config Manager
72+
73+
The `HTTPConfigManager` asynchronously polls for datafiles from a specified URL at regular intervals by making HTTP requests.
74+
75+
76+
~~~~~~
77+
http_project_config_manager = Optimizely::HTTPProjectConfigManager.new(
78+
sdk_key: nil,
79+
url: nil,
80+
datafile: nil,
81+
url_template: nil,
82+
auto_update: nil,
83+
polling_interval: nil,
84+
start_by_default: nil,
85+
blocking_timeout: nil,
86+
logger: nil,
87+
error_handler: nil,
88+
skip_json_validation: false,
89+
notification_center: notification_center
90+
)
91+
~~~~~~
92+
**Note:** You must provide either the `sdk_key` or URL. If you provide both, the URL takes precedence.
93+
94+
**sdk_key**
95+
The `sdk_key` is used to compose the outbound HTTP request to the default datafile location on the Optimizely CDN.
96+
97+
**datafile**
98+
You can provide an initial datafile to bootstrap the `DataFileProjectConfig` so that it can be used immediately. The initial datafile also serves as a fallback datafile if HTTP connection cannot be established. The initial datafile will be discarded after the first successful datafile poll.
99+
100+
**polling_interval**
101+
The polling_interval is used to specify a fixed delay in seconds between consecutive HTTP requests for the datafile.
102+
103+
**url_template**
104+
A string with placeholder `{sdk_key}` can be provided so that this template along with the provided `sdk_key` is used to form the target URL.
105+
106+
**start_by_default**
107+
Boolean flag used to start the `AsyncScheduler` for datafile polling if set to `True`.
108+
109+
**blocking_timeout**
110+
Maximum time in seconds to block the `get_config` call until config has been initialized.
111+
112+
You may also provide your own logger, error handler, or notification center.
113+
114+
115+
#### Advanced configuration
116+
The following properties can be set to override the default configurations for `HTTPConfigManager`.
117+
118+
| **PropertyName** | **Default Value** | **Description**
119+
| -- | -- | --
120+
| update_interval | 5 minutes | Fixed delay between fetches for the datafile
121+
| sdk_key | nil | Optimizely project SDK key
122+
| url | nil | URL override location used to specify custom HTTP source for the Optimizely datafile
123+
| url_template | 'https://cdn.optimizely.com/datafiles/{sdk_key}.json' | Parameterized datafile URL by SDK key
124+
| datafile | nil | Initial datafile, typically sourced from a local cached source
125+
| auto_update | true | Boolean flag to specify if callback needs to execute infinitely or only once
126+
| start_by_default | true | Boolean flag to specify if datafile polling should start right away as soon as `HTTPConfigManager` initializes
127+
| blocking_timeout | 15 seconds | Maximum time in seconds to block the `get_config` call until config has been initialized
128+
129+
A notification signal will be triggered whenever a _new_ datafile is fetched and Project Config is updated. To subscribe to these notifications, use the `notification_center.add_notification_listener(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:OPTIMIZELY_CONFIG_UPDATE], @callback)`
130+
26131
See the Optimizely Full Stack [developer documentation](http://developers.optimizely.com/server/reference/index.html) to learn how to set up your first Full Stack project and use the SDK.
27132
28133
## Development

0 commit comments

Comments
 (0)