23
23
import com .optimizely .ab .Optimizely ;
24
24
import com .optimizely .ab .UnknownEventTypeException ;
25
25
import com .optimizely .ab .config .Experiment ;
26
+ import com .optimizely .ab .config .ProjectConfig ;
26
27
import com .optimizely .ab .config .Variation ;
27
28
import com .optimizely .ab .notification .NotificationListener ;
28
29
@@ -60,10 +61,10 @@ public class OptimizelyClient {
60
61
*/
61
62
public @ Nullable Variation activate (@ NonNull String experimentKey ,
62
63
@ NonNull String userId ) {
63
- if (optimizely != null ) {
64
+ if (isValid () ) {
64
65
return optimizely .activate (experimentKey , userId );
65
66
} else {
66
- logger .warn ("Optimizely is not initialized, can't activate experiment {} for user {}" ,
67
+ logger .warn ("Optimizely is not initialized, could not activate experiment {} for user {}" ,
67
68
experimentKey , userId );
68
69
return null ;
69
70
}
@@ -81,15 +82,28 @@ public class OptimizelyClient {
81
82
public @ Nullable Variation activate (@ NonNull String experimentKey ,
82
83
@ NonNull String userId ,
83
84
@ NonNull Map <String , String > attributes ) {
84
- if (optimizely != null ) {
85
+ if (isValid () ) {
85
86
return optimizely .activate (experimentKey , userId , attributes );
86
87
} else {
87
- logger .warn ("Optimizely is not initialized, can't activate experiment {} for user {} " +
88
+ logger .warn ("Optimizely is not initialized, could not activate experiment {} for user {} " +
88
89
"with attributes" , experimentKey , userId );
89
90
return null ;
90
91
}
91
92
}
92
93
94
+ /**
95
+ * Get the {@link ProjectConfig} instance
96
+ * @return the current {@link ProjectConfig} instance
97
+ */
98
+ public @ Nullable ProjectConfig getProjectConfig () {
99
+ if (isValid ()) {
100
+ return optimizely .getProjectConfig ();
101
+ } else {
102
+ logger .warn ("Optimizely is not initialized, could not get project config" );
103
+ return null ;
104
+ }
105
+ }
106
+
93
107
/**
94
108
* Check that this is a valid instance
95
109
* @return True if the OptimizelyClient instance was instantiated correctly
@@ -105,7 +119,7 @@ public boolean isValid() {
105
119
*/
106
120
public void track (@ NonNull String eventName ,
107
121
@ NonNull String userId ) {
108
- if (optimizely != null ) {
122
+ if (isValid () ) {
109
123
optimizely .track (eventName , userId );
110
124
} else {
111
125
logger .warn ("Optimizely is not initialized, could not track event {} for user {}" , eventName , userId );
@@ -121,7 +135,7 @@ public void track(@NonNull String eventName,
121
135
public void track (@ NonNull String eventName ,
122
136
@ NonNull String userId ,
123
137
@ NonNull Map <String , String > attributes ) throws UnknownEventTypeException {
124
- if (optimizely != null ) {
138
+ if (isValid () ) {
125
139
optimizely .track (eventName , userId , attributes );
126
140
127
141
} else {
@@ -141,7 +155,7 @@ public void track(@NonNull String eventName,
141
155
@ NonNull String userId ,
142
156
@ NonNull Map <String , String > attributes ,
143
157
@ NonNull Map <String , ?> eventTags ) throws UnknownEventTypeException {
144
- if (optimizely != null ) {
158
+ if (isValid () ) {
145
159
optimizely .track (eventName , userId , attributes , eventTags );
146
160
147
161
} else {
@@ -160,7 +174,7 @@ public void track(@NonNull String eventName,
160
174
public void track (@ NonNull String eventName ,
161
175
@ NonNull String userId ,
162
176
long eventValue ) throws UnknownEventTypeException {
163
- if (optimizely != null ) {
177
+ if (isValid () ) {
164
178
optimizely .track (eventName , userId , eventValue );
165
179
} else {
166
180
logger .warn ("Optimizely is not initialized, could not track event {} for user {}" +
@@ -181,7 +195,7 @@ public void track(@NonNull String eventName,
181
195
@ NonNull String userId ,
182
196
@ NonNull Map <String , String > attributes ,
183
197
long eventValue ) {
184
- if (optimizely != null ) {
198
+ if (isValid () ) {
185
199
optimizely .track (eventName , userId , attributes , eventValue );
186
200
} else {
187
201
logger .warn ("Optimizely is not initialized, could not track event {} for user {}" +
@@ -215,7 +229,7 @@ public void track(@NonNull String eventName,
215
229
@ NonNull String userId ,
216
230
@ NonNull Map <String , String > attributes ,
217
231
boolean activateExperiment ) {
218
- if (optimizely != null ) {
232
+ if (isValid () ) {
219
233
return optimizely .getVariableString (variableKey , userId , attributes ,
220
234
activateExperiment );
221
235
} else {
@@ -251,7 +265,7 @@ public void track(@NonNull String eventName,
251
265
@ NonNull String userId ,
252
266
@ NonNull Map <String , String > attributes ,
253
267
boolean activateExperiment ) {
254
- if (optimizely != null ) {
268
+ if (isValid () ) {
255
269
return optimizely .getVariableBoolean (variableKey , userId , attributes ,
256
270
activateExperiment );
257
271
} else {
@@ -287,7 +301,7 @@ public void track(@NonNull String eventName,
287
301
@ NonNull String userId ,
288
302
@ NonNull Map <String , String > attributes ,
289
303
boolean activateExperiment ) {
290
- if (optimizely != null ) {
304
+ if (isValid () ) {
291
305
return optimizely .getVariableInteger (variableKey , userId , attributes ,
292
306
activateExperiment );
293
307
} else {
@@ -323,7 +337,7 @@ public void track(@NonNull String eventName,
323
337
@ NonNull String userId ,
324
338
@ NonNull Map <String , String > attributes ,
325
339
boolean activateExperiment ) {
326
- if (optimizely != null ) {
340
+ if (isValid () ) {
327
341
return optimizely .getVariableDouble (variableKey , userId , attributes ,
328
342
activateExperiment );
329
343
} else {
@@ -343,7 +357,7 @@ public void track(@NonNull String eventName,
343
357
@ SuppressWarnings ("WeakerAccess" )
344
358
public @ Nullable Variation getVariation (@ NonNull String experimentKey ,
345
359
@ NonNull String userId ) {
346
- if (optimizely != null ) {
360
+ if (isValid () ) {
347
361
return optimizely .getVariation (experimentKey , userId );
348
362
} else {
349
363
logger .warn ("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -364,7 +378,7 @@ public void track(@NonNull String eventName,
364
378
public @ Nullable Variation getVariation (@ NonNull String experimentKey ,
365
379
@ NonNull String userId ,
366
380
@ NonNull Map <String , String > attributes ) {
367
- if (optimizely != null ) {
381
+ if (isValid () ) {
368
382
return optimizely .getVariation (experimentKey , userId , attributes );
369
383
} else {
370
384
logger .warn ("Optimizely is not initialized, could not get variation for experiment {} " +
@@ -385,7 +399,7 @@ public void track(@NonNull String eventName,
385
399
* @param listener listener to add
386
400
*/
387
401
public void addNotificationListener (@ NonNull NotificationListener listener ) {
388
- if (optimizely != null ) {
402
+ if (isValid () ) {
389
403
optimizely .addNotificationListener (listener );
390
404
} else {
391
405
logger .warn ("Optimizely is not initialized, could not add notification listener" );
@@ -398,7 +412,7 @@ public void addNotificationListener(@NonNull NotificationListener listener) {
398
412
* @param listener listener to remove
399
413
*/
400
414
public void removeNotificationListener (@ NonNull NotificationListener listener ) {
401
- if (optimizely != null ) {
415
+ if (isValid () ) {
402
416
optimizely .removeNotificationListener (listener );
403
417
} else {
404
418
logger .warn ("Optimizely is not initialized, could not remove notification listener" );
@@ -409,7 +423,7 @@ public void removeNotificationListener(@NonNull NotificationListener listener) {
409
423
* Remove all {@link NotificationListener} instances.
410
424
*/
411
425
public void clearNotificationListeners () {
412
- if (optimizely != null ) {
426
+ if (isValid () ) {
413
427
optimizely .clearNotificationListeners ();
414
428
} else {
415
429
logger .warn ("Optimizely is not initialized, could not clear notification listeners" );
0 commit comments