interactive_set_access_codes/
interactive_set_access_codes.rs

1use seamapi_rs::Seam;
2use std::io;
3
4fn main() {
5    println!("This will reset your workspace sandbox, continure? (Y/n)");
6    let mut guess = String::new();
7    io::stdin()
8        .read_line(&mut guess)
9        .expect("failed to read line");
10
11    println!("{guess}");
12    if guess != "Y\n" {
13        panic!();
14    }
15
16    let seam = Seam::new(None, None).unwrap();
17
18    println!("Reseting sandbox...");
19    seam.workspace().reset_sandbox();
20
21    println!("creating a Connect Webview...");
22    let webview = seam
23        .connect_webviews()
24        .create(vec!["august".to_string()], None, None)
25        .unwrap();
26
27    println!("This is my webview: \n{:?}", webview);
28
29    println!(
30        "Got the URL below and login\n\n{}\n\njane@example.com\n123\n\n",
31        webview.url
32    );
33
34    let mut enter = String::new();
35    io::stdin()
36        .read_line(&mut enter)
37        .expect("failed to read line");
38
39    let updated_webview = seam
40        .connect_webviews()
41        .get(webview.connect_webview_id)
42        .unwrap();
43
44    print!("This is my updated webview: \n {:?}", updated_webview);
45
46    if updated_webview.login_successful {
47        println!("Successfully logged in!");
48    } else {
49        panic!("Webview wasn't logged in");
50    }
51
52    let locks = seam.locks().list().unwrap();
53    println!(
54        "Listing all the connected locks for our new account: {:?}",
55        locks
56    );
57
58    let mut front_door = String::new();
59    for lock in locks {
60        if lock.properties.august_metadata.unwrap().device_name == "FRONT DOOR" {
61            front_door = lock.device_id;
62        }
63    }
64
65    println!("Settings the code 123459 on FRONT DOOR");
66    seam.access_codes()
67        .create(
68            front_door.clone(),
69            Some("My personal entry code".to_string()),
70            Some("123459".to_string()),
71            None,
72            None,
73        )
74        .unwrap();
75
76    let all_access_codes_on_front_door = seam.access_codes().list(front_door.clone()).unwrap();
77    println!("{:?}", all_access_codes_on_front_door);
78}