allow to assign automatically current user on new work package
This commit is contained in:
42
src/openproject/root.rs
Normal file
42
src/openproject/root.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use crate::openproject::client::{handle_response_status, Client, Error};
|
||||
use crate::openproject::hal::HalEntity;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct User {
|
||||
pub href: String,
|
||||
pub title: String,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Links {
|
||||
pub user: User,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Root {
|
||||
#[serde(rename = "instanceName")]
|
||||
pub instance_name: String,
|
||||
#[serde(rename = "_links")]
|
||||
pub links: Links,
|
||||
#[serde(flatten)]
|
||||
pub hal_entity: HalEntity,
|
||||
}
|
||||
|
||||
pub trait RootClient {
|
||||
async fn root(&self) -> Result<Root, Error>;
|
||||
}
|
||||
|
||||
impl RootClient for Client {
|
||||
async fn root(&self) -> Result<Root, Error> {
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let response = client
|
||||
.get(format!("{}/api/v3", self.base_url))
|
||||
.basic_auth("apikey", Some(&self.token))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let r = handle_response_status(response, "Error while retrieving root").await?;
|
||||
|
||||
Ok(r)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user