|
5 | 5 | logging.basicConfig(level=logging.WARNING) |
6 | 6 |
|
7 | 7 | if __name__ == '__main__': |
8 | | - config = fp.Config(remote_uri='http://127.0.0.1:4007', # FeatureProbe server URL |
| 8 | + # FEATURE_PROBE_SERVER_URL = 'http://localhost:4007' # for local docker |
| 9 | + FEATURE_PROBE_SERVER_URL = 'https://featureprobe.io/server' # for featureprobe.io |
| 10 | + |
| 11 | + config = fp.Config(remote_uri=FEATURE_PROBE_SERVER_URL, # FeatureProbe server URL |
9 | 12 | sync_mode='pooling', |
10 | 13 | refresh_interval=3) |
11 | 14 |
|
12 | | - client = fp.Client('server-8ed48815ef044428826787e9a238b9c6a479f98c', |
| 15 | + client = fp.Client('server-b8b7c58417680d9e76b1b8454326f357296b5003', |
13 | 16 | # Server Side SDK Key for your project and environment |
14 | 17 | config) |
15 | 18 |
|
16 | | - # create one user, with id='user_unique_id' and one attribute |
17 | | - user = fp.User('user_unique_id', {'city': 'New York'}) |
18 | | - discount = float(client.evaluate('promotion_activity', # Toggle you want to use |
19 | | - user, default=0)) |
20 | | - print('user in New York has a discount of : %d' % discount) |
21 | | - |
22 | | - detail = client.evaluate_detail('promotion_activity', user, default=0) |
23 | | - print('detail: %s' % detail.reason) |
24 | | - # rule_index = None on default rule is hit |
25 | | - print('rule index: ' + str(detail.rule_index)) |
| 19 | + # create one user |
| 20 | + # key is for percentage rollout, normally use userId as key |
| 21 | + user = fp.User('00001', {'userId': '00001'}) |
26 | 22 |
|
27 | | - user2 = fp.User('user_id2') |
28 | | - # create another user, here's the alternative way to set user attributes |
29 | | - user2['city'] = 'Paris' |
| 23 | + # Toggle you want to use |
| 24 | + TOGGLE_KEY = 'feature_toggle02' |
30 | 25 |
|
31 | | - discount = float(client.evaluate('promotion_activity', user2, default=0)) |
32 | | - print('user in Paris has a discount of : %d' % discount) |
| 26 | + # get toggle result for this user |
| 27 | + is_open = client.value(TOGGLE_KEY, user, default=False) |
| 28 | + print('feature for this user is: ' + str(is_open)) |
33 | 29 |
|
34 | | - detail2 = client.evaluate_detail('promotion_activity', user2, default=0) |
35 | | - print('detail2: %s' % detail2.reason) |
36 | | - print('rule index: %d' % detail2.rule_index) |
| 30 | + is_open_detail = client.value_detail(TOGGLE_KEY, user, default=False) |
| 31 | + print('detail: ' + str(is_open_detail.reason)) |
| 32 | + print('rule index: ' + str(is_open_detail.rule_index)) |
0 commit comments