use crate::config::OpenProjectConfig; use crate::error::GeneralError; use crate::openproject::work::{WorkPackageWriter, WorkPackage}; pub(crate) struct Error { description: String, } impl From for Error { fn from(value: reqwest::Error) -> Self { Error { description: format!("Error while connecting to openproject instance: {}", value) } } } impl From for GeneralError { fn from(value: Error) -> GeneralError { GeneralError{description: value.description} } } pub(crate) struct Client { base_url: String, token: String, } impl Client { pub fn from_config(config: &OpenProjectConfig) -> Client { Client{base_url: config.base_url.clone(), token: config.token.clone()} } pub async fn create_work_package(&self, work_package: &WorkPackageWriter, project_id: &String) -> Result { let client = reqwest::Client::new(); let work_package: WorkPackage = client .post(format!("{}/api/v3/projects/{}/work_packages", self.base_url, project_id)) .basic_auth("apikey", Some(&self.token)) .json(&work_package) .send() .await? .json() .await?; Ok(work_package) } }