use serde::Serialize;
use crate::api::orgs::OrgHandler;
use crate::Result;
pub struct OrgExternalPropertiesHandler<'octo, 'b> {
handler: &'b OrgHandler<'octo>,
}
impl<'octo, 'b> OrgExternalPropertiesHandler<'octo, 'b> {
pub(crate) fn new(handler: &'b OrgHandler<'octo>) -> Self {
Self { handler }
}
pub async fn list_installations(&self) -> Result<serde_json::Value> {
let route = format!("/orgs/{}/properties/installations", self.handler.owner);
self.handler.crab.get(route, None::<&()>).await
}
pub async fn register_installation(&self, body: &impl Serialize) -> Result<serde_json::Value> {
let route = format!("/orgs/{}/properties/installations", self.handler.owner);
self.handler.crab.post(route, Some(body)).await
}
pub async fn get_schema(&self) -> Result<serde_json::Value> {
let route = format!(
"/orgs/{}/properties/installations/schema",
self.handler.owner
);
self.handler.crab.get(route, None::<&()>).await
}
pub async fn create_or_update_values(&self, body: &impl Serialize) -> Result<()> {
let route = format!(
"/orgs/{}/properties/installations/values",
self.handler.owner
);
let res = self.handler.crab._patch(route, Some(body)).await?;
crate::map_github_error(res).await.map(drop)
}
pub async fn create_or_update_property_values(
&self,
property_name: impl AsRef<str>,
body: &impl Serialize,
) -> Result<()> {
let route = format!(
"/orgs/{}/properties/installations/values/{}",
self.handler.owner,
property_name.as_ref()
);
let res = self.handler.crab._patch(route, Some(body)).await?;
crate::map_github_error(res).await.map(drop)
}
pub async fn delete_property_values(&self, property_name: impl AsRef<str>) -> Result<()> {
let route = format!(
"/orgs/{}/properties/installations/values/{}",
self.handler.owner,
property_name.as_ref()
);
let res = self.handler.crab._delete(route, None::<&()>).await?;
crate::map_github_error(res).await.map(drop)
}
}