mod client_core;
mod update_stream;
pub use crate::endpoints::*;
use crate::{ClientBuilder, Result};
pub use client_core::*;
use std::fmt::Debug;
pub use update_stream::*;
#[derive(Clone)]
pub struct Client {
pub(crate) client: reqwest::Client,
pub(crate) base_url: String,
pub(crate) access_key: String,
}
impl Client {
pub fn builder() -> ClientBuilder {
ClientBuilder::default()
}
pub fn new<S1: ToString, S2: ToString>(endpoint: S1, access_key: S2) -> Self {
Self {
base_url: endpoint.to_string(),
client: reqwest::Client::new(),
access_key: access_key.to_string(),
}
}
#[tracing::instrument(skip(self), level = "debug")]
pub async fn get_options(&self) -> Result<OptionsResponse> {
self.get::<OptionsEndpoint, ()>(&()).await
}
#[tracing::instrument(skip(self), level = "debug")]
pub async fn get_metadata(&self, since: u64) -> Result<MetadataResponse> {
self.get::<MetadataEndpoint, _>(&[("since", since)]).await
}
#[tracing::instrument(skip(self), level = "debug")]
pub async fn get_update<S: AsRef<str> + Debug>(
&self,
update_hash: S,
) -> Result<UpdateResponse> {
self.get::<UpdateEndpoint, _>(&[("update_hash", update_hash.as_ref())])
.await
}
}