use crate::error::Error;
use crate::http::{ClientBuilder, HttpClient, Method, Request, RequestParts};
use crate::types;
use crate::resources::accounts::AccountsResource;
use crate::resources::bots::BotsResource;
use crate::resources::branding::BrandingResource;
use crate::resources::calls::CallsResource;
use crate::resources::channels::ChannelsResource;
use crate::resources::chats::ChatsResource;
use crate::resources::contacts::ContactsResource;
use crate::resources::events::EventsResource;
use crate::resources::favorite_stickers::FavoriteStickersResource;
use crate::resources::groups::GroupsResource;
use crate::resources::incoming_webhooks::IncomingWebhooksResource;
use crate::resources::invitations::InvitationsResource;
use crate::resources::labels::LabelsResource;
use crate::resources::messages::MessagesResource;
use crate::resources::orders::OrdersResource;
use crate::resources::privacy::PrivacyResource;
use crate::resources::profile::ProfileResource;
use crate::resources::projects::ProjectsResource;
use crate::resources::proxy_locations::ProxyLocationsResource;
use crate::resources::sticker_packs::StickerPacksResource;
use crate::resources::stories::StoriesResource;
use crate::resources::uploads::UploadsResource;
use crate::resources::usage::UsageResource;
use crate::resources::webhook_endpoints::WebhookEndpointsResource;
#[derive(Clone, Debug)]
pub struct Wuapi {
http: HttpClient,
}
impl From<HttpClient> for Wuapi {
fn from(http: HttpClient) -> Self {
Self { http }
}
}
impl Wuapi {
pub fn new(api_key: impl Into<String>) -> Result<Self, Error> {
ClientBuilder::new().api_key(api_key).build()
}
pub fn from_env() -> Result<Self, Error> {
ClientBuilder::new().build()
}
#[must_use]
pub fn builder() -> ClientBuilder {
ClientBuilder::new()
}
#[must_use]
pub fn http(&self) -> &HttpClient {
&self.http
}
#[must_use]
pub fn base_url(&self) -> &str {
self.http.base_url()
}
#[must_use]
pub fn project(&self) -> Option<&str> {
self.http.project()
}
pub fn with_project(&self, project: &str) -> Result<Self, Error> {
self.http.with_project(project).map(Self::from)
}
#[must_use]
pub fn accounts(&self) -> AccountsResource {
AccountsResource::new(self.http.clone())
}
#[must_use]
pub fn proxy_locations(&self) -> ProxyLocationsResource {
ProxyLocationsResource::new(self.http.clone())
}
#[must_use]
pub fn messages(&self) -> MessagesResource {
MessagesResource::new(self.http.clone())
}
#[must_use]
pub fn stories(&self) -> StoriesResource {
StoriesResource::new(self.http.clone())
}
#[must_use]
pub fn uploads(&self) -> UploadsResource {
UploadsResource::new(self.http.clone())
}
#[must_use]
pub fn chats(&self) -> ChatsResource {
ChatsResource::new(self.http.clone())
}
#[must_use]
pub fn labels(&self) -> LabelsResource {
LabelsResource::new(self.http.clone())
}
#[must_use]
pub fn contacts(&self) -> ContactsResource {
ContactsResource::new(self.http.clone())
}
#[must_use]
pub fn bots(&self) -> BotsResource {
BotsResource::new(self.http.clone())
}
#[must_use]
pub fn profile(&self) -> ProfileResource {
ProfileResource::new(self.http.clone())
}
#[must_use]
pub fn privacy(&self) -> PrivacyResource {
PrivacyResource::new(self.http.clone())
}
#[must_use]
pub fn calls(&self) -> CallsResource {
CallsResource::new(self.http.clone())
}
#[must_use]
pub fn sticker_packs(&self) -> StickerPacksResource {
StickerPacksResource::new(self.http.clone())
}
#[must_use]
pub fn favorite_stickers(&self) -> FavoriteStickersResource {
FavoriteStickersResource::new(self.http.clone())
}
#[must_use]
pub fn orders(&self) -> OrdersResource {
OrdersResource::new(self.http.clone())
}
#[must_use]
pub fn groups(&self) -> GroupsResource {
GroupsResource::new(self.http.clone())
}
#[must_use]
pub fn channels(&self) -> ChannelsResource {
ChannelsResource::new(self.http.clone())
}
#[must_use]
pub fn webhook_endpoints(&self) -> WebhookEndpointsResource {
WebhookEndpointsResource::new(self.http.clone())
}
#[must_use]
pub fn incoming_webhooks(&self) -> IncomingWebhooksResource {
IncomingWebhooksResource::new(self.http.clone())
}
#[must_use]
pub fn projects(&self) -> ProjectsResource {
ProjectsResource::new(self.http.clone())
}
#[must_use]
pub fn invitations(&self) -> InvitationsResource {
InvitationsResource::new(self.http.clone())
}
#[must_use]
pub fn branding(&self) -> BrandingResource {
BrandingResource::new(self.http.clone())
}
#[must_use]
pub fn usage(&self) -> UsageResource {
UsageResource::new(self.http.clone())
}
#[must_use]
pub fn events(&self) -> EventsResource {
EventsResource::new(self.http.clone())
}
pub fn me(&self) -> Request<types::AuthContext> {
let parts = RequestParts::new(Method::Get, "/v1/me").retryable();
self.http.request(parts)
}
}