use http::Method;
use serde_json::Value;
use crate::{Result, client::RequestOptions, types::path::PathParam};
#[cfg(feature = "blocking")]
use crate::client::BlockingClient;
#[cfg(feature = "async")]
use crate::client::Client;
#[cfg(feature = "async")]
#[derive(Clone)]
pub struct FieldService {
client: Client,
}
#[cfg(feature = "async")]
impl FieldService {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn get_by_id(
&self,
id: impl Into<PathParam>,
query: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str()];
self.client
.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn put_by_id(&self, id: impl Into<PathParam>, body: Option<&Value>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str()];
self.client
.request_json(
Method::PUT,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
.await
}
pub async fn delete_by_id_dimension(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "dimension"];
self.client
.request_json(
Method::DELETE,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn post_by_id_dimension(
&self,
id: impl Into<PathParam>,
body: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "dimension"];
self.client
.request_json(
Method::POST,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
.await
}
pub async fn post_by_id_discard_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "discard_values"];
self.client
.request_json(
Method::POST,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id_related(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "related"];
self.client
.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id_remapping_by_remapped_id(
&self,
id: impl Into<PathParam>,
remapped_id: impl Into<PathParam>,
query: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let remapped_id = remapped_id.into();
let segments = [
"api",
"field",
id.as_str(),
"remapping",
remapped_id.as_str(),
];
self.client
.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn post_by_id_rescan_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "rescan_values"];
self.client
.request_json(
Method::POST,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id_search_by_search_id(
&self,
id: impl Into<PathParam>,
search_id: impl Into<PathParam>,
query: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let search_id = search_id.into();
let segments = ["api", "field", id.as_str(), "search", search_id.as_str()];
self.client
.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id_summary(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "summary"];
self.client
.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn get_by_id_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "values"];
self.client
.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
.await
}
pub async fn post_by_id_values(
&self,
id: impl Into<PathParam>,
body: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "values"];
self.client
.request_json(
Method::POST,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
.await
}
}
#[cfg(feature = "blocking")]
#[derive(Clone)]
pub struct BlockingFieldService {
client: BlockingClient,
}
#[cfg(feature = "blocking")]
impl BlockingFieldService {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn get_by_id(&self, id: impl Into<PathParam>, query: Option<&Value>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str()];
self.client.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn put_by_id(&self, id: impl Into<PathParam>, body: Option<&Value>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str()];
self.client.request_json(
Method::PUT,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
}
pub fn delete_by_id_dimension(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "dimension"];
self.client.request_json(
Method::DELETE,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn post_by_id_dimension(
&self,
id: impl Into<PathParam>,
body: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "dimension"];
self.client.request_json(
Method::POST,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
}
pub fn post_by_id_discard_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "discard_values"];
self.client.request_json(
Method::POST,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id_related(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "related"];
self.client.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id_remapping_by_remapped_id(
&self,
id: impl Into<PathParam>,
remapped_id: impl Into<PathParam>,
query: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let remapped_id = remapped_id.into();
let segments = [
"api",
"field",
id.as_str(),
"remapping",
remapped_id.as_str(),
];
self.client.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn post_by_id_rescan_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "rescan_values"];
self.client.request_json(
Method::POST,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id_search_by_search_id(
&self,
id: impl Into<PathParam>,
search_id: impl Into<PathParam>,
query: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let search_id = search_id.into();
let segments = ["api", "field", id.as_str(), "search", search_id.as_str()];
self.client.request_json(
Method::GET,
&segments,
query,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id_summary(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "summary"];
self.client.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn get_by_id_values(&self, id: impl Into<PathParam>) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "values"];
self.client.request_json(
Method::GET,
&segments,
Option::<&()>::None,
Option::<&()>::None,
RequestOptions::default(),
)
}
pub fn post_by_id_values(
&self,
id: impl Into<PathParam>,
body: Option<&Value>,
) -> Result<Value> {
let id = id.into();
let segments = ["api", "field", id.as_str(), "values"];
self.client.request_json(
Method::POST,
&segments,
Option::<&()>::None,
body,
RequestOptions::default(),
)
}
}