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;

macro_rules! tmdb_struct {
    ($name:ident, $base_path:literal, { $($url_key:literal => $url_val:literal),* $(,)? }) => {
        pub struct $name {
            tmdb: TMDB,
        }

        impl $name {
            pub fn new() -> Self {
                let mut tmdb = TMDB::new();
                tmdb.base_path = $base_path.to_string();
                tmdb.urls = [
                    $(($url_key.to_string(), $url_val.to_string())),*
                ]
                .iter()
                .cloned()
                .collect();
                $name { tmdb }
            }
        }
    };
}

macro_rules! tmdb_method_get {
    ($struct_name:ident, $method_name:ident, $url_key:literal) => {
        impl $struct_name {
            pub async fn $method_name(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
                let path = self.tmdb._get_path($url_key);
                self.tmdb._get(&path, options).await
            }
        }
    };
}

tmdb_struct!(Configuration, "configuration", {
    "info" => "",
    "countries" => "/countries",
    "jobs" => "/jobs",
    "languages" => "/languages",
    "primary_translations" => "/primary_translations",
    "timezones" => "/timezones",
});

tmdb_method_get!(Configuration, info, "info");
tmdb_method_get!(Configuration, countries, "countries");
tmdb_method_get!(Configuration, jobs, "jobs");
tmdb_method_get!(Configuration, languages, "languages");
tmdb_method_get!(Configuration, primary_translations, "primary_translations");
tmdb_method_get!(Configuration, timezones, "timezones");

tmdb_struct!(Certifications, "certification", {
    "movie_list" => "/movie/list",
    "tv_list" => "/tv/list",
});

tmdb_method_get!(Certifications, movie_list, "movie_list");
tmdb_method_get!(Certifications, tv_list, "tv_list");

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