use std::collections::HashMap;
use serde_json::Value;
use crate::error::TombaError;
use crate::tomba::{Tomba, TombaResponse};
const VALID_BULK_TYPES: &[&str] = &[
"search",
"similar",
"company",
"finder",
"enrich",
"linkedin",
"author",
"verifier",
"phone-finder",
"phone-validator",
];
fn validate_bulk_type(bulk_type: &str) -> Result<(), TombaError> {
if !VALID_BULK_TYPES.contains(&bulk_type) {
return Err(TombaError::InvalidParam(format!(
"Invalid bulk type: \"{}\". Must be one of: {}",
bulk_type,
VALID_BULK_TYPES.join(", ")
)));
}
Ok(())
}
impl Tomba {
pub fn list_bulk(
&self,
bulk_type: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}", bulk_type);
self.call("GET", &path, &HashMap::new())
}
pub fn get_bulk(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}", bulk_type, id);
self.call("GET", &path, &HashMap::new())
}
pub fn create_bulk(
&self,
bulk_type: &str,
body: &Value,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}", bulk_type);
self.call_json("POST", &path, body)
}
pub fn launch_bulk(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}", bulk_type, id);
self.call_json("PUT", &path, &serde_json::json!({}))
}
pub fn delete_bulk(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}/delete", bulk_type, id);
self.call("DELETE", &path, &HashMap::new())
}
pub fn archive_bulk(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}/archive", bulk_type, id);
self.call("DELETE", &path, &HashMap::new())
}
pub fn rename_bulk(
&self,
bulk_type: &str,
id: &str,
name: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}/rename", bulk_type, id);
self.call_json("PUT", &path, &serde_json::json!({ "name": name }))
}
pub fn bulk_progress(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}/progress", bulk_type, id);
self.call("GET", &path, &HashMap::new())
}
pub fn bulk_download(
&self,
bulk_type: &str,
id: &str,
) -> Result<TombaResponse, TombaError> {
validate_bulk_type(bulk_type)?;
let path = format!("bulk/{}/{}/download", bulk_type, id);
self.call("GET", &path, &HashMap::new())
}
}