Expand description
GrabFood: a typed API over grabcli_core::Context.
Every function takes a &mut Context and returns plain structs; nothing
here reads config files, picks paths or prints. Carts are values the
caller keeps (Cart); the grab CLI stores them as JSON files, a
daemon can keep them anywhere.
- Browse:
browse::search,browse::nearby,browse::recommended,browse::cuisines,browse::category,menu(). - Cart:
cart_add,cart_remove(plusCart’s own fields). - Checkout:
quote(),vouchers,best_voucher,prepare_order,submit_order,place_order. - After:
orders,track,history().
Build a context with context, which registers the GrabFood URL
allowlist (the order endpoint only when allow_ordering is set) and
turns the response cache off; browse callers opt back in with
Context::set_cache_mode. The cart → quote → order path never reads
the cache.
§Example: read a merchant menu
use grabfood::{menu, MenuSource};
let menu = menu(ctx, "merchant-id", MenuSource::Live).await?;
println!("{}", menu.name);Create ctx with context using your configuration, session store, and cache.
Reading a menu makes a network request but places no order. Use real merchant
IDs returned by browse calls. cart_add validates cart IDs against the menu;
quote() fetches current prices before checkout.
Re-exports§
pub use cart::Cart;pub use cart::CartItem;pub use cart::CartModifier;pub use menu::Menu;pub use quote::Quote;pub use tracking::Tracking;
Modules§
- api
- GrabFood endpoint URLs and the URL allowlist.
- browse
- Discovery:
search,nearby,recommended,cuisinesandcategory, each returning a typedListing(printing is the CLI’s). Lists are fetched page by page through the response cache (paced, stopping cleanly on a 429), indexed into the local catalog, then filtered/sorted client-side. If the live call fails, results fall back to the last stored response or the local catalog, marked with their age. - cart
- A GrabFood cart: one merchant at a time, validated against the live menu
before quoting. The library passes carts by value; where one is kept is
the caller’s choice (the
grabCLI stores<state>/food/cart.json). - datetime
- Tiny UTC→PHT (UTC+8) date math, no external date crate.
- discover
- Discovery lists: parsing
/search,/categoryand/recommended/merchantsresponses intoMerchants (with any dish hits), plus the client-side filters and sorting the upstream lacks (see docs/discovery.md). - history
grab food history sync --vault <dir>: export completed GrabFood orders to a Markdown/Obsidian vault, idempotently.- index
- Mapping GrabFood responses into the core catalog (restaurants, sightings,
menu categories, items) and catalog rows back into
Merchants for--localresults. Indexing is best-effort: callers ignore its errors. - menu
- Menu parsing: categories, items, modifier groups, merchant hours/ETA and the offer carousel.
- order
- Order submission — gated, and disabled by default.
- quote
- Price quotes via
POST /order/cart. - tracking
- A stable, versioned view of a live order, combined from the track and detail endpoints.
Structs§
- Added
- What
cart_addadded. - Best
Voucher - The cheapest voucher for a cart.
- Order
Summary - One order in the order list.
- Placed
- A placed order.
- Prepared
Order - A fresh quote and the exact order body that would be submitted for it.
- Voucher
List - Eligible voucher codes for a cart, with the base (no-voucher) quote.
- Voucher
Try - One code tried by
best_voucher: its total, orNoneif the quote with it failed.
Enums§
- Menu
Source - Where a menu may come from.
Constants§
- CACHE_
NS - Cache namespace for GrabFood entries.
- MAX_
MENU_ IMAGES - Most item images
download_menu_imagesfetches per call.
Functions§
- best_
voucher - Re-quote
cartwith each eligible code (sequentially, ~1.2s apart) and pick the lowest total. To use it, setcart.voucher = best.best_code. - cart_
add - Add an item to
cart, validating the ids against the merchant’s menu.modsareGROUP_ID:OPTION_IDchoices. A cached menu (≤ menu TTL) is fine here: the cart only stores ids, andquote()re-validates against a live menu before any price is shown. - cart_
remove - Remove every line with
item_idfromcart. Errors if there was none. - context
- A GrabFood context:
Context::newplus the GrabFood allowlist, with the cache off (cart/quote/voucher/order/tracking/history always talk to Grab live). Browse callers may thenContext::set_cache_mode. - download_
menu_ images - Download up to
MAX_MENU_IMAGESitem images into the image cache, one request at a time. Returns how many failed. - ensure_
ordering_ enabled - The
ordering_disablederror (with the redacted body that would have been sent) unlessallow_orderingis set. - history
- Completed orders, newest first, up to
limitscanned (paged gently). - menu
- A merchant’s menu, modifiers, hours and offers.
- menu_
meta - A menu plus when it was fetched (
cached_atset if it came from the cache). Live fetches through the cache are indexed into the catalog. For browsing only, an expired login falls back to the guest menu endpoint. - orders
- Recent orders (only ongoing ones with
ongoing). - parse_
mods - Parse
GROUP_ID:OPTION_IDmodifier choices against a menu item. - payment_
default - The payment method id used when none is given: config, then session.
- place_
order - Re-quote
cart, and if the fresh quote id equalsquote_id(the one the user approved) and ordering is enabled, submit it once and empty the cart. A mismatch returnsquote_changedand nothing is sent. - prepare_
order - Re-quote
cartlive and build the order body (nothing is sent). Show the quote to the user, then pass their confirmed quote id tosubmit_order. - quote
- Price
cartlive (no order is placed).voucheroverrides the cart’s stored code;paymentoverridespayment_default. The cart is validated against the live menu first. - quote_
json - A quote as the CLI’s
--jsonshape. - submit_
order - Submit a prepared order. Refuses unless
confirmed_quote_idequals the prepared (fresh) quote’s id andallow_orderingis set; both checks run before any request. Never retried: on an ambiguous failure the error says to check ongoing orders. Returns the order id. - track
- One order’s live status: state, driver, ETA, route, items.
- vouchers
- List the voucher codes Grab says are eligible for
cart.