use serde_json::json;
use crate::types::{
AgentBatch, AgentBatchLine, AgentCheck, AgentCheckRequest, AgentSelfCheck, AgentSelfRequest,
Allowlist, AllowlistAgent, CrawlerVerification, CrawlerVerifyRequest,
};
use crate::{Client, Error};
#[derive(Debug, Clone, Copy)]
pub struct Agentscan<'a> {
client: &'a Client,
}
impl<'a> Agentscan<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Agentscan { client }
}
pub async fn check(&self, req: &AgentCheckRequest) -> Result<AgentCheck, Error> {
self.client.post("/agentscan/check", req).await
}
pub async fn batch(&self, lines: &[AgentBatchLine]) -> Result<AgentBatch, Error> {
self.client
.post("/agentscan/batch", &json!({ "lines": lines }))
.await
}
pub async fn verify(&self, req: &CrawlerVerifyRequest) -> Result<CrawlerVerification, Error> {
self.client.post("/agentscan/verify", req).await
}
pub async fn allowlist(&self) -> Result<Vec<AllowlistAgent>, Error> {
let res: Allowlist = self.client.get("/agentscan/allowlist", &[]).await?;
Ok(res.agents)
}
pub async fn self_check(&self, req: &AgentSelfRequest) -> Result<AgentSelfCheck, Error> {
self.client.post("/agentscan/self", req).await
}
}