use crate::models::apps::UpdateWebhookConfig;
use crate::models::hooks::{Config, Delivery, DeliveryDetail};
use crate::models::HookDeliveryId;
use crate::{Octocrab, Result};
pub struct AppWebhookHandler<'octo> {
crab: &'octo Octocrab,
}
impl<'octo> AppWebhookHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self { crab }
}
pub async fn get_config(&self) -> Result<Config> {
self.crab.get("/app/hook/config", None::<&()>).await
}
pub async fn update_config(&self, config: &UpdateWebhookConfig) -> Result<Config> {
self.crab.patch("/app/hook/config", Some(config)).await
}
pub fn deliveries(&self) -> ListAppWebhookDeliveriesBuilder<'octo> {
ListAppWebhookDeliveriesBuilder::new(self.crab)
}
pub async fn delivery(&self, delivery_id: impl Into<HookDeliveryId>) -> Result<DeliveryDetail> {
let route = format!("/app/hook/deliveries/{}", delivery_id.into());
self.crab.get(route, None::<&()>).await
}
pub async fn redeliver(&self, delivery_id: impl Into<HookDeliveryId>) -> Result<()> {
let route = format!("/app/hook/deliveries/{}/attempts", delivery_id.into());
let resp = self.crab._post(route, None::<&()>).await?;
crate::map_github_error(resp).await?;
Ok(())
}
}
#[derive(serde::Serialize)]
pub struct ListAppWebhookDeliveriesBuilder<'octo> {
#[serde(skip)]
crab: &'octo Octocrab,
#[serde(skip_serializing_if = "Option::is_none")]
per_page: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
cursor: Option<String>,
}
impl<'octo> ListAppWebhookDeliveriesBuilder<'octo> {
pub(crate) fn new(crab: &'octo Octocrab) -> Self {
Self {
crab,
per_page: None,
cursor: None,
}
}
pub fn per_page(mut self, per_page: impl Into<u8>) -> Self {
self.per_page = Some(per_page.into());
self
}
pub fn cursor(mut self, cursor: impl Into<String>) -> Self {
self.cursor = Some(cursor.into());
self
}
pub async fn send(self) -> Result<Vec<Delivery>> {
self.crab.get("/app/hook/deliveries", Some(&self)).await
}
}