sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use sellapp::resources::products::ListParams;
use sellapp::{Client, Error};

pub async fn paginate(client: &Client) -> Result<Vec<(i64, String)>, Error> {
    let mut products = Vec::new();
    // Keep this example bounded to three pages, even for a very busy store.
    for page_number in 1..=3 {
        let page = client
            .products()
            .list(ListParams {
                limit: Some(15),
                page: Some(page_number),
                ..Default::default()
            })
            .await?;
        for product in page.data {
            println!("{}: {}", product.id, product.title);
            products.push((product.id, product.title));
        }
        if page.meta.current_page >= page.meta.last_page {
            break;
        }
    }
    Ok(products)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let base_url = std::env::var("SELLAPP_API_BASE_URL")?;
    let client = Client::from_env()?
        .with_base_url(base_url)
        .with_max_retries(0);
    paginate(&client).await?;
    Ok(())
}