podping-api 0.1.0

A library for the Podping API.
Documentation
use std::{thread, time};

use reqwest::Client;

use podping_api::{
    self,
    podping::{
        api::{get_head_block_number, get_operations, get_payloads},
        request::BlockId,
    },
};

#[tokio::main]
async fn main() -> std::io::Result<()> {
    // Create a new client
    let client = Client::new();
    // Get the current head block number
    let mut head_block = get_head_block_number(&client).await.unwrap();
    let mut block = head_block;

    println!("Press ^C to quit.");

    loop {
        println!("Block Number: {:?}", block);
        let operations = get_operations(&client, &BlockId::new(block)).await.unwrap();
        // The filtered operations
        // println!("Operations: {:?}", operations.clone());
        // The payloads of the operations (the Url's)
        let payloads = get_payloads(operations, &BlockId::new(block)).await;
        println!("Payloads: {:?}", payloads.clone());
        block = head_block + 1;
        tracing::warn!("Block advanced!");
        while block > head_block {
            if let Ok(block_response) = get_head_block_number(&client).await {
                head_block = block_response;
            }
            // A new block should be created every 3 seconds
            thread::sleep(time::Duration::from_secs(1));
        }
    }

    // This is unreachable for this example,
    // but sufficient for the general concept
    #[allow(unreachable_code)]
    Ok(())
}