1#![forbid(unsafe_code)]
30#![warn(missing_debug_implementations)]
31
32mod admin_api;
33mod analytics;
34mod error;
35mod http;
36mod public_api;
37
38pub mod models;
39
40pub use admin_api::AdminApi;
41pub use analytics::{
42 analytics_namespace, fnv1a32_hex, origin_of, AnalyticsOptions, AnalyticsPersistence,
43 EventBatch, EventQueue, QueuedEvent,
44};
45pub use error::{Error, Result};
46pub use http::{
47 detect_platform, detect_platform_version, VerhubClientBuilder, CLIENT_TIME_HEADER,
48 PLATFORM_HEADER, PLATFORM_VERSION_HEADER,
49};
50pub use models::{LogLevel, Platform, TermsDocumentSlug};
52pub use public_api::PublicApi;
53
54use std::sync::Arc;
55
56use reqwest::Method;
57
58use crate::http::Inner;
59use crate::models::HealthResponse;
60
61pub const VERHUB_SDK_VERSION: &str = "0.2.10";
63
64#[derive(Debug, Clone)]
71pub struct VerhubClient {
72 inner: Arc<Inner>,
73}
74
75impl VerhubClient {
76 pub fn new(base_url: impl Into<String>) -> Result<Self> {
81 Self::builder(base_url).build()
82 }
83
84 pub fn builder(base_url: impl Into<String>) -> VerhubClientBuilder {
86 VerhubClientBuilder::new(base_url)
87 }
88 pub(crate) fn from_inner(inner: Inner) -> Self {
89 Self {
90 inner: Arc::new(inner),
91 }
92 }
93
94 pub fn public(&self) -> PublicApi<'_> {
96 PublicApi { inner: &self.inner }
97 }
98
99 pub fn admin(&self) -> AdminApi<'_> {
101 AdminApi { inner: &self.inner }
102 }
103
104 pub fn project_key(&self) -> Option<String> {
106 self.inner.project_key()
107 }
108
109 pub fn set_project_key(&self, project_key: impl Into<String>) {
111 self.inner.set_project_key(project_key);
112 }
113
114 pub fn set_token(&self, token: impl Into<String>) {
116 self.inner.set_token(token);
117 }
118
119 pub fn clear_token(&self) {
121 self.inner.clear_token();
122 }
123
124 pub fn set_platform(&self, platform: Option<Platform>) {
126 self.inner.set_platform(platform);
127 }
128
129 pub fn set_platform_version(&self, version: Option<String>) {
131 self.inner.set_platform_version(version);
132 }
133
134 pub async fn health(&self) -> Result<HealthResponse> {
136 self.inner
137 .request::<_, ()>(Method::GET, "/health", &[], None, false)
138 .await
139 }
140}
141
142impl VerhubClientBuilder {
143 pub fn build(self) -> Result<VerhubClient> {
146 Ok(VerhubClient::from_inner(self.build_inner()?))
147 }
148}