use crate::errors::HivehookError;
use crate::resources::*;
use crate::transport::{AsyncGraphQLTransport, DEFAULT_MAX_RETRIES};
use std::time::Duration;
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[derive(Clone)]
pub struct AsyncHivehookClient {
transport: AsyncGraphQLTransport,
}
impl std::fmt::Debug for AsyncHivehookClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AsyncHivehookClient")
.field("transport", &self.transport)
.finish()
}
}
#[derive(Debug, Clone)]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub struct AsyncHivehookClientBuilder {
base_url: String,
api_key: Option<String>,
timeout: Option<Duration>,
max_retries: u32,
}
impl AsyncHivehookClientBuilder {
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub fn max_retries(mut self, max_retries: u32) -> Self {
self.max_retries = max_retries;
self
}
pub fn build(self) -> Result<AsyncHivehookClient, HivehookError> {
Ok(AsyncHivehookClient {
transport: AsyncGraphQLTransport::with_options(
&self.base_url,
self.api_key,
self.timeout,
self.max_retries,
)?,
})
}
}
impl AsyncHivehookClient {
pub fn new(base_url: &str, api_key: Option<String>) -> Result<Self, HivehookError> {
Ok(Self {
transport: AsyncGraphQLTransport::new(base_url, api_key)?,
})
}
pub fn builder(
base_url: impl Into<String>,
api_key: Option<String>,
) -> AsyncHivehookClientBuilder {
AsyncHivehookClientBuilder {
base_url: base_url.into(),
api_key,
timeout: None,
max_retries: DEFAULT_MAX_RETRIES,
}
}
pub fn sources(&self) -> sources::AsyncSourceService<'_> {
sources::AsyncSourceService { transport: &self.transport }
}
pub fn destinations(&self) -> destinations::AsyncDestinationService<'_> {
destinations::AsyncDestinationService { transport: &self.transport }
}
pub fn subscriptions(&self) -> subscriptions::AsyncSubscriptionService<'_> {
subscriptions::AsyncSubscriptionService { transport: &self.transport }
}
pub fn events(&self) -> events::AsyncEventService<'_> {
events::AsyncEventService { transport: &self.transport }
}
pub fn deliveries(&self) -> deliveries::AsyncDeliveryService<'_> {
deliveries::AsyncDeliveryService { transport: &self.transport }
}
pub fn dlq(&self) -> dlq::AsyncDLQService<'_> {
dlq::AsyncDLQService { transport: &self.transport }
}
pub fn api_keys(&self) -> api_keys::AsyncApiKeyService<'_> {
api_keys::AsyncApiKeyService { transport: &self.transport }
}
pub fn alert_rules(&self) -> alert_rules::AsyncAlertRuleService<'_> {
alert_rules::AsyncAlertRuleService { transport: &self.transport }
}
pub fn bookmarks(&self) -> bookmarks::AsyncBookmarkService<'_> {
bookmarks::AsyncBookmarkService { transport: &self.transport }
}
pub fn event_type_schemas(&self) -> event_type_schemas::AsyncEventTypeSchemaService<'_> {
event_type_schemas::AsyncEventTypeSchemaService { transport: &self.transport }
}
pub fn applications(&self) -> applications::AsyncApplicationService<'_> {
applications::AsyncApplicationService { transport: &self.transport }
}
pub fn endpoints(&self) -> endpoints::AsyncEndpointService<'_> {
endpoints::AsyncEndpointService { transport: &self.transport }
}
pub fn messages(&self) -> messages::AsyncMessageService<'_> {
messages::AsyncMessageService { transport: &self.transport }
}
pub fn outbound_deliveries(&self) -> outbound_deliveries::AsyncOutboundDeliveryService<'_> {
outbound_deliveries::AsyncOutboundDeliveryService { transport: &self.transport }
}
pub fn outbound_dlq(&self) -> outbound_dlq::AsyncOutboundDLQService<'_> {
outbound_dlq::AsyncOutboundDLQService { transport: &self.transport }
}
pub fn status(&self) -> status::AsyncStatusService<'_> {
status::AsyncStatusService { transport: &self.transport }
}
pub fn transformations(&self) -> transformations::AsyncTransformationService<'_> {
transformations::AsyncTransformationService { transport: &self.transport }
}
pub fn portal(&self) -> portal::AsyncPortalService<'_> {
portal::AsyncPortalService { transport: &self.transport }
}
pub fn streams(&self) -> streams::AsyncStreamService<'_> {
streams::AsyncStreamService { transport: &self.transport }
}
pub fn stream_consumers(&self) -> stream_consumers::AsyncStreamConsumerService<'_> {
stream_consumers::AsyncStreamConsumerService { transport: &self.transport }
}
pub fn stream_sinks(&self) -> stream_sinks::AsyncStreamSinkService<'_> {
stream_sinks::AsyncStreamSinkService { transport: &self.transport }
}
pub fn organizations(&self) -> organizations::AsyncOrganizationService<'_> {
organizations::AsyncOrganizationService { transport: &self.transport }
}
pub fn users(&self) -> users::AsyncUserService<'_> {
users::AsyncUserService { transport: &self.transport }
}
pub fn audit_logs(&self) -> audit_logs::AsyncAuditLogService<'_> {
audit_logs::AsyncAuditLogService { transport: &self.transport }
}
}