use serde_json::json;
use crate::core::{IntoBody, Json, Result};
platform_service! {
IpWhitelistService
}
impl IpWhitelistService {
pub async fn get(&self) -> Result<Json> {
self.base.get("ip-whitelist").await
}
pub async fn set<I, S>(&self, entries: I) -> Result<Json>
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
let entries: Vec<String> = entries.into_iter().map(Into::into).collect();
self.base
.put("ip-whitelist", json!({ "ip_whitelist": entries }))
.await
}
pub async fn add(&self, entry: &str) -> Result<Json> {
self.base
.post("ip-whitelist/add", json!({ "entry": entry }))
.await
}
pub async fn remove(&self, entry: &str) -> Result<Json> {
self.base
.delete("ip-whitelist/remove", json!({ "entry": entry }))
.await
}
pub async fn validate(&self, entry: &str) -> Result<Json> {
self.base
.post("ip-whitelist/validate", json!({ "entry": entry }))
.await
}
pub async fn current_ip(&self) -> Result<Json> {
self.base.get("ip-whitelist/current-ip").await
}
}
json_empty! {
IpWhitelistService {
add_current => post "ip-whitelist/add-current",
reset => post "ip-whitelist/reset",
}
}
platform_service! {
BearerRateLimitService
}
impl BearerRateLimitService {
pub async fn get(&self) -> Result<Json> {
self.base.get("bearer-rate-limit").await
}
pub async fn set(&self, body: impl IntoBody) -> Result<Json> {
self.base.put("bearer-rate-limit", body).await
}
}