@@ -32,6 +32,7 @@ namespace VWOFmeSdk
32
32
{
33
33
public class VWOClient
34
34
{
35
+ private static VWOClient vwoClientInstance ;
35
36
private Settings processedSettings ;
36
37
public string Settings { get ; private set ; }
37
38
private VWOInitOptions options ;
@@ -40,8 +41,6 @@ public class VWOClient
40
41
MissingMemberHandling = MissingMemberHandling . Ignore
41
42
} ;
42
43
43
- public static ObjectMapper ObjectMapper { get ; } = new ObjectMapper ( ) ;
44
-
45
44
/// <summary>
46
45
/// Constructor to initialize the VWOClient
47
46
/// </summary>
@@ -64,6 +63,8 @@ public VWOClient(string settings, VWOInitOptions options)
64
63
UrlService . Init ( this . processedSettings . CollectionPrefix ) ;
65
64
// Init SDKMetaUtil and set SDK version
66
65
LoggerService . Log ( LogLevelEnum . INFO , "CLIENT_INITIALIZED" , null ) ;
66
+
67
+ vwoClientInstance = this ;
67
68
}
68
69
catch ( Exception exception )
69
70
{
@@ -82,13 +83,59 @@ public void UpdateSettings(string newSettings)
82
83
{
83
84
this . processedSettings = JsonConvert . DeserializeObject < Settings > ( newSettings , JsonSerializerSettings ) ;
84
85
SettingsUtil . ProcessSettings ( this . processedSettings ) ;
86
+ LoggerService . Log ( LogLevelEnum . INFO , "SETTINGS_UPDATED_SUCCESSFULLY" , null ) ;
85
87
}
86
88
catch ( Exception exception )
87
89
{
88
90
LoggerService . Log ( LogLevelEnum . ERROR , "Exception occurred while updating settings: " + exception . Message ) ;
89
91
}
90
92
}
91
93
94
+ /// <summary>
95
+ /// This method is used to update the settings by fetching from server (overloaded method with no parameters).
96
+ /// </summary>
97
+ /// <returns>Updated settings in JSON string format</returns>
98
+ public string UpdateSettings ( )
99
+ {
100
+ return UpdateSettings ( true ) ;
101
+ }
102
+
103
+ /// <summary>
104
+ /// This method is used to update the settings.
105
+ /// </summary>
106
+ /// <param name="isViaWebhook">Boolean value to indicate if the settings are being fetched via webhook</param>
107
+ /// <returns>Updated settings in JSON string format</returns>
108
+ public string UpdateSettings ( bool isViaWebhook )
109
+ {
110
+ string apiName = "updateSettings" ;
111
+ try
112
+ {
113
+ // Fetch the new settings from the server based on the webhook flag
114
+ this . Settings = SettingsManager . GetInstance ( ) . FetchSettings ( isViaWebhook ) ;
115
+ UpdateSettings ( this . Settings ) ; // Call the method that takes a settings string
116
+ return this . Settings ;
117
+ }
118
+ catch ( Exception exception )
119
+ {
120
+ LoggerService . Log ( LogLevelEnum . ERROR , "SETTINGS_FETCH_FAILED" , new Dictionary < string , string >
121
+ {
122
+ { "apiName" , apiName } ,
123
+ { "isViaWebhook" , isViaWebhook . ToString ( ) } ,
124
+ { "err" , exception . ToString ( ) }
125
+ } ) ;
126
+ return null ;
127
+ }
128
+ }
129
+
130
+ /// <summary>
131
+ /// Static method to get the VWOClient instance
132
+ /// </summary>
133
+ /// <returns>VWOClient instance</returns>
134
+ public static VWOClient GetInstance ( )
135
+ {
136
+ return vwoClientInstance ;
137
+ }
138
+
92
139
/// <summary>
93
140
/// This method is used to get the flag value for the given feature key
94
141
/// </summary>
@@ -205,8 +252,7 @@ public Dictionary<string, bool> TrackEvent(string eventName, VWOContext context,
205
252
}
206
253
207
254
/// <summary>
208
- /// Overloaded function for no event properties
209
- /// calls track method to track the event
255
+ /// Overloaded function when no event properties are required
210
256
/// </summary>
211
257
/// <param name="eventName">Event name to be tracked</param>
212
258
/// <param name="context">User context</param>
@@ -215,73 +261,5 @@ public Dictionary<string, bool> TrackEvent(string eventName, VWOContext context)
215
261
{
216
262
return Track ( eventName , context , new Dictionary < string , object > ( ) ) ;
217
263
}
218
-
219
- /// <summary>
220
- /// Sets an attribute for a user in the context provided.
221
- /// This method validates the types of the inputs before proceeding with the API call.
222
- /// </summary>
223
- /// <param name="attributeKey">The key of the attribute to set</param>
224
- /// <param name="attributeValue">The value of the attribute to set</param>
225
- /// <param name="context">User context</param>
226
- public void SetAttribute ( string attributeKey , string attributeValue , VWOContext context )
227
- {
228
- string apiName = "setAttribute" ;
229
- try
230
- {
231
- LoggerService . Log ( LogLevelEnum . DEBUG , "API_CALLED" , new Dictionary < string , string > { { "apiName" , apiName } } ) ;
232
- if ( ! DataTypeUtil . IsString ( attributeKey ) )
233
- {
234
- LoggerService . Log ( LogLevelEnum . ERROR , "API_INVALID_PARAM" , new Dictionary < string , string >
235
- {
236
- { "apiName" , apiName } ,
237
- { "key" , "attributeKey" } ,
238
- { "type" , DataTypeUtil . GetType ( attributeKey ) } ,
239
- { "correctType" , "String" }
240
- } ) ;
241
- throw new ArgumentException ( "TypeError: attributeKey should be a string" ) ;
242
- }
243
-
244
- if ( ! DataTypeUtil . IsString ( attributeValue ) )
245
- {
246
- LoggerService . Log ( LogLevelEnum . ERROR , "API_INVALID_PARAM" , new Dictionary < string , string >
247
- {
248
- { "apiName" , apiName } ,
249
- { "key" , "attributeValue" } ,
250
- { "type" , DataTypeUtil . GetType ( attributeValue ) } ,
251
- { "correctType" , "String" }
252
- } ) ;
253
- throw new ArgumentException ( "TypeError: attributeValue should be a string" ) ;
254
- }
255
-
256
- if ( context == null || string . IsNullOrEmpty ( context . Id ) )
257
- {
258
- throw new ArgumentException ( "User ID is required" ) ;
259
- }
260
-
261
- if ( this . processedSettings == null || ! new SettingsSchema ( ) . IsSettingsValid ( this . processedSettings ) )
262
- {
263
- LoggerService . Log ( LogLevelEnum . ERROR , "SETTINGS_SCHEMA_INVALID" , null ) ;
264
- return ;
265
- }
266
-
267
- SetAttributeAPI . SetAttribute ( this . processedSettings , attributeKey , attributeValue , context ) ;
268
- }
269
- catch ( Exception exception )
270
- {
271
- LoggerService . Log ( LogLevelEnum . ERROR , "API_THROW_ERROR" , new Dictionary < string , string >
272
- {
273
- { "apiName" , apiName } ,
274
- { "err" , exception . ToString ( ) }
275
- } ) ;
276
- }
277
- }
278
- }
279
-
280
- public class ObjectMapper
281
- {
282
- public Dictionary < string , object > ConvertValue < T > ( T value )
283
- {
284
- return JsonConvert . DeserializeObject < Dictionary < string , object > > ( JsonConvert . SerializeObject ( value ) ) ;
285
- }
286
264
}
287
- }
265
+ }
0 commit comments