@@ -239,6 +239,10 @@ func (client *Client) CreateAccount(account *Account) (*Account, error) {
239
239
return nil , err
240
240
}
241
241
242
+ err = client .setAccountFeatures (account .Features , & respAccount )
243
+ if err != nil {
244
+ return nil , err
245
+ }
242
246
return & respAccount , nil
243
247
}
244
248
@@ -284,24 +288,10 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
284
288
return nil , err
285
289
}
286
290
287
- // Update Features
288
- requestOptions := & RequestOptions {}
289
- for k , v := range account .Features {
290
- requestOptions .Body = []byte (fmt .Sprintf ("{\" feature\" : \" %s\" }" , k ))
291
- if v {
292
- requestOptions .Path = fmt .Sprintf ("/features/%s" , id )
293
- requestOptions .Method = "POST"
294
- } else {
295
- requestOptions .Path = fmt .Sprintf ("/features/switchOff/%s" , id )
296
- requestOptions .Method = "PUT"
297
- }
298
- _ , err = client .RequestAPI (requestOptions )
299
- if err != nil {
300
- return nil , err
301
- }
302
- respAccount .Features [k ] = v
303
- }
304
-
291
+ err = client .setAccountFeatures (account .Features , & respAccount )
292
+ if err != nil {
293
+ return nil , err
294
+ }
305
295
306
296
return & respAccount , nil
307
297
}
@@ -335,11 +325,32 @@ func GetAccountAdminsDiff(desiredAdmins []string, existingAdmins []string) (admi
335
325
}
336
326
337
327
for _ , id := range desiredAdmins {
338
-
339
328
if ok := FindInSlice (existingAdmins , id ); ! ok {
340
329
adminsToAdd = append (adminsToAdd , id )
341
330
}
342
331
}
343
332
344
333
return adminsToAdd , adminsToDelete
345
334
}
335
+
336
+ // Update Features
337
+ func (client * Client ) setAccountFeatures (features map [string ]bool , account * Account ) error {
338
+ id := account .GetID ()
339
+ requestOptions := & RequestOptions {}
340
+ for k , v := range features {
341
+ requestOptions .Body = []byte (fmt .Sprintf ("{\" feature\" : \" %s\" }" , k ))
342
+ if v {
343
+ requestOptions .Path = fmt .Sprintf ("/features/%s" , id )
344
+ requestOptions .Method = "POST"
345
+ } else {
346
+ requestOptions .Path = fmt .Sprintf ("/features/switchOff/%s" , id )
347
+ requestOptions .Method = "PUT"
348
+ }
349
+ _ , err := client .RequestAPI (requestOptions )
350
+ if err != nil {
351
+ return err
352
+ }
353
+ account .Features [k ] = v
354
+ }
355
+ return nil
356
+ }
0 commit comments