mod response;
use response::{Root, ScanRoot};
use crate::{
utils::{http_get, http_post},
VtClient, VtResult,
};
use base64::{engine::general_purpose::STANDARD, Engine as _};
impl VtClient {
pub fn url_scan(&self, resource_url: &str) -> VtResult<ScanRoot> {
let url = format!("{}/urls", &self.endpoint);
let form_data = &[("public_api.url", resource_url)];
http_post(&self.api_key, &self.user_agent, &url, form_data)
}
pub fn url_rescan(&self, resource_id: &str) -> VtResult<ScanRoot> {
let url_id = resource_id.split('-').nth(1).unwrap_or(resource_id);
let url = format!("{}/urls/{}/analyse", &self.endpoint, url_id);
let form_data = &[("public_api.url", resource_id)];
http_post(&self.api_key, &self.user_agent, &url, form_data)
}
pub fn url_info(&self, resource_url: &str) -> VtResult<Root> {
let url = format!(
"{}/urls/{}",
&self.endpoint,
STANDARD.encode(resource_url).replace('=', "")
);
http_get(&self.api_key, &self.user_agent, &url)
}
pub fn url_info_by_id(&self, resource_id: &str) -> VtResult<Root> {
let url_id = resource_id.split('-').nth(1).unwrap_or(resource_id);
let url = format!("{}/urls/{}", &self.endpoint, url_id);
http_get(&self.api_key, &self.user_agent, &url)
}
}