refactor!: refactored response models

doc: documented all public methods
This commit is contained in:
ThetaDev 2022-12-09 01:01:25 +01:00
parent 4c1876cb55
commit f526ab38eb
37 changed files with 600 additions and 255 deletions

View file

@ -7,16 +7,31 @@ use std::{
use log::error;
/// RustyPipe has to cache some information fetched from YouTube: specifically
/// the client versions and the JavaScript code used to deobfuscate the stream URLs.
///
/// This trait is used to abstract the cache storage behavior so you can store
/// cache data in your preferred way (File, SQL, Redis, etc).
///
/// The cache is read when building the [`crate::client::RustyPipe`] client and updated
/// whenever additional data is fetched.
pub trait CacheStorage: Sync + Send {
/// Write the given string to the cache
fn write(&self, data: &str);
/// Read the string from the cache
///
/// Returns [`None`] when the cache is empty or the reading failed.
fn read(&self) -> Option<String>;
}
/// [`CacheStorage`] implementation that writes the cache to a JSON file
/// at the given location.
pub struct FileStorage {
path: PathBuf,
}
impl FileStorage {
/// Create a new JSON-file based cache storage
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self {
path: path.as_ref().to_path_buf(),