@@ -195,6 +195,125 @@ impl VoiceIt2 {
195
195
Ok ( body)
196
196
}
197
197
198
+ // SUBACCOUNTS
199
+ pub fn create_managed_sub_account (
200
+ & self ,
201
+ first_name : & str ,
202
+ last_name : & str ,
203
+ email : & str ,
204
+ password : & str ,
205
+ content_language : & str ,
206
+ ) -> Result < String , VoiceItError > {
207
+ let url = format ! (
208
+ "{}/subaccount/managed{}" ,
209
+ String :: from( BASE_URL ) ,
210
+ self . notification_url_parameter
211
+ ) ;
212
+
213
+ let form = multipart:: Form :: new ( )
214
+ . text ( "firstName" , String :: from ( first_name) )
215
+ . text ( "lastName" , String :: from ( last_name) )
216
+ . text ( "email" , String :: from ( email) )
217
+ . text ( "password" , String :: from ( password) )
218
+ . text ( "contentLanguage" , String :: from ( content_language) ) ;
219
+
220
+ let mut response = Client :: new ( )
221
+ . post ( & url)
222
+ . header ( "platformId" , PLATFORM_ID )
223
+ . header ( "platformVersion" , PLATFORM_VERSION )
224
+ . basic_auth ( self . api_key . clone ( ) , Some ( self . api_token . clone ( ) ) )
225
+ . multipart ( form)
226
+ . send ( ) ?;
227
+
228
+ let mut body = String :: new ( ) ;
229
+ response. read_to_string ( & mut body) ?;
230
+
231
+ Ok ( body)
232
+ }
233
+
234
+ pub fn create_unmanaged_sub_account (
235
+ & self ,
236
+ first_name : & str ,
237
+ last_name : & str ,
238
+ email : & str ,
239
+ password : & str ,
240
+ content_language : & str ,
241
+ ) -> Result < String , VoiceItError > {
242
+ let url = format ! (
243
+ "{}/subaccount/unmanaged{}" ,
244
+ String :: from( BASE_URL ) ,
245
+ self . notification_url_parameter
246
+ ) ;
247
+
248
+ let form = multipart:: Form :: new ( )
249
+ . text ( "firstName" , String :: from ( first_name) )
250
+ . text ( "lastName" , String :: from ( last_name) )
251
+ . text ( "email" , String :: from ( email) )
252
+ . text ( "password" , String :: from ( password) )
253
+ . text ( "contentLanguage" , String :: from ( content_language) ) ;
254
+
255
+ let mut response = Client :: new ( )
256
+ . post ( & url)
257
+ . header ( "platformId" , PLATFORM_ID )
258
+ . header ( "platformVersion" , PLATFORM_VERSION )
259
+ . basic_auth ( self . api_key . clone ( ) , Some ( self . api_token . clone ( ) ) )
260
+ . multipart ( form)
261
+ . send ( ) ?;
262
+
263
+ let mut body = String :: new ( ) ;
264
+ response. read_to_string ( & mut body) ?;
265
+
266
+ Ok ( body)
267
+ }
268
+
269
+ pub fn regenerate_sub_account_api_token (
270
+ & self ,
271
+ sub_account_api_key : & str ,
272
+ ) -> Result < String , VoiceItError > {
273
+ let url = format ! (
274
+ "{}/subaccount/{}{}" ,
275
+ String :: from( BASE_URL ) ,
276
+ String :: from( sub_account_api_key) ,
277
+ self . notification_url_parameter
278
+ ) ;
279
+
280
+ let mut response = Client :: new ( )
281
+ . post ( & url)
282
+ . header ( "platformId" , PLATFORM_ID )
283
+ . header ( "platformVersion" , PLATFORM_VERSION )
284
+ . basic_auth ( self . api_key . clone ( ) , Some ( self . api_token . clone ( ) ) )
285
+ . send ( ) ?;
286
+
287
+ let mut body = String :: new ( ) ;
288
+ response. read_to_string ( & mut body) ?;
289
+
290
+ Ok ( body)
291
+ }
292
+
293
+ pub fn delete_subaccount (
294
+ & self ,
295
+ sub_account_api_key : & str ,
296
+ ) -> Result < String , VoiceItError > {
297
+ let url = format ! (
298
+ "{}/subaccount/{}{}" ,
299
+ String :: from( BASE_URL ) ,
300
+ String :: from( sub_account_api_key) ,
301
+ self . notification_url_parameter
302
+ ) ;
303
+
304
+ let mut response = Client :: new ( )
305
+ . delete ( & url)
306
+ . header ( "platformId" , PLATFORM_ID )
307
+ . header ( "platformVersion" , PLATFORM_VERSION )
308
+ . basic_auth ( self . api_key . clone ( ) , Some ( self . api_token . clone ( ) ) )
309
+ . send ( ) ?;
310
+
311
+ let mut body = String :: new ( ) ;
312
+ response. read_to_string ( & mut body) ?;
313
+
314
+ Ok ( body)
315
+ }
316
+
198
317
// GROUPS
199
318
200
319
pub fn create_group ( & self , description : & str ) -> Result < String , VoiceItError > {
0 commit comments