use crate::prelude::*;
#[derive(Clone)]
pub struct Navigation {
pub client: Client,
}
impl Navigation {
pub async fn get_navigation_tree(&self) -> Result<Vec<NavigationNode>, LimitlessError> {
self.client.get("navigation", None).await
}
pub async fn get_page_by_path(&self, path: &str) -> Result<MarketPage, LimitlessError> {
let mut params = BTreeMap::new();
params.insert("path".into(), path.to_string());
let request = build_request(¶ms);
self.client.get("market-pages/by-path", Some(request)).await
}
pub async fn list_page_markets(
&self,
page_id: &str,
cursor: Option<&str>,
page: Option<u64>,
limit: Option<u64>,
sort_by: Option<&str>,
filters: Option<&BTreeMap<String, String>>,
) -> Result<PageMarketsResponse, LimitlessError> {
let mut params = BTreeMap::new();
if let Some(ref v) = cursor {
params.insert("cursor".into(), v.to_string());
}
if let Some(v) = page {
params.insert("page".into(), v.to_string());
}
if let Some(v) = limit {
params.insert("limit".into(), v.to_string());
}
if let Some(ref v) = sort_by {
params.insert("sortBy".into(), v.to_string());
}
if let Some(f) = filters {
for (k, v) in f {
params.insert(k.clone(), v.clone());
}
}
let request = build_request(¶ms);
let path = format!("market-pages/{}/markets", page_id);
self.client.get(&path, Some(request)).await
}
pub async fn list_property_keys(&self) -> Result<Vec<PropertyKey>, LimitlessError> {
self.client.get("property-keys", None).await
}
pub async fn get_property_key(&self, key_id: &str) -> Result<PropertyKey, LimitlessError> {
let path = format!("property-keys/{}", key_id);
self.client.get(&path, None).await
}
pub async fn list_property_options(
&self,
key_id: &str,
parent_id: Option<&str>,
) -> Result<Vec<PropertyOption>, LimitlessError> {
let mut params = BTreeMap::new();
if let Some(ref v) = parent_id {
params.insert("parentId".into(), v.to_string());
}
let request = build_request(¶ms);
let path = format!("property-keys/{}/options", key_id);
self.client.get(&path, Some(request)).await
}
}
impl Limitless for Navigation {
fn new(api_key: Option<String>, secret: Option<String>) -> Self {
Self::new_with_config(&Config::default(), api_key, secret)
}
fn new_with_config(config: &Config, api_key: Option<String>, secret: Option<String>) -> Self {
Self {
client: Client::new(api_key, secret, config.rest_api_endpoint.to_string()),
}
}
}