66import io .getunleash .UnleashException ;
77import io .getunleash .event .UnleashReady ;
88import io .getunleash .event .UnleashSubscriber ;
9- import io .getunleash .repository .FeatureToggleResponse ;
109import io .getunleash .repository .OkHttpFeatureFetcher ;
1110import io .getunleash .util .UnleashConfig ;
1211
@@ -15,26 +14,11 @@ public static void main(String[] args) throws InterruptedException {
1514
1615 UnleashConfig config = UnleashConfig .builder ().appName ("client-example.okhttp" )
1716 .customHttpHeader ("Authorization" ,
18- "*:production.ZvzGdauVXYPyevrQVqnt8LSRHKuW" )
19- .unleashAPI ("http://localhost:1500/api" ).instanceId ("okhttp-example" )
17+ getOrElse ("UNLEASH_API_TOKEN" ,
18+ "*:development.25a06b75248528f8ca93ce179dcdd141aedfb632231e0d21fd8ff349" ))
19+ .unleashAPI (getOrElse ("UNLEASH_API_URL" , "https://app.unleash-hosted.com/demo/api" ))
2020 .unleashFeatureFetcherFactory (OkHttpFeatureFetcher ::new )
2121 .fetchTogglesInterval (10 )
22- .subscriber (new UnleashSubscriber () {
23- @ Override
24- public void onReady (UnleashReady unleashReady ) {
25- System .out .println ("Ready" );
26- }
27-
28- @ Override
29- public void togglesFetched (FeatureToggleResponse toggleResponse ) {
30- System .out .println ("Fetched toggles. " + toggleResponse );
31- }
32-
33- @ Override
34- public void onError (UnleashException unleashException ) {
35- System .out .println ("Failed " + unleashException );
36- }
37- })
3822 .synchronousFetchOnInitialisation (true )
3923 .build ();
4024 Unleash unleash = new DefaultUnleash (config );
@@ -46,4 +30,11 @@ public void onError(UnleashException unleashException) {
4630 System .out .println (unleash .getVariant ("my.feature" ));
4731 }
4832 }
33+ public static String getOrElse (String key , String defaultValue ) {
34+ String value = System .getenv (key );
35+ if (value == null ) {
36+ return defaultValue ;
37+ }
38+ return value ;
39+ }
4940}
0 commit comments