#![allow(unused_imports)]
#![cfg_attr(rustfmt, rustfmt_skip)]
use crate::{Client, ClientBuilder, Credentials, Retry};
use anyhow::Error;
use serde_json::Value;
use std::time::Duration;
use crate::util::urlencode;
pub struct Hooks {
pub client: Client
}
#[allow(non_snake_case)]
impl Hooks {
pub fn new<CB: Into<ClientBuilder>>(client_builder: CB) -> Result<Self, Error> {
Ok(Self{
client: client_builder
.into()
.path_prefix("api/hooks/v1/")
.build()?,
})
}
pub async fn ping(&self) -> Result<(), Error> {
let method = "GET";
let (path, query) = Self::ping_details();
let body = None;
let resp = self.client.request(method, path, query, body).await?;
resp.bytes().await?;
Ok(())
}
pub fn ping_url(&self) -> Result<String, Error> {
let (path, query) = Self::ping_details();
self.client.make_url(path, query)
}
pub fn ping_signed_url(&self, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::ping_details();
self.client.make_signed_url(path, query, ttl)
}
fn ping_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
let path = "ping";
let query = None;
(path, query)
}
pub async fn lbheartbeat(&self) -> Result<(), Error> {
let method = "GET";
let (path, query) = Self::lbheartbeat_details();
let body = None;
let resp = self.client.request(method, path, query, body).await?;
resp.bytes().await?;
Ok(())
}
pub fn lbheartbeat_url(&self) -> Result<String, Error> {
let (path, query) = Self::lbheartbeat_details();
self.client.make_url(path, query)
}
pub fn lbheartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::lbheartbeat_details();
self.client.make_signed_url(path, query, ttl)
}
fn lbheartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
let path = "__lbheartbeat__";
let query = None;
(path, query)
}
pub async fn version(&self) -> Result<(), Error> {
let method = "GET";
let (path, query) = Self::version_details();
let body = None;
let resp = self.client.request(method, path, query, body).await?;
resp.bytes().await?;
Ok(())
}
pub fn version_url(&self) -> Result<String, Error> {
let (path, query) = Self::version_details();
self.client.make_url(path, query)
}
pub fn version_signed_url(&self, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::version_details();
self.client.make_signed_url(path, query, ttl)
}
fn version_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
let path = "__version__";
let query = None;
(path, query)
}
pub async fn listHookGroups(&self) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::listHookGroups_details();
let body = None;
let resp = self.client.request(method, path, query, body).await?;
Ok(resp.json().await?)
}
pub fn listHookGroups_url(&self) -> Result<String, Error> {
let (path, query) = Self::listHookGroups_details();
self.client.make_url(path, query)
}
pub fn listHookGroups_signed_url(&self, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::listHookGroups_details();
self.client.make_signed_url(path, query, ttl)
}
fn listHookGroups_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
let path = "hooks";
let query = None;
(path, query)
}
pub async fn listHooks(&self, hookGroupId: &str) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::listHooks_details(hookGroupId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
pub fn listHooks_url(&self, hookGroupId: &str) -> Result<String, Error> {
let (path, query) = Self::listHooks_details(hookGroupId);
self.client.make_url(&path, query)
}
pub fn listHooks_signed_url(&self, hookGroupId: &str, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::listHooks_details(hookGroupId);
self.client.make_signed_url(&path, query, ttl)
}
fn listHooks_details<'a>(hookGroupId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}", urlencode(hookGroupId));
let query = None;
(path, query)
}
pub async fn hook(&self, hookGroupId: &str, hookId: &str) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::hook_details(hookGroupId, hookId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
pub fn hook_url(&self, hookGroupId: &str, hookId: &str) -> Result<String, Error> {
let (path, query) = Self::hook_details(hookGroupId, hookId);
self.client.make_url(&path, query)
}
pub fn hook_signed_url(&self, hookGroupId: &str, hookId: &str, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::hook_details(hookGroupId, hookId);
self.client.make_signed_url(&path, query, ttl)
}
fn hook_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn getHookStatus(&self, hookGroupId: &str, hookId: &str) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::getHookStatus_details(hookGroupId, hookId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
pub fn getHookStatus_url(&self, hookGroupId: &str, hookId: &str) -> Result<String, Error> {
let (path, query) = Self::getHookStatus_details(hookGroupId, hookId);
self.client.make_url(&path, query)
}
pub fn getHookStatus_signed_url(&self, hookGroupId: &str, hookId: &str, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::getHookStatus_details(hookGroupId, hookId);
self.client.make_signed_url(&path, query, ttl)
}
fn getHookStatus_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/status", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn createHook(&self, hookGroupId: &str, hookId: &str, payload: &Value) -> Result<Value, Error> {
let method = "PUT";
let (path, query) = Self::createHook_details(hookGroupId, hookId);
let body = Some(payload);
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
fn createHook_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn updateHook(&self, hookGroupId: &str, hookId: &str, payload: &Value) -> Result<Value, Error> {
let method = "POST";
let (path, query) = Self::updateHook_details(hookGroupId, hookId);
let body = Some(payload);
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
fn updateHook_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn removeHook(&self, hookGroupId: &str, hookId: &str) -> Result<(), Error> {
let method = "DELETE";
let (path, query) = Self::removeHook_details(hookGroupId, hookId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
resp.bytes().await?;
Ok(())
}
fn removeHook_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn triggerHook(&self, hookGroupId: &str, hookId: &str, payload: &Value) -> Result<Value, Error> {
let method = "POST";
let (path, query) = Self::triggerHook_details(hookGroupId, hookId);
let body = Some(payload);
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
fn triggerHook_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/trigger", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn getTriggerToken(&self, hookGroupId: &str, hookId: &str) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::getTriggerToken_details(hookGroupId, hookId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
pub fn getTriggerToken_url(&self, hookGroupId: &str, hookId: &str) -> Result<String, Error> {
let (path, query) = Self::getTriggerToken_details(hookGroupId, hookId);
self.client.make_url(&path, query)
}
pub fn getTriggerToken_signed_url(&self, hookGroupId: &str, hookId: &str, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::getTriggerToken_details(hookGroupId, hookId);
self.client.make_signed_url(&path, query, ttl)
}
fn getTriggerToken_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/token", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn resetTriggerToken(&self, hookGroupId: &str, hookId: &str) -> Result<Value, Error> {
let method = "POST";
let (path, query) = Self::resetTriggerToken_details(hookGroupId, hookId);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
fn resetTriggerToken_details<'a>(hookGroupId: &'a str, hookId: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/token", urlencode(hookGroupId), urlencode(hookId));
let query = None;
(path, query)
}
pub async fn triggerHookWithToken(&self, hookGroupId: &str, hookId: &str, token: &str, payload: &Value) -> Result<Value, Error> {
let method = "POST";
let (path, query) = Self::triggerHookWithToken_details(hookGroupId, hookId, token);
let body = Some(payload);
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
fn triggerHookWithToken_details<'a>(hookGroupId: &'a str, hookId: &'a str, token: &'a str) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/trigger/{}", urlencode(hookGroupId), urlencode(hookId), urlencode(token));
let query = None;
(path, query)
}
pub async fn listLastFires(&self, hookGroupId: &str, hookId: &str, continuationToken: Option<&str>, limit: Option<&str>) -> Result<Value, Error> {
let method = "GET";
let (path, query) = Self::listLastFires_details(hookGroupId, hookId, continuationToken, limit);
let body = None;
let resp = self.client.request(method, &path, query, body).await?;
Ok(resp.json().await?)
}
pub fn listLastFires_url(&self, hookGroupId: &str, hookId: &str, continuationToken: Option<&str>, limit: Option<&str>) -> Result<String, Error> {
let (path, query) = Self::listLastFires_details(hookGroupId, hookId, continuationToken, limit);
self.client.make_url(&path, query)
}
pub fn listLastFires_signed_url(&self, hookGroupId: &str, hookId: &str, continuationToken: Option<&str>, limit: Option<&str>, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::listLastFires_details(hookGroupId, hookId, continuationToken, limit);
self.client.make_signed_url(&path, query, ttl)
}
fn listLastFires_details<'a>(hookGroupId: &'a str, hookId: &'a str, continuationToken: Option<&'a str>, limit: Option<&'a str>) -> (String, Option<Vec<(&'static str, &'a str)>>) {
let path = format!("hooks/{}/{}/last-fires", urlencode(hookGroupId), urlencode(hookId));
let mut query = None;
if let Some(q) = continuationToken {
query.get_or_insert_with(Vec::new).push(("continuationToken", q));
}
if let Some(q) = limit {
query.get_or_insert_with(Vec::new).push(("limit", q));
}
(path, query)
}
pub async fn heartbeat(&self) -> Result<(), Error> {
let method = "GET";
let (path, query) = Self::heartbeat_details();
let body = None;
let resp = self.client.request(method, path, query, body).await?;
resp.bytes().await?;
Ok(())
}
pub fn heartbeat_url(&self) -> Result<String, Error> {
let (path, query) = Self::heartbeat_details();
self.client.make_url(path, query)
}
pub fn heartbeat_signed_url(&self, ttl: Duration) -> Result<String, Error> {
let (path, query) = Self::heartbeat_details();
self.client.make_signed_url(path, query, ttl)
}
fn heartbeat_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
let path = "__heartbeat__";
let query = None;
(path, query)
}
}