11using Microsoft . Extensions . Logging ;
22using System ;
33using System . Collections . Generic ;
4+ using OfflineHandler ;
5+ using System . Net . Http ;
46
57namespace Flagsmith
68{
7- public class FlagsmithConfiguration : IFlagsmithConfiguration
9+ public class FlagsmithConfiguration
810 {
9- public FlagsmithConfiguration ( )
11+ private static readonly Uri DefaultApiUri = new Uri ( "https://edge.api.flagsmith.com/api/v1/" ) ;
12+ private TimeSpan _timeout ;
13+
14+ /// <summary>
15+ /// <para>Override the URL of the Flagsmith API to communicate with.</para>
16+ /// <para>Deprecated since 7.1.0. Use <see cref="ApiUri"/> instead.</para>
17+ /// </summary>
18+ [ Obsolete ( "Use ApiUri instead." ) ]
19+ public string ApiUrl
1020 {
11- ApiUrl = "https://edge.api.flagsmith.com/api/v1/" ;
12- EnvironmentKey = string . Empty ;
13- EnvironmentRefreshIntervalSeconds = 60 ;
21+ get => ApiUri . ToString ( ) ;
22+ set => ApiUri = value . EndsWith ( "/" ) ? new Uri ( value ) : new Uri ( $ "{ value } /") ;
1423 }
24+
1525 /// <summary>
16- /// Override the URL of the Flagsmith API to communicate with.
26+ /// Versioned base Flagsmith API URI to use for all requests. Defaults to
27+ /// <c>https://edge.api.flagsmith.com/api/v1/</c>.
28+ /// <example><code>new Uri("https://flagsmith.example.com/api/v1/")</code></example>
1729 /// </summary>
18- public string ApiUrl { get ; set ; }
30+ public Uri ApiUri { get ; set ; } = DefaultApiUri ;
31+
1932 /// <summary>
2033 /// The environment key obtained from Flagsmith interface.
2134 /// </summary>
2235 public string EnvironmentKey { get ; set ; }
36+
2337 /// <summary>
2438 /// Enables local evaluation of flags.
2539 /// </summary>
26- public bool EnableClientSideEvaluation { get ; set ; }
40+ [ Obsolete ( "Use EnableLocalEvaluation instead." ) ]
41+ public bool EnableClientSideEvaluation
42+ {
43+ get => EnableLocalEvaluation ;
44+ set => EnableLocalEvaluation = value ;
45+ }
46+
47+ /// <summary>
48+ /// Enables local evaluation of flags.
49+ /// </summary>
50+ public bool EnableLocalEvaluation { get ; set ; }
51+
52+ /// <summary>
53+ /// <para>If using local evaluation, specify the interval period between refreshes of local environment data.</para>
54+ /// <para>Deprecated since 7.1.0. Use <see cref="EnvironmentRefreshInterval"/> instead.</para>
55+ /// </summary>
56+ [ Obsolete ( "Use EnvironmentRefreshInterval instead." ) ]
57+ public int EnvironmentRefreshIntervalSeconds
58+ {
59+ get => EnvironmentRefreshInterval . Seconds ;
60+ set => EnvironmentRefreshInterval = TimeSpan . FromSeconds ( value ) ;
61+ }
2762 /// <summary>
2863 /// If using local evaluation, specify the interval period between refreshes of local environment data.
2964 /// </summary>
30- public int EnvironmentRefreshIntervalSeconds { get ; set ; }
65+ public TimeSpan EnvironmentRefreshInterval { get ; set ; } = TimeSpan . FromSeconds ( 60 ) ;
3166 /// <summary>
3267 /// Callable which will be used in the case where flags cannot be retrieved from the API or a non existent feature is requested.
3368 /// </summary>
34- public Func < string , Flag > DefaultFlagHandler { get ; set ; }
69+ public Func < string , Flag > ? DefaultFlagHandler { get ; set ; }
3570 /// <summary>
3671 /// Provide logger for logging polling info & errors which is only applicable when client side evalution is enabled and analytics errors.
3772 /// </summary>
@@ -40,10 +75,24 @@ public FlagsmithConfiguration()
4075 /// if enabled, sends additional requests to the Flagsmith API to power flag analytics charts.
4176 /// </summary>
4277 public bool EnableAnalytics { get ; set ; }
78+
4379 /// <summary>
4480 /// Number of seconds to wait for a request to complete before terminating the request
4581 /// </summary>
46- public Double ? RequestTimeout { get ; set ; }
82+ public Double ? RequestTimeout
83+ {
84+ get => _timeout . Seconds ;
85+ set => _timeout = TimeSpan . FromSeconds ( value ?? 100 ) ;
86+ }
87+
88+ /// <summary>
89+ /// Timeout duration to use for HTTP requests.
90+ /// </summary>
91+ public TimeSpan Timeout
92+ {
93+ get => _timeout ;
94+ set => _timeout = value ;
95+ }
4796 /// <summary>
4897 /// Total http retries for every failing request before throwing the final error.
4998 /// </summary>
@@ -56,11 +105,27 @@ public FlagsmithConfiguration()
56105 /// <summary>
57106 /// If enabled, the SDK will cache the flags for the duration specified in the CacheConfig
58107 /// </summary>
59- public CacheConfig CacheConfig { get ; set ; }
108+ public CacheConfig CacheConfig { get ; set ; } = new CacheConfig ( false ) ;
109+
110+ /// <summary>
111+ /// Indicates whether the client is in offline mode.
112+ /// </summary>
113+ public bool OfflineMode { get ; set ; }
114+
115+ /// <summary>
116+ /// Handler for offline mode operations.
117+ /// </summary>
118+ public BaseOfflineHandler ? OfflineHandler { get ; set ; }
119+
120+ /// <summary>
121+ /// Http client used for flagsmith-API requests.
122+ /// </summary>
123+ public HttpClient HttpClient { get ; set ; } = new HttpClient ( ) ;
60124
125+ [ Obsolete ( "This method will be removed in a future release." ) ]
61126 public bool IsValid ( )
62127 {
63- return ! string . IsNullOrEmpty ( ApiUrl ) && ! string . IsNullOrEmpty ( EnvironmentKey ) ;
128+ return ! string . IsNullOrEmpty ( ApiUri . ToString ( ) ) && ! string . IsNullOrEmpty ( EnvironmentKey ) ;
64129 }
65130 }
66131}
0 commit comments