use super::{UrlScanResponse, VtClient};
use anyhow::{Context, Result};
use reqwest::Client;
use serde_json::{from_str, Value};
impl<'a> VtClient<'a> {
pub async fn scan_url(self, target_url: &str) -> Result<UrlScanResponse> {
let url = format!("{}/urls", self.endpoint);
let resp = Client::new()
.post(&url)
.header("x-apikey", self.api_key)
.body(format!("url={}", target_url))
.send()
.await
.context("Error! Probably maximum request limit achieved!")?;
let text: &str = &resp.text().await?;
Ok(from_str(text)?)
}
pub async fn report_url(self, resource: &str) -> Result<Value> {
let url = format!("{}/urls/{resource}", self.endpoint);
let resp = Client::new()
.get(&url)
.header("x-apikey", self.api_key)
.send()
.await
.context("Error! Probably maximum request limit achieved!")?;
let text: &str = &resp.text().await?;
Ok(from_str(text)?)
}
}