use crate::errors::HivehookError;
use crate::resources::*;
use crate::transport::{BlockingGraphQLTransport, DEFAULT_MAX_RETRIES};
use std::time::Duration;
#[derive(Clone)]
pub struct HivehookClient {
transport: BlockingGraphQLTransport,
}
impl std::fmt::Debug for HivehookClient {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HivehookClient")
.field("transport", &self.transport)
.finish()
}
}
#[derive(Debug, Clone)]
pub struct HivehookClientBuilder {
base_url: String,
api_key: Option<String>,
timeout: Option<Duration>,
max_retries: u32,
}
impl HivehookClientBuilder {
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<HivehookClient, HivehookError> {
Ok(HivehookClient {
transport: BlockingGraphQLTransport::with_options(
&self.base_url,
self.api_key,
self.timeout,
self.max_retries,
)?,
})
}
}
impl HivehookClient {
pub fn new(base_url: &str, api_key: Option<String>) -> Result<Self, HivehookError> {
Ok(Self {
transport: BlockingGraphQLTransport::new(base_url, api_key)?,
})
}
pub fn builder(base_url: impl Into<String>, api_key: Option<String>) -> HivehookClientBuilder {
HivehookClientBuilder {
base_url: base_url.into(),
api_key,
timeout: None,
max_retries: DEFAULT_MAX_RETRIES,
}
}
pub fn sources(&self) -> sources::SourceService<'_> {
sources::SourceService { transport: &self.transport }
}
pub fn destinations(&self) -> destinations::DestinationService<'_> {
destinations::DestinationService { transport: &self.transport }
}
pub fn subscriptions(&self) -> subscriptions::SubscriptionService<'_> {
subscriptions::SubscriptionService { transport: &self.transport }
}
pub fn events(&self) -> events::EventService<'_> {
events::EventService { transport: &self.transport }
}
pub fn deliveries(&self) -> deliveries::DeliveryService<'_> {
deliveries::DeliveryService { transport: &self.transport }
}
pub fn dlq(&self) -> dlq::DLQService<'_> {
dlq::DLQService { transport: &self.transport }
}
pub fn api_keys(&self) -> api_keys::ApiKeyService<'_> {
api_keys::ApiKeyService { transport: &self.transport }
}
pub fn alert_rules(&self) -> alert_rules::AlertRuleService<'_> {
alert_rules::AlertRuleService { transport: &self.transport }
}
pub fn bookmarks(&self) -> bookmarks::BookmarkService<'_> {
bookmarks::BookmarkService { transport: &self.transport }
}
pub fn event_type_schemas(&self) -> event_type_schemas::EventTypeSchemaService<'_> {
event_type_schemas::EventTypeSchemaService { transport: &self.transport }
}
pub fn applications(&self) -> applications::ApplicationService<'_> {
applications::ApplicationService { transport: &self.transport }
}
pub fn endpoints(&self) -> endpoints::EndpointService<'_> {
endpoints::EndpointService { transport: &self.transport }
}
pub fn messages(&self) -> messages::MessageService<'_> {
messages::MessageService { transport: &self.transport }
}
pub fn outbound_deliveries(&self) -> outbound_deliveries::OutboundDeliveryService<'_> {
outbound_deliveries::OutboundDeliveryService { transport: &self.transport }
}
pub fn outbound_dlq(&self) -> outbound_dlq::OutboundDLQService<'_> {
outbound_dlq::OutboundDLQService { transport: &self.transport }
}
pub fn status(&self) -> status::StatusService<'_> {
status::StatusService { transport: &self.transport }
}
pub fn transformations(&self) -> transformations::TransformationService<'_> {
transformations::TransformationService { transport: &self.transport }
}
pub fn portal(&self) -> portal::PortalService<'_> {
portal::PortalService { transport: &self.transport }
}
pub fn streams(&self) -> streams::StreamService<'_> {
streams::StreamService { transport: &self.transport }
}
pub fn stream_consumers(&self) -> stream_consumers::StreamConsumerService<'_> {
stream_consumers::StreamConsumerService { transport: &self.transport }
}
pub fn stream_sinks(&self) -> stream_sinks::StreamSinkService<'_> {
stream_sinks::StreamSinkService { transport: &self.transport }
}
pub fn organizations(&self) -> organizations::OrganizationService<'_> {
organizations::OrganizationService { transport: &self.transport }
}
pub fn users(&self) -> users::UserService<'_> {
users::UserService { transport: &self.transport }
}
pub fn audit_logs(&self) -> audit_logs::AuditLogService<'_> {
audit_logs::AuditLogService { transport: &self.transport }
}
}