1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use anyhow::Context;

mod model;
pub use model::*;

pub async fn get_front_page(city: &str) -> anyhow::Result<Page> {
    let url = format!("https://restaurant-api.wolt.com/v1/pages/front/{}", city);
    Ok(reqwest::get(url).await?.json().await?)
}

pub async fn get_delivery_page(lat: f64, lon: f64) -> anyhow::Result<Page> {
    let url = format!(
        "https://restaurant-api.wolt.com/v1/pages/delivery?lat={}&lon={}",
        lat, lon
    );
    Ok(reqwest::get(url).await?.json().await?)
}

pub async fn get_menu(oid: &str) -> anyhow::Result<MenuResults> {
    let url = format!("https://restaurant-api.wolt.com/v3/menus/{}", oid);
    Ok(reqwest::get(url).await?.json().await?)
}

pub async fn get_venue(id: &str) -> anyhow::Result<VenueResults> {
    let url = format!("https://restaurant-api.wolt.com/v3/venues/{}", id);
    Ok(reqwest::get(url)
        .await
        .context("failed to fetch venue")?
        .json()
        .await
        .context("failed to parse venue")?)
}

pub async fn get_venue_estimates(id: &str) -> anyhow::Result<EstimateResults> {
    let url = format!("https://restaurant-api.wolt.com/v1/venues/{}/estimates", id);
    Ok(reqwest::Client::new()
        .post(url)
        .json(&std::collections::HashMap::<String, String>::new())
        .send()
        .await
        .context("failed to fetch venue estimates")?
        .json()
        .await
        .context("failed to parse venue estimates")?)
}