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 Find {
    tmdb: TMDB,
    id: String,
}

impl Find {
    pub fn new(id: String) -> Self {
        let mut tmdb = TMDB::new();
        tmdb.base_path = "find".to_string();
        tmdb.urls
            .insert("info".to_string(), "/{id}".to_string());
        Find { tmdb, id }
    }

    pub fn _get_id_path(&self, key: &str) -> String {
        self.tmdb._get_path(key).replace("{id}", &self.id)
    }

    pub async fn info(
        &self,
        options: Option<HashMap<String, String>>,
    ) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
        let path = self._get_id_path("info");
        self.tmdb._get(&path, options).await
    }
}

pub struct Trending {
    tmdb: TMDB,
    media_type: String,
    time_window: String,
}

impl Trending {
    pub fn new(media_type: Option<String>, time_window: Option<String>) -> Self {
        let mut tmdb = TMDB::new();
        tmdb.base_path = "trending".to_string();
        tmdb.urls.insert(
            "info".to_string(),
            "/{media_type}/{time_window}".to_string(),
        );
        Trending {
            tmdb,
            media_type: media_type.unwrap_or_else(|| "all".to_string()),
            time_window: time_window.unwrap_or_else(|| "day".to_string()),
        }
    }

    pub fn _get_media_type_time_window_path(&self, key: &str) -> String {
        self.tmdb
            ._get_path(key)
            .replace("{media_type}", &self.media_type)
            .replace("{time_window}", &self.time_window)
    }

    pub async fn info(
        &self,
        options: Option<HashMap<String, String>>,
    ) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
        let path = self._get_media_type_time_window_path("info");
        self.tmdb._get(&path, options).await
    }
}