use crate::inner::VkApiInner;
use crate::structs::Version;
use crate::vkapi::{Compression, Encoding, VkApi};
#[derive(Clone, Debug)]
pub struct VkApiBuilder {
inner: VkApiInner,
}
impl VkApiBuilder {
pub fn new(access_token: String) -> Self {
cfg_if::cfg_if! {
if #[cfg(feature = "compression_zstd")] {
let encoding = Compression::Zstd;
} else if #[cfg(feature = "compression_gzip")] {
let encoding = Compression::Gzip;
} else {
let encoding = Compression::None;
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "encode_msgpack")] {
let format = Encoding::Msgpack;
} else if #[cfg(feature = "encode_json")] {
let format = Encoding::Json;
} else {
let format = Encoding::None;
}
}
Self {
inner: VkApiInner {
access_token,
version: Version::default(),
domain: "api.vk.ru".to_owned(),
format,
encoding,
},
}
}
#[must_use]
pub fn with_access_token(mut self, access_token: String) -> Self {
self.inner.access_token = access_token;
self
}
#[must_use]
pub const fn with_version(mut self, version: Version) -> Self {
self.inner.version = version;
self
}
#[must_use]
pub fn with_domain(mut self, domain: String) -> Self {
self.inner.domain = domain;
self
}
#[must_use]
pub const fn with_compression(mut self, compression: Compression) -> Self {
self.inner.encoding = compression;
self
}
#[must_use]
pub const fn with_encoding(mut self, encoding: Encoding) -> Self {
self.inner.format = encoding;
self
}
}
impl From<VkApiBuilder> for VkApi {
fn from(builder: VkApiBuilder) -> Self {
Self::from_inner(builder.inner)
}
}