TheMovieDB 0.1.0

A robust and idiomatic Rust API wrapper for The Movie Database (TMDb) v3 API.
Documentation
use crate::base::TMDB;
use std::collections::HashMap;
use serde_json::Value;

pub struct Discover {
    tmdb: TMDB,
}

impl Discover {
    pub fn new() -> Self {
        let mut tmdb = TMDB::new();
        tmdb.base_path = "discover".to_string();
        tmdb.urls = [("movie".to_string(), "/movie".to_string()), ("tv".to_string(), "/tv".to_string())]
            .iter()
            .cloned()
            .collect();
        Discover { tmdb }
    }

    fn handle_options(&self, options: &mut HashMap<String, String>) {
        let keys: Vec<String> = options.keys().cloned().collect();
        for key in keys {
            if key.contains("_gte") {
                let new_key = key.replace("_gte", ".gte");
                if let Some(value) = options.remove(&key) {
                    options.insert(new_key, value);
                }
            } else if key.contains("_lte") {
                let new_key = key.replace("_lte", ".lte");
                if let Some(value) = options.remove(&key) {
                    options.insert(new_key, value);
                }
            }
        }
    }

    pub async fn movie(&self, mut options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
        let path = self.tmdb._get_path("movie");
        if let Some(ref mut opts) = options {
            self.handle_options(opts);
        }
        self.tmdb._get(&path, options).await
    }

    pub async fn tv(&self, mut options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
        let path = self.tmdb._get_path("tv");
        if let Some(ref mut opts) = options {
            self.handle_options(opts);
        }
        self.tmdb._get(&path, options).await
    }
}