use std::fmt::Debug;
use reqwest::{Client, RequestBuilder};
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
#[serde(untagged)]
pub enum Value {
Null,
String(String),
Array(Vec<Cell>),
Struct(Tuple),
}
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Cell {
pub v: Value,
}
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Tuple {
pub f: Vec<Cell>,
}
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct FetchDataRequest {
pub start_index: Option<i32>,
pub max_results: Option<u32>,
pub page_token: Option<String>,
pub selected_fields: Option<String>,
}
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FetchDataResponse {
pub kind: String,
pub etag: String,
#[serde(deserialize_with = "crate::http::from_str")]
pub total_rows: u64,
pub page_token: Option<String>,
pub rows: Option<Vec<Tuple>>,
}
pub fn build(
base_url: &str,
client: &Client,
project_id: &str,
dataset_id: &str,
table_id: &str,
data: &FetchDataRequest,
) -> RequestBuilder {
let url = format!(
"{}/projects/{}/datasets/{}/tables/{}/data",
base_url, project_id, dataset_id, table_id
);
client.get(url).query(&data)
}