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 Genres {
    tmdb: TMDB,
    id: i32,
}

impl Genres {
    pub fn new(id: Option<i32>) -> Self {
        let mut tmdb = TMDB::new();
        tmdb.base_path = "genre".to_string();
        tmdb.urls = [
            ("movie_list".to_string(), "/movie/list".to_string()),
            ("tv_list".to_string(), "/tv/list".to_string()),
            ("movies".to_string(), "/{id}/movies".to_string()),
        ]
        .iter()
        .cloned()
        .collect();
        Genres { tmdb, id: id.unwrap_or(0) }
    }

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

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

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

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