buddy_client 0.0.1

A client for the Prusa Buddy Firmware http api.
Documentation
use std::{thread::sleep, time::Duration};

use dotenvy_macro::dotenv;

use buddy_client::{PrusaClient, responses::V1JobState};

#[tokio::main]
async fn main() {
    let ip = dotenv!("PRUSA_IP");
    let key = dotenv!("PRUSA_KEY");

    let client = PrusaClient::new_async(ip, key, None);

    let version = client.version().await.unwrap();
    println!("{:?}", version);

    // Octo API
    print!("\n[Octo API]\n\n");

    let octo_printer = client.octo_printer().await.unwrap();
    println!("{:?}", octo_printer);

    let octo_job = client.octo_job().await.unwrap();
    println!("{:?}", octo_job);

    // V1 API
    print!("\n[V1 API]\n\n");

    let v1_info = client.v1_info().await.unwrap();
    println!("{:?}", v1_info);

    let v1_status = client.v1_status().await.unwrap();
    println!("{:?}", v1_status);

    let v1_storage = client.v1_storage().await.unwrap();
    println!("{:?}", v1_storage);

    let v1_job = client.v1_get_job().await.unwrap();
    println!("{:?}", v1_job);

    // Submit a gcode file. It is a one line auto home gcode file in this case.
    client
        .v1_put_file("home.gcode", "G28;\n".as_bytes(), true, true)
        .await
        .unwrap();

    loop {
        match client.v1_get_job().await {
            Ok(Some(job)) => {
                println!("{:?}: {}", job.state, job.time_printing);
                if job.state != V1JobState::Printing {
                    break;
                }
            }
            Ok(None) => {
                println!("No Job Present");
                break;
            }
            Err(e) => {
                println!("{e}");
            }
        }
        sleep(Duration::from_secs(1));
    }

    sleep(Duration::from_secs(1));

    let exists = client.v1_is_path("home.gcode").await;
    println!("Path Exists: {:?}", exists);

    if exists.is_ok() {
        let deleted = client.v1_delete_path("home.gcode").await;
        println!("Path Deleted: {:?}", deleted);
    }
}