Skip to main content

fake_order/
fake_order.rs

1//! A whole order on the fake backend, no network:
2//! `cargo run -p grabcli-service --example fake_order`.
3//!
4//! Swap `Fake::default()` for `grabcli_service::real::Real::new(config)` and
5//! a slot over your own storage for the real thing.
6
7use std::sync::Arc;
8
9use grabcli_service::fake::Fake;
10use grabcli_service::{CartOp, GrabBackend, GrabResult, MemorySlot, text};
11
12#[tokio::main(flavor = "current_thread")]
13async fn main() -> GrabResult<()> {
14    let backend = Fake::default();
15    let slot = Arc::new(MemorySlot::new("acct-1", Some(Fake::session("Sample"))));
16    let client = backend.client(slot);
17
18    let found = client.search("ramen", 5).await?;
19    println!("{}\n", text::merchants(&found));
20
21    let menu = client.menu("fake-ramen").await?;
22    println!("{}\n", text::menu(&menu, None));
23
24    let cart = client
25        .cart(&CartOp::Add {
26            merchant_id: menu.merchant.id.clone(),
27            item_id: menu.items[0].id.clone(),
28            quantity: 2,
29            note: Some("less salt".into()),
30        })
31        .await?;
32    println!("{}\n", text::cart(&cart));
33
34    let quote = client.quote().await?;
35    println!("{}\n", text::quote(&quote));
36
37    // Only once the person agreed to this quote id; never retried.
38    let placed = client.place_order(&quote.quote_id).await?;
39    println!("placed {}\n", placed.order_id);
40    println!("{}", text::tracked(&client.track(None).await?));
41    Ok(())
42}