use serde_json::json;
use crate::core::{urlencode_path, Json, Result};
platform_service! {
CatalogService
}
impl CatalogService {
pub async fn apis(&self, search: Option<&str>) -> Result<Json> {
match search.filter(|search| !search.is_empty()) {
Some(search) => {
self.base
.get_query("apis", json!({ "search": search }))
.await
}
None => self.base.get("apis").await,
}
}
pub async fn api(&self, identifier: &str) -> Result<Json> {
self.base.get(&format!("apis/{identifier}")).await
}
pub async fn api_by_name(&self, name: &str) -> Result<Json> {
self.base
.get(&format!("apis/name/{}", urlencode_path(name)))
.await
}
pub async fn apis_by_device(&self, device_token: &str) -> Result<Json> {
self.base.get(&format!("apis/device/{device_token}")).await
}
pub async fn documentations_by_server(&self, server_search: &str) -> Result<Json> {
self.base
.get(&format!("documentations/server/{server_search}"))
.await
}
}
json_get! {
CatalogService {
api_categories => "apis/categories",
my_apis => "apis/list",
plans => "plans",
documentations => "documentations",
servers => "servers",
status => "status",
}
}
json_body! {
CatalogService {
endpoint_url => post "endpoint/url",
endpoint_body => post "endpoint/body",
}
}