1#![allow(dead_code)]
2pub mod client;
3pub mod errors;
4pub mod structs;
5
6extern crate regex;
7
8#[allow(unused_imports)]
9use structs::enrollments::{
10 CreateFaceEnrollmentByUrlReturn, CreateFaceEnrollmentReturn, CreateVideoEnrollmentByUrlReturn,
11 CreateVideoEnrollmentReturn, CreateVoiceEnrollmentByUrlReturn, CreateVoiceEnrollmentReturn,
12 DeleteAllEnrollmentsReturn, GetAllFaceEnrollmentsReturn, GetAllVideoEnrollmentsReturn,
13 GetAllVoiceEnrollmentsReturn,
14};
15
16#[allow(unused_imports)]
17use structs::groups::{
18 AddUserToGroupReturn, CheckGroupExistsReturn, CreateGroupReturn, DeleteGroupReturn,
19 GetAllGroupsReturn, GetGroupReturn, RemoveUserFromGroupReturn,
20};
21
22#[allow(unused_imports)]
23use structs::identification::{
24 FaceIdentificationByUrlReturn, FaceIdentificationReturn, VideoIdentificationByUrlReturn,
25 VideoIdentificationReturn, VoiceIdentificationByUrlReturn, VoiceIdentificationReturn,
26};
27
28#[allow(unused_imports)]
29use structs::phrases::GetPhrasesReturn;
30
31#[allow(unused_imports)]
32use structs::users::{
33 CheckUserExistsReturn, CreateUserReturn, CreateUserTokenReturn, DeleteUserReturn,
34 ExpireUserTokensReturn, GetAllUsersReturn, GetGroupsForUserReturn,
35};
36
37#[allow(unused_imports)]
38use structs::verification::{
39 FaceVerificationByUrlReturn, FaceVerificationReturn, VideoVerificationByUrlReturn,
40 VideoVerificationReturn, VoiceVerificationByUrlReturn, VoiceVerificationReturn,
41};
42
43#[allow(unused_imports)]
44use structs::subaccounts::{
45 CreateSubAccountReturn, DeleteSubAccountReturn, RegenerateSubAccountAPITokenReturn,
46};
47
48use regex::Regex;
49use std::fs::File;
50use std::io::copy;
51
52fn is_user_id(text: &str) -> bool {
53 let re: Regex = Regex::new(r"^usr_[a-zA-Z0-9]{32}$").unwrap();
54 re.is_match(text)
55}
56
57fn is_group_id(text: &str) -> bool {
58 let re: Regex = Regex::new(r"^grp_[a-zA-Z0-9]{32}$").unwrap();
59 re.is_match(text)
60}
61
62fn is_user_token(text: &str) -> bool {
63 let re: Regex = Regex::new(r"^utk_[a-zA-Z0-9]{32}_[0-9]*$").unwrap();
64 re.is_match(text)
65}
66
67fn is_api_key(text: &str) -> bool {
68 let re: Regex = Regex::new(r"^key_[a-zA-Z0-9]{32}$").unwrap();
69 re.is_match(text)
70}
71
72fn download_file(link: &str) -> Result<(), Box<dyn std::error::Error>> {
73 let mut response = reqwest::blocking::get(link)?;
74
75 let mut dest = {
76 let fname = response
77 .url()
78 .path_segments()
79 .and_then(|segments| segments.last())
80 .and_then(|name| if name.is_empty() { None } else { Some(name) })
81 .unwrap_or("tmp.bin");
82
83 println!("file to download: '{}'", fname);
84 let pwd = std::env::var("PWD").unwrap();
85 let fname = format!("{}/{}", pwd, fname);
86 println!("will be located under: '{:?}'", fname);
87 File::create(fname)?
88 };
89 copy(&mut response, &mut dest)?;
90 Ok(())
91}
92
93#[cfg(test)]
94mod tests {
95
96 #[test]
97 fn test_basics() {
98 let env = std::env::var("BOXFUSE_ENV").unwrap();
99 if env == "voiceittest" {
100 let home_dir = std::env::var("HOME").unwrap();
101 std::fs::write(
102 format!("{}/platformVersion", home_dir),
103 crate::client::PLATFORM_VERSION,
104 )
105 .expect("Unable to write platformVersion file");
106 }
107
108 let mut x = crate::client::VoiceIt2::new(
109 std::env::var("VIAPIKEY").unwrap(),
110 std::env::var("VIAPITOKEN").unwrap(),
111 );
112
113 let result: crate::structs::users::GetAllUsersReturn = match &x.get_all_users() {
114 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
115 Err(err) => {
116 panic!("Panic error: {:?}", err);
117 }
118 };
119
120 assert_eq!(result.status, 200);
121 assert_eq!(result.responseCode, "SUCC");
122
123 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
124 Ok(x) => serde_json::from_str(&x).expect(&x),
125 Err(err) => {
126 panic!("Panic error: {:?}", err);
127 }
128 };
129
130 assert_eq!(result.status, 201);
131 let user_id = result.userId;
132 assert!(crate::is_user_id(&user_id));
133 assert_eq!(result.responseCode, "SUCC");
134
135 let result: crate::structs::users::CheckUserExistsReturn = match &x.check_user_exists(&user_id) {
136 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
137 Err(err) => {
138 panic!("Panic error: {:?}", err);
139 }
140 };
141
142 assert_eq!(result.status, 200);
143 assert_eq!(result.exists, true);
144 assert_eq!(result.responseCode, "SUCC");
145
146 let result: crate::structs::groups::CreateGroupReturn = match &x.create_group("sample group") {
147 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
148 Err(err) => {
149 panic!("Panic error: {:?}", err);
150 }
151 };
152
153 assert_eq!(result.status, 201);
154 let group_id = result.groupId;
155 assert!(crate::is_group_id(&group_id));
156 assert_eq!(result.responseCode, "SUCC");
157
158 let result: crate::structs::groups::GetAllGroupsReturn = match &x.get_all_groups() {
159 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
160 Err(err) => {
161 panic!("Panic error: {:?}", err);
162 }
163 };
164
165 assert_eq!(result.status, 200);
166 assert_eq!(result.responseCode, "SUCC");
167
168 let result: crate::structs::groups::GetGroupReturn = match &x.get_group(&group_id) {
169 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
170 Err(err) => {
171 panic!("Panic error: {:?}", err);
172 }
173 };
174
175 assert_eq!(result.status, 200);
176 assert_eq!(result.responseCode, "SUCC");
177
178 let result: crate::structs::groups::CheckGroupExistsReturn = match &x.check_group_exists(&group_id) {
179 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
180 Err(err) => {
181 panic!("Panic error: {:?}", err);
182 }
183 };
184
185 assert_eq!(result.status, 200);
186 assert_eq!(result.responseCode, "SUCC");
187
188 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id) {
189 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
190 Err(err) => {
191 panic!("Panic error: {:?}", err);
192 }
193 };
194
195 assert_eq!(result.status, 200);
196 assert_eq!(result.responseCode, "SUCC");
197
198 let result: crate::structs::users::GetGroupsForUserReturn = match &x.get_groups_for_user(&user_id) {
199 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
200 Err(err) => {
201 panic!("Panic error: {:?}", err);
202 }
203 };
204
205 assert_eq!(result.status, 200);
206 assert_eq!(result.responseCode, "SUCC");
207 assert_eq!(result.groups[0], group_id);
208
209 let result: crate::structs::groups::RemoveUserFromGroupReturn = match &x.remove_user_from_group(&group_id, &user_id) {
210 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
211 Err(err) => {
212 panic!("Panic error: {:?}", err);
213 }
214 };
215
216 assert_eq!(result.status, 200);
217 assert_eq!(result.responseCode, "SUCC");
218
219 let result: crate::structs::users::CreateUserTokenReturn = match &x.create_user_token(&user_id, 100000) {
220 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
221 Err(err) => {
222 panic!("Panic error: {:?}", err);
223 }
224 };
225
226 assert_eq!(result.status, 201);
227 let user_token = result.userToken;
228 assert!(crate::is_user_token(&user_token));
229 assert_eq!(result.responseCode, "SUCC");
230
231 let result: crate::structs::users::ExpireUserTokensReturn = match &x.expire_user_tokens(&user_id) {
232 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
233 Err(err) => {
234 panic!("Panic error: {:?}", err);
235 }
236 };
237
238 assert_eq!(result.status, 201);
239 assert_eq!(result.responseCode, "SUCC");
240
241 let result: crate::structs::users::DeleteUserReturn = match &x.delete_user(&user_id) {
242 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
243 Err(err) => {
244 panic!("Panic error: {:?}", err);
245 }
246 };
247
248 assert_eq!(result.status, 200);
249 assert_eq!(result.responseCode, "SUCC");
250
251 let result: crate::structs::groups::DeleteGroupReturn = match &x.delete_group(&group_id) {
252 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
253 Err(err) => {
254 panic!("Panic error: {:?}", err);
255 }
256 };
257
258 assert_eq!(result.status, 200);
259 assert_eq!(result.responseCode, "SUCC");
260
261 let result: crate::structs::phrases::GetPhrasesReturn = match &x.get_phrases("en-US") {
262 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
263 Err(err) => {
264 panic!("Panic error: {:?}", err);
265 }
266 };
267
268 assert_eq!(result.status, 200);
269 assert_eq!(result.responseCode, "SUCC");
270
271 &x.add_notification_url("https://voiceit.io");
272 assert_eq!(
273 &x.get_base_url(),
274 "https://api.voiceit.io?notificationURL=https%3A%2F%2Fvoiceit.io"
275 );
276 &x.remove_notification_url();
277 assert_eq!(&x.get_base_url(), "https://api.voiceit.io");
278 }
279
280 #[test]
281 fn test_subaccounts() {
282 let env = std::env::var("BOXFUSE_ENV").unwrap();
283 if env == "voiceittest" {
284 let home_dir = std::env::var("HOME").unwrap();
285 std::fs::write(
286 format!("{}/platformVersion", home_dir),
287 crate::client::PLATFORM_VERSION,
288 )
289 .expect("Unable to write platformVersion file");
290 }
291
292 let x = crate::client::VoiceIt2::new(
293 std::env::var("VIAPIKEY").unwrap(),
294 std::env::var("VIAPITOKEN").unwrap(),
295 );
296
297 let result: crate::structs::subaccounts::CreateSubAccountReturn =
298 match &x.create_managed_sub_account("test", "rust", "", "", "") {
299 Ok(x) => serde_json::from_str(&x).expect(&x),
300 Err(err) => {
301 panic!("Panic error: {:?}", err);
302 }
303 };
304
305 assert_eq!(result.status, 201);
306 let sub_account_managed_api_key = result.apiKey;
307 assert!(crate::is_api_key(&sub_account_managed_api_key));
308 assert_eq!(result.responseCode, "SUCC");
309
310 let result: crate::structs::subaccounts::CreateSubAccountReturn =
311 match &x.create_unmanaged_sub_account("test", "rust", "", "", "") {
312 Ok(x) => serde_json::from_str(&x).expect(&x),
313 Err(err) => {
314 panic!("Panic error: {:?}", err);
315 }
316 };
317
318 assert_eq!(result.status, 201);
319 let sub_account_unmanaged_api_key = result.apiKey;
320 assert!(crate::is_api_key(&sub_account_unmanaged_api_key));
321 assert_eq!(result.responseCode, "SUCC");
322
323 let result: crate::structs::subaccounts::SwitchSubAccountTypeReturn =
324 match &x.switch_sub_account_type(&sub_account_unmanaged_api_key) {
325 Ok(x) => serde_json::from_str(&x).expect(&x),
326 Err(err) => {
327 panic!("Panic error: {:?}", err);
328 }
329 };
330
331 assert_eq!(result.status, 200);
332 assert_eq!(result.responseCode, "SUCC");
333
334 let result: crate::structs::subaccounts::RegenerateSubAccountAPITokenReturn =
335 match &x.regenerate_sub_account_api_token(&sub_account_managed_api_key) {
336 Ok(x) => serde_json::from_str(&x).expect(&x),
337 Err(err) => {
338 panic!("Panic error: {:?}", err);
339 }
340 };
341
342 assert_eq!(result.status, 200);
343 assert_eq!(result.responseCode, "SUCC");
344
345 let result: crate::structs::subaccounts::DeleteSubAccountReturn =
346 match &x.delete_subaccount(&sub_account_managed_api_key) {
347 Ok(x) => serde_json::from_str(&x).expect(&x),
348 Err(err) => {
349 panic!("Panic error: {:?}", err);
350 }
351 };
352
353 assert_eq!(result.status, 200);
354 assert_eq!(result.responseCode, "SUCC");
355
356 let result: crate::structs::subaccounts::DeleteSubAccountReturn =
357 match &x.delete_subaccount(&sub_account_unmanaged_api_key) {
358 Ok(x) => serde_json::from_str(&x).expect(&x),
359 Err(err) => {
360 panic!("Panic error: {:?}", err);
361 }
362 };
363
364 assert_eq!(result.status, 200);
365 assert_eq!(result.responseCode, "SUCC");
366 }
367
368 #[test]
369 fn test_io() {
370 println!("To be filled out later");
371 }
372
373 #[test]
374 fn test_voice() {
375 crate::download_file("https://drive.voiceit.io/files/enrollmentA1.wav").unwrap();
376 crate::download_file("https://drive.voiceit.io/files/enrollmentA2.wav").unwrap();
377 crate::download_file("https://drive.voiceit.io/files/enrollmentA3.wav").unwrap();
378 crate::download_file("https://drive.voiceit.io/files/verificationA1.wav").unwrap();
379
380 let pwd = std::env::var("PWD").unwrap();
381 let x = crate::client::VoiceIt2::new(
382 std::env::var("VIAPIKEY").unwrap(),
383 std::env::var("VIAPITOKEN").unwrap(),
384 );
385
386 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
387 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
388 Err(err) => {
389 panic!("Panic error: {:?}", err);
390 }
391 };
392
393 assert_eq!(result.status, 201);
394 let user_id1 = result.userId;
395 assert_eq!(result.responseCode, "SUCC");
396
397 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
398 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
399 Err(err) => {
400 panic!("Panic error: {:?}", err);
401 }
402 };
403
404 assert_eq!(result.status, 201);
405 let user_id2 = result.userId;
406 assert_eq!(result.responseCode, "SUCC");
407
408 let result: crate::structs::groups::CreateGroupReturn = match &x.create_group("example group") {
409 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
410 Err(err) => {
411 panic!("Panic error: {:?}", err);
412 }
413 };
414
415 assert_eq!(result.status, 201);
416 let group_id = result.groupId;
417 assert_eq!(result.responseCode, "SUCC");
418
419 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id1) {
420 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
421 Err(err) => {
422 panic!("Panic error: {:?}", err);
423 }
424 };
425
426 assert_eq!(result.status, 200);
427 assert_eq!(result.responseCode, "SUCC");
428
429 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id2) {
430 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
431 Err(err) => {
432 panic!("Panic error: {:?}", err);
433 }
434 };
435
436 assert_eq!(result.status, 200);
437 assert_eq!(result.responseCode, "SUCC");
438
439 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/enrollmentA1.wav", &pwd).as_str()) {
440 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
441 Err(err) => {
442 panic!("Panic error: {:?}", err);
443 }
444 };
445
446 assert_eq!(result.status, 201);
447 assert_eq!(result.responseCode, "SUCC");
448
449 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/enrollmentA2.wav", &pwd).as_str()) {
450 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
451 Err(err) => {
452 panic!("Panic error: {:?}", err);
453 }
454 };
455
456 assert_eq!(result.status, 201);
457 assert_eq!(result.responseCode, "SUCC");
458
459 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/enrollmentA3.wav", &pwd).as_str()) {
460 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
461 Err(err) => {
462 panic!("Panic error: {:?}", err);
463 }
464 };
465
466 assert_eq!(result.status, 201);
467 assert_eq!(result.responseCode, "SUCC");
468
469 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/enrollmentC1.wav") {
470 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
471 Err(err) => {
472 panic!("Panic error: {:?}", err);
473 }
474 };
475
476 assert_eq!(result.status, 201);
477 assert_eq!(result.responseCode, "SUCC");
478
479 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/enrollmentC2.wav") {
480 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
481 Err(err) => {
482 panic!("Panic error: {:?}", err);
483 }
484 };
485
486 assert_eq!(result.status, 201);
487 assert_eq!(result.responseCode, "SUCC");
488
489 let result: crate::structs::enrollments::CreateVoiceEnrollmentReturn = match &x.create_voice_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/enrollmentC3.wav") {
490 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
491 Err(err) => {
492 panic!("Panic error: {:?}", err);
493 }
494 };
495
496 assert_eq!(result.status, 201);
497 assert_eq!(result.responseCode, "SUCC");
498
499 let result: crate::structs::enrollments::GetAllVoiceEnrollmentsReturn = match &x.get_all_voice_enrollments(&user_id1) {
500 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
501 Err(err) => {
502 panic!("Panic error: {:?}", err);
503 }
504 };
505
506 assert_eq!(result.status, 200);
507 assert_eq!(result.responseCode, "SUCC");
508
509 let result: crate::structs::verification::VoiceVerificationReturn = match &x.voice_verification(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/verificationA1.wav", &pwd).as_str()) {
510 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
511 Err(err) => {
512 panic!("Panic error: {:?}", err);
513 }
514 };
515
516 assert_eq!(result.status, 200);
517 assert_eq!(result.responseCode, "SUCC");
518
519 let result: crate::structs::verification::VoiceVerificationReturn = match &x.voice_verification_by_url(&user_id1, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/enrollmentA4.wav") {
520 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
521 Err(err) => {
522 panic!("Panic error: {:?}", err);
523 }
524 };
525
526 assert_eq!(result.status, 200);
527 assert_eq!(result.responseCode, "SUCC");
528
529 let result: crate::structs::identification::VoiceIdentificationReturn = match &x.voice_identification(&group_id, "en-US", "never forget tomorrow is a new day", format!("{}/verificationA1.wav", &pwd).as_str()) {
530 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
531 Err(err) => {
532 panic!("Panic error: {:?}", err);
533 }
534 };
535
536 assert_eq!(result.status, 200);
537 assert_eq!(result.userId, user_id1);
538 assert_eq!(result.responseCode, "SUCC");
539
540 let result: crate::structs::identification::VoiceIdentificationReturn = match &x.voice_identification_by_url(&group_id, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/enrollmentA4.wav") {
541 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
542 Err(err) => {
543 panic!("Panic error: {:?}", err);
544 }
545 };
546
547 assert_eq!(result.status, 200);
548 assert_eq!(result.userId, user_id1);
549 assert_eq!(result.responseCode, "SUCC");
550
551 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id1) {
552 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
553 Err(err) => {
554 panic!("Panic error: {:?}", err);
555 }
556 };
557
558 assert_eq!(result.status, 200);
559 assert_eq!(result.responseCode, "SUCC");
560
561 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id2) {
562 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
563 Err(err) => {
564 panic!("Panic error: {:?}", err);
565 }
566 };
567
568 assert_eq!(result.status, 200);
569 assert_eq!(result.responseCode, "SUCC");
570
571 &x.delete_user(&user_id1).unwrap();
572 &x.delete_user(&user_id2).unwrap();
573 &x.delete_group(&group_id).unwrap();
574
575 std::fs::remove_file(format!("{}/{}", &pwd, "enrollmentA1.wav"))
576 .expect("Unable to delete file");
577 std::fs::remove_file(format!("{}/{}", &pwd, "enrollmentA2.wav"))
578 .expect("Unable to delete file");
579 std::fs::remove_file(format!("{}/{}", &pwd, "enrollmentA3.wav"))
580 .expect("Unable to delete file");
581 std::fs::remove_file(format!("{}/{}", &pwd, "verificationA1.wav"))
582 .expect("Unable to delete file");
583 }
584
585 #[test]
586 fn test_face() {
587 crate::download_file("https://drive.voiceit.io/files/faceEnrollmentB1.mp4").unwrap();
588 crate::download_file("https://drive.voiceit.io/files/faceEnrollmentB2.mp4").unwrap();
589 crate::download_file("https://drive.voiceit.io/files/faceEnrollmentB3.mp4").unwrap();
590 crate::download_file("https://drive.voiceit.io/files/faceVerificationB1.mp4").unwrap();
591
592 let pwd = std::env::var("PWD").unwrap();
593
594 let x = crate::client::VoiceIt2::new(
595 std::env::var("VIAPIKEY").unwrap(),
596 std::env::var("VIAPITOKEN").unwrap(),
597 );
598
599 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
600 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
601 Err(err) => {
602 panic!("Panic error: {:?}", err);
603 }
604 };
605
606 assert_eq!(result.status, 201);
607 let user_id1 = result.userId;
608 assert_eq!(result.responseCode, "SUCC");
609
610 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
611 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
612 Err(err) => {
613 panic!("Panic error: {:?}", err);
614 }
615 };
616
617 assert_eq!(result.status, 201);
618 let user_id2 = result.userId;
619 assert_eq!(result.responseCode, "SUCC");
620
621 let result: crate::structs::groups::CreateGroupReturn = match &x.create_group("example group") {
622 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
623 Err(err) => {
624 panic!("Panic error: {:?}", err);
625 }
626 };
627
628 assert_eq!(result.status, 201);
629 let group_id = result.groupId;
630 assert_eq!(result.responseCode, "SUCC");
631
632 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id1) {
633 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
634 Err(err) => {
635 panic!("Panic error: {:?}", err);
636 }
637 };
638
639 assert_eq!(result.status, 200);
640 assert_eq!(result.responseCode, "SUCC");
641
642 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id2) {
643 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
644 Err(err) => {
645 panic!("Panic error: {:?}", err);
646 }
647 };
648
649 assert_eq!(result.status, 200);
650 assert_eq!(result.responseCode, "SUCC");
651
652 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment(&user_id1, format!("{}/faceEnrollmentB1.mp4", &pwd).as_str()) {
653 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
654 Err(err) => {
655 panic!("Panic error: {:?}", err);
656 }
657 };
658
659 assert_eq!(result.status, 201);
660 assert_eq!(result.responseCode, "SUCC");
661
662 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment(&user_id1, format!("{}/faceEnrollmentB2.mp4", &pwd).as_str()) {
663 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
664 Err(err) => {
665 panic!("Panic error: {:?}", err);
666 }
667 };
668
669 assert_eq!(result.status, 201);
670 assert_eq!(result.responseCode, "SUCC");
671
672 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment(&user_id1, format!("{}/faceEnrollmentB3.mp4", &pwd).as_str()) {
673 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
674 Err(err) => {
675 panic!("Panic error: {:?}", err);
676 }
677 };
678
679 assert_eq!(result.status, 201);
680 assert_eq!(result.responseCode, "SUCC");
681
682 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment_by_url(&user_id2, "https://drive.voiceit.io/files/videoEnrollmentC1.mov") {
683 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
684 Err(err) => {
685 panic!("Panic error: {:?}", err);
686 }
687 };
688
689 assert_eq!(result.status, 201);
690 assert_eq!(result.responseCode, "SUCC");
691
692 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment_by_url(&user_id2, "https://drive.voiceit.io/files/videoEnrollmentC2.mov") {
693 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
694 Err(err) => {
695 panic!("Panic error: {:?}", err);
696 }
697 };
698
699 assert_eq!(result.status, 201);
700 assert_eq!(result.responseCode, "SUCC");
701
702 let result: crate::structs::enrollments::CreateFaceEnrollmentReturn = match &x.create_face_enrollment_by_url(&user_id2, "https://drive.voiceit.io/files/videoEnrollmentC3.mov") {
703 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
704 Err(err) => {
705 panic!("Panic error: {:?}", err);
706 }
707 };
708
709 assert_eq!(result.status, 201);
710 assert_eq!(result.responseCode, "SUCC");
711
712 let result: crate::structs::enrollments::GetAllFaceEnrollmentsReturn = match &x.get_all_face_enrollments(&user_id1) {
713 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
714 Err(err) => {
715 panic!("Panic error: {:?}", err);
716 }
717 };
718
719 assert_eq!(result.status, 200);
720 assert_eq!(result.responseCode, "SUCC");
721
722 let result: crate::structs::verification::FaceVerificationReturn = match &x.face_verification(&user_id1, format!("{}/faceVerificationB1.mp4", &pwd).as_str()) {
723 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
724 Err(err) => {
725 panic!("Panic error: {:?}", err);
726 }
727 };
728
729 assert_eq!(result.status, 200);
730 assert_eq!(result.responseCode, "SUCC");
731
732 let result: crate::structs::verification::FaceVerificationReturn = match &x.face_verification_by_url(&user_id1, "https://drive.voiceit.io/files/faceVerificationB1.mp4") {
733 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
734 Err(err) => {
735 panic!("Panic error: {:?}", err);
736 }
737 };
738
739 assert_eq!(result.status, 200);
740 assert_eq!(result.responseCode, "SUCC");
741
742 let result: crate::structs::identification::FaceIdentificationReturn = match &x.face_identification(&group_id, format!("{}/faceVerificationB1.mp4", &pwd).as_str()) {
743 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
744 Err(err) => {
745 panic!("Panic error: {:?}", err);
746 }
747 };
748
749 assert_eq!(result.status, 200);
750 assert_eq!(result.userId, user_id1);
751 assert_eq!(result.responseCode, "SUCC");
752
753 let result: crate::structs::identification::FaceIdentificationReturn = match &x.face_identification_by_url(&group_id, "https://drive.voiceit.io/files/faceVerificationB1.mp4") {
754 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
755 Err(err) => {
756 panic!("Panic error: {:?}", err);
757 }
758 };
759
760 assert_eq!(result.status, 200);
761 assert_eq!(result.userId, user_id1);
762 assert_eq!(result.responseCode, "SUCC");
763
764 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id1) {
765 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
766 Err(err) => {
767 panic!("Panic error: {:?}", err);
768 }
769 };
770
771 assert_eq!(result.status, 200);
772 assert_eq!(result.responseCode, "SUCC");
773
774 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id2) {
775 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
776 Err(err) => {
777 panic!("Panic error: {:?}", err);
778 }
779 };
780
781 assert_eq!(result.status, 200);
782 assert_eq!(result.responseCode, "SUCC");
783
784 std::fs::remove_file(format!("{}/{}", &pwd, "faceEnrollmentB1.mp4"))
785 .expect("Unable to delete file");
786 std::fs::remove_file(format!("{}/{}", &pwd, "faceEnrollmentB2.mp4"))
787 .expect("Unable to delete file");
788 std::fs::remove_file(format!("{}/{}", &pwd, "faceEnrollmentB3.mp4"))
789 .expect("Unable to delete file");
790 std::fs::remove_file(format!("{}/{}", &pwd, "faceVerificationB1.mp4"))
791 .expect("Unable to delete file");
792 }
793
794 #[test]
795 fn test_video() {
796 crate::download_file("https://drive.voiceit.io/files/videoEnrollmentB1.mov").unwrap();
797 crate::download_file("https://drive.voiceit.io/files/videoEnrollmentB2.mov").unwrap();
798 crate::download_file("https://drive.voiceit.io/files/videoEnrollmentB3.mov").unwrap();
799 crate::download_file("https://drive.voiceit.io/files/videoVerificationB1.mov").unwrap();
800
801 let pwd = std::env::var("PWD").unwrap();
802
803 let x = crate::client::VoiceIt2::new(
804 std::env::var("VIAPIKEY").unwrap(),
805 std::env::var("VIAPITOKEN").unwrap(),
806 );
807
808 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
809 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
810 Err(err) => {
811 panic!("Panic error: {:?}", err);
812 }
813 };
814
815 assert_eq!(result.status, 201);
816 let user_id1 = result.userId;
817 assert_eq!(result.responseCode, "SUCC");
818
819 let result: crate::structs::users::CreateUserReturn = match &x.create_user() {
820 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
821 Err(err) => {
822 panic!("Panic error: {:?}", err);
823 }
824 };
825
826 assert_eq!(result.status, 201);
827 let user_id2 = result.userId;
828 assert_eq!(result.responseCode, "SUCC");
829
830 let result: crate::structs::groups::CreateGroupReturn = match &x.create_group("example group") {
831 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
832 Err(err) => {
833 panic!("Panic error: {:?}", err);
834 }
835 };
836
837 assert_eq!(result.status, 201);
838 let group_id = result.groupId;
839 assert_eq!(result.responseCode, "SUCC");
840
841 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id1) {
842 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
843 Err(err) => {
844 panic!("Panic error: {:?}", err);
845 }
846 };
847
848 assert_eq!(result.status, 200);
849 assert_eq!(result.responseCode, "SUCC");
850
851 let result: crate::structs::groups::AddUserToGroupReturn = match &x.add_user_to_group(&group_id, &user_id2) {
852 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
853 Err(err) => {
854 panic!("Panic error: {:?}", err);
855 }
856 };
857
858 assert_eq!(result.status, 200);
859 assert_eq!(result.responseCode, "SUCC");
860
861 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/videoEnrollmentB1.mov", &pwd).as_str()) {
862 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
863 Err(err) => {
864 panic!("Panic error: {:?}", err);
865 }
866 };
867
868 assert_eq!(result.status, 201);
869 assert_eq!(result.responseCode, "SUCC");
870
871 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/videoEnrollmentB2.mov", &pwd).as_str()) {
872 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
873 Err(err) => {
874 panic!("Panic error: {:?}", err);
875 }
876 };
877
878 assert_eq!(result.status, 201);
879 assert_eq!(result.responseCode, "SUCC");
880
881 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/videoEnrollmentB3.mov", &pwd).as_str()) {
882 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
883 Err(err) => {
884 panic!("Panic error: {:?}", err);
885 }
886 };
887
888 assert_eq!(result.status, 201);
889 assert_eq!(result.responseCode, "SUCC");
890
891 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/videoEnrollmentC1.mov") {
892 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
893 Err(err) => {
894 panic!("Panic error: {:?}", err);
895 }
896 };
897
898 assert_eq!(result.status, 201);
899 assert_eq!(result.responseCode, "SUCC");
900
901 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/videoEnrollmentC2.mov") {
902 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
903 Err(err) => {
904 panic!("Panic error: {:?}", err);
905 }
906 };
907
908 assert_eq!(result.status, 201);
909 assert_eq!(result.responseCode, "SUCC");
910
911 let result: crate::structs::enrollments::CreateVideoEnrollmentReturn = match &x.create_video_enrollment_by_url(&user_id2, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/videoEnrollmentC3.mov") {
912 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
913 Err(err) => {
914 panic!("Panic error: {:?}", err);
915 }
916 };
917
918 assert_eq!(result.status, 201);
919 assert_eq!(result.responseCode, "SUCC");
920
921 let result: crate::structs::enrollments::GetAllVideoEnrollmentsReturn = match &x.get_all_video_enrollments(&user_id1) {
922 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
923 Err(err) => {
924 panic!("Panic error: {:?}", err);
925 }
926 };
927
928 assert_eq!(result.status, 200);
929 assert_eq!(result.responseCode, "SUCC");
930
931 let result: crate::structs::verification::VideoVerificationReturn = match &x.video_verification(&user_id1, "en-US", "never forget tomorrow is a new day", format!("{}/videoVerificationB1.mov", &pwd).as_str()) {
932 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
933 Err(err) => {
934 panic!("Panic error: {:?}", err);
935 }
936 };
937
938 assert_eq!(result.status, 200);
939 assert_eq!(result.responseCode, "SUCC");
940
941 let result: crate::structs::verification::VideoVerificationReturn = match &x.video_verification_by_url(&user_id1, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/videoVerificationB1.mov") {
942 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
943 Err(err) => {
944 panic!("Panic error: {:?}", err);
945 }
946 };
947
948 assert_eq!(result.status, 200);
949 assert_eq!(result.responseCode, "SUCC");
950
951 let result: crate::structs::identification::VideoIdentificationReturn = match &x.video_identification(&group_id, "en-US", "never forget tomorrow is a new day", format!("{}/videoVerificationB1.mov", &pwd).as_str()) {
952 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
953 Err(err) => {
954 panic!("Panic error: {:?}", err);
955 }
956 };
957
958 assert_eq!(result.status, 200);
959 assert_eq!(result.userId, user_id1);
960 assert_eq!(result.responseCode, "SUCC");
961
962 let result: crate::structs::identification::VideoIdentificationReturn = match &x.video_identification_by_url(&group_id, "en-US", "never forget tomorrow is a new day", "https://drive.voiceit.io/files/videoVerificationB1.mov") {
963 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
964 Err(err) => {
965 panic!("Panic error: {:?}", err);
966 }
967 };
968
969 assert_eq!(result.status, 200);
970 assert_eq!(result.userId, user_id1);
971 assert_eq!(result.responseCode, "SUCC");
972
973 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id1) {
974 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
975 Err(err) => {
976 panic!("Panic error: {:?}", err);
977 }
978 };
979
980 assert_eq!(result.status, 200);
981 assert_eq!(result.responseCode, "SUCC");
982
983 let result: crate::structs::enrollments::DeleteAllEnrollmentsReturn = match &x.delete_all_enrollments(&user_id2) {
984 Ok(x) => serde_json::from_str(&x).expect(format!("Unable to unmarshal JSON properly due to call failing and returning with missing values. server response: {}", &x).as_str()),
985 Err(err) => {
986 panic!("Panic error: {:?}", err);
987 }
988 };
989
990 assert_eq!(result.status, 200);
991 assert_eq!(result.responseCode, "SUCC");
992
993 std::fs::remove_file(format!("{}/{}", &pwd, "videoEnrollmentB1.mov"))
994 .expect("Unable to delete file");
995 std::fs::remove_file(format!("{}/{}", &pwd, "videoEnrollmentB2.mov"))
996 .expect("Unable to delete file");
997 std::fs::remove_file(format!("{}/{}", &pwd, "videoEnrollmentB3.mov"))
998 .expect("Unable to delete file");
999 std::fs::remove_file(format!("{}/{}", &pwd, "videoVerificationB1.mov"))
1000 .expect("Unable to delete file");
1001 }
1002}