use crate::client::MaxClient;
use crate::error::Result;
use crate::types::Subscription;
impl MaxClient {
pub async fn get_subscriptions(&self) -> Result<Vec<Subscription>> {
self.request_with_rate_limit(reqwest::Method::GET, "/subscriptions", &[], None)
.await
}
pub async fn create_subscription(
&self,
url: &str,
update_types: Vec<String>,
secret: Option<&str>,
) -> Result<()> {
let mut body = serde_json::json!({
"url": url,
"update_types": update_types,
});
if let Some(s) = secret {
body["secret"] = s.into();
}
let resp: serde_json::Value = self
.request_with_rate_limit(reqwest::Method::POST, "/subscriptions", &[], Some(body))
.await?;
if !resp["success"].as_bool().unwrap_or(false) {
let msg = resp["message"].as_str().unwrap_or("unknown error");
return Err(crate::error::Error::Api {
code: 400,
message: msg.to_string(),
});
}
Ok(())
}
pub async fn delete_subscription(&self, url: &str) -> Result<()> {
let resp: serde_json::Value = self
.request_with_rate_limit(
reqwest::Method::DELETE,
"/subscriptions",
&[("url", url.to_string())],
None,
)
.await?;
if !resp["success"].as_bool().unwrap_or(false) {
let msg = resp["message"].as_str().unwrap_or("unknown error");
return Err(crate::error::Error::Api {
code: 400,
message: msg.to_string(),
});
}
Ok(())
}
}