@@ -43,11 +43,11 @@ var sdkKey int
43
43
44
44
// ClientWrapper - wrapper around the optimizely client that keeps track of various custom components used with the client
45
45
type ClientWrapper struct {
46
- Client * client.OptimizelyClient
47
- DecisionService decision. Service
48
- EventDispatcher event. Dispatcher
49
- UserProfileService decision.UserProfileService
50
- OverrideStore decision. ExperimentOverrideStore
46
+ client * client.OptimizelyClient
47
+ eventDispatcher event. Dispatcher
48
+ userProfileService decision. UserProfileService
49
+ overrideStore decision.ExperimentOverrideStore
50
+ notificationManager * optlyplugins. NotificationManager
51
51
}
52
52
53
53
// DeleteInstance deletes cached instance of optly wrapper
@@ -98,28 +98,25 @@ func GetInstance(apiOptions models.APIOptions) *ClientWrapper {
98
98
)
99
99
100
100
// @TODO: Add sdkKey dynamically once event-batching support is implemented
101
-
102
- compositeService := * decision .NewCompositeService (strconv .Itoa (sdkKey ), decision .WithCompositeExperimentService (compositeExperimentService ))
103
- decisionService := & optlyplugins.TestCompositeService {CompositeService : compositeService }
104
-
101
+ compositeService := decision .NewCompositeService (strconv .Itoa (sdkKey ), decision .WithCompositeExperimentService (compositeExperimentService ))
105
102
client , err := optimizelyFactory .Client (
106
103
client .WithConfigManager (configManager ),
107
- client .WithDecisionService (decisionService ),
104
+ client .WithDecisionService (compositeService ),
108
105
client .WithEventProcessor (eventProcessor ),
109
106
)
110
107
if err != nil {
111
108
log .Fatal (err )
112
109
}
113
110
111
+ notificationManager := optlyplugins.NotificationManager {}
112
+ notificationManager .SubscribeNotifications (apiOptions .Listeners , client )
114
113
clientInstance = & ClientWrapper {
115
- Client : client ,
116
- DecisionService : decisionService ,
117
- EventDispatcher : eventProcessor . EventDispatcher ,
118
- UserProfileService : userProfileService ,
119
- OverrideStore : overrideStore ,
114
+ client : client ,
115
+ eventDispatcher : eventProcessor . EventDispatcher ,
116
+ userProfileService : userProfileService ,
117
+ overrideStore : overrideStore ,
118
+ notificationManager : & notificationManager ,
120
119
}
121
- clientInstance .DecisionService .(* optlyplugins.TestCompositeService ).AddListeners (apiOptions .Listeners )
122
-
123
120
return clientInstance
124
121
}
125
122
@@ -170,8 +167,8 @@ func (c *ClientWrapper) InvokeAPI(request models.APIOptions) (models.APIResponse
170
167
break
171
168
}
172
169
// TODO: For event batching, it should be conditional.
173
- c .Client .Close ()
174
- response .ListenerCalled = c .DecisionService .( * optlyplugins. TestCompositeService ) .GetListenersCalled ()
170
+ c .client .Close ()
171
+ response .ListenerCalled = c .notificationManager .GetListenersCalled ()
175
172
return response , err
176
173
}
177
174
@@ -185,7 +182,7 @@ func (c *ClientWrapper) isFeatureEnabled(request models.APIOptions) (models.APIR
185
182
Attributes : params .Attributes ,
186
183
}
187
184
188
- isEnabled , err := c .Client .IsFeatureEnabled (params .FeatureKey , user )
185
+ isEnabled , err := c .client .IsFeatureEnabled (params .FeatureKey , user )
189
186
result := "false"
190
187
if err == nil && isEnabled {
191
188
result = "true"
@@ -204,7 +201,7 @@ func (c *ClientWrapper) getFeatureVariable(request models.APIOptions) (models.AP
204
201
ID : params .UserID ,
205
202
Attributes : params .Attributes ,
206
203
}
207
- value , valueType , err := c .Client .GetFeatureVariable (params .FeatureKey , params .VariableKey , user )
204
+ value , valueType , err := c .client .GetFeatureVariable (params .FeatureKey , params .VariableKey , user )
208
205
if err == nil {
209
206
response .Result = value
210
207
response .Type = valueType
@@ -222,7 +219,7 @@ func (c *ClientWrapper) getFeatureVariableInteger(request models.APIOptions) (mo
222
219
ID : params .UserID ,
223
220
Attributes : params .Attributes ,
224
221
}
225
- value , err := c .Client .GetFeatureVariableInteger (params .FeatureKey , params .VariableKey , user )
222
+ value , err := c .client .GetFeatureVariableInteger (params .FeatureKey , params .VariableKey , user )
226
223
if err == nil {
227
224
response .Result = value
228
225
}
@@ -239,7 +236,7 @@ func (c *ClientWrapper) getFeatureVariableDouble(request models.APIOptions) (mod
239
236
ID : params .UserID ,
240
237
Attributes : params .Attributes ,
241
238
}
242
- value , err := c .Client .GetFeatureVariableDouble (params .FeatureKey , params .VariableKey , user )
239
+ value , err := c .client .GetFeatureVariableDouble (params .FeatureKey , params .VariableKey , user )
243
240
if err == nil {
244
241
response .Result = value
245
242
}
@@ -256,7 +253,7 @@ func (c *ClientWrapper) getFeatureVariableBoolean(request models.APIOptions) (mo
256
253
ID : params .UserID ,
257
254
Attributes : params .Attributes ,
258
255
}
259
- value , err := c .Client .GetFeatureVariableBoolean (params .FeatureKey , params .VariableKey , user )
256
+ value , err := c .client .GetFeatureVariableBoolean (params .FeatureKey , params .VariableKey , user )
260
257
if err == nil {
261
258
response .Result = value
262
259
}
@@ -273,7 +270,7 @@ func (c *ClientWrapper) getFeatureVariableString(request models.APIOptions) (mod
273
270
ID : params .UserID ,
274
271
Attributes : params .Attributes ,
275
272
}
276
- value , err := c .Client .GetFeatureVariableString (params .FeatureKey , params .VariableKey , user )
273
+ value , err := c .client .GetFeatureVariableString (params .FeatureKey , params .VariableKey , user )
277
274
if err == nil {
278
275
response .Result = value
279
276
}
@@ -291,7 +288,7 @@ func (c *ClientWrapper) getEnabledFeatures(request models.APIOptions) (models.AP
291
288
ID : params .UserID ,
292
289
Attributes : params .Attributes ,
293
290
}
294
- if values , err := c .Client .GetEnabledFeatures (user ); err == nil {
291
+ if values , err := c .client .GetEnabledFeatures (user ); err == nil {
295
292
enabledFeatures = values
296
293
}
297
294
response .Result = enabledFeatures
@@ -308,7 +305,7 @@ func (c *ClientWrapper) getVariation(request models.APIOptions) (models.APIRespo
308
305
ID : params .UserID ,
309
306
Attributes : params .Attributes ,
310
307
}
311
- response .Result , _ = c .Client .GetVariation (params .ExperimentKey , user )
308
+ response .Result , _ = c .client .GetVariation (params .ExperimentKey , user )
312
309
if response .Result == "" {
313
310
response .Result = "NULL"
314
311
}
@@ -325,7 +322,7 @@ func (c *ClientWrapper) activate(request models.APIOptions) (models.APIResponse,
325
322
ID : params .UserID ,
326
323
Attributes : params .Attributes ,
327
324
}
328
- response .Result , _ = c .Client .Activate (params .ExperimentKey , user )
325
+ response .Result , _ = c .client .Activate (params .ExperimentKey , user )
329
326
if response .Result == "" {
330
327
response .Result = "NULL"
331
328
}
@@ -342,7 +339,7 @@ func (c *ClientWrapper) track(request models.APIOptions) (models.APIResponse, er
342
339
ID : params .UserID ,
343
340
Attributes : params .Attributes ,
344
341
}
345
- err = c .Client .Track (params .EventKey , user , params .EventTags )
342
+ err = c .client .Track (params .EventKey , user , params .EventTags )
346
343
}
347
344
response .Result = "NULL"
348
345
return response , err
@@ -356,9 +353,9 @@ func (c *ClientWrapper) setForcedVariation(request models.APIOptions) (models.AP
356
353
if err == nil {
357
354
// For removeForcedVariation cases
358
355
if params .VariationKey == "" {
359
- c .OverrideStore .(* decision.MapExperimentOverridesStore ).RemoveVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID })
356
+ c .overrideStore .(* decision.MapExperimentOverridesStore ).RemoveVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID })
360
357
} else {
361
- c .OverrideStore .(* decision.MapExperimentOverridesStore ).SetVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID }, params .VariationKey )
358
+ c .overrideStore .(* decision.MapExperimentOverridesStore ).SetVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID }, params .VariationKey )
362
359
response .Result = params .VariationKey
363
360
}
364
361
}
@@ -371,7 +368,7 @@ func (c *ClientWrapper) getForcedVariation(request models.APIOptions) (models.AP
371
368
err := yaml .Unmarshal ([]byte (request .Arguments ), & params )
372
369
response .Result = "NULL"
373
370
if err == nil {
374
- variation , success := c .OverrideStore .(* decision.MapExperimentOverridesStore ).GetVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID })
371
+ variation , success := c .overrideStore .(* decision.MapExperimentOverridesStore ).GetVariation (decision.ExperimentOverrideKey {ExperimentKey : params .ExperimentKey , UserID : params .UserID })
375
372
if success {
376
373
response .Result = variation
377
374
}
0 commit comments