use crate::base::TMDB;
use std::collections::HashMap;
use serde_json::Value;
pub struct People {
tmdb: TMDB,
id: Option<i32>,
}
impl People {
pub fn new(id: Option<i32>) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "person".to_string();
tmdb.urls = [
("info".to_string(), "/{id}".to_string()),
("changes".to_string(), "/{id}/changes".to_string()),
("movie_credits".to_string(), "/{id}/movie_credits".to_string()),
("tv_credits".to_string(), "/{id}/tv_credits".to_string()),
("combined_credits".to_string(), "/{id}/combined_credits".to_string()),
("external_ids".to_string(), "/{id}/external_ids".to_string()),
("images".to_string(), "/{id}/images".to_string()),
("tagged_images".to_string(), "/{id}/tagged_images".to_string()),
("translations".to_string(), "/{id}/translations".to_string()),
("latest".to_string(), "/latest".to_string()),
("popular".to_string(), "/popular".to_string()),
]
.iter()
.cloned()
.collect();
People { tmdb, id }
}
pub fn _get_id_path(&self, key: &str) -> String {
if let Some(id) = self.id {
self.tmdb._get_path(key).replace("{id}", &id.to_string())
} else {
self.tmdb._get_path(key).to_string()
}
}
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 async fn changes(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("changes");
self.tmdb._get(&path, options).await
}
pub async fn movie_credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("movie_credits");
self.tmdb._get(&path, options).await
}
pub async fn tv_credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("tv_credits");
self.tmdb._get(&path, options).await
}
pub async fn combined_credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("combined_credits");
self.tmdb._get(&path, options).await
}
pub async fn external_ids(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("external_ids");
self.tmdb._get(&path, options).await
}
pub async fn images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("images");
self.tmdb._get(&path, options).await
}
pub async fn tagged_images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("tagged_images");
self.tmdb._get(&path, options).await
}
pub async fn translations(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self._get_id_path("translations");
self.tmdb._get(&path, options).await
}
pub async fn latest(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self.tmdb._get_path("latest");
self.tmdb._get(&path, options).await
}
pub async fn popular(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let path = self.tmdb._get_path("popular");
self.tmdb._get(&path, options).await
}
}
pub struct Credits {
tmdb: TMDB,
credit_id: String,
}
impl Credits {
pub fn new(credit_id: String) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "credit".to_string();
tmdb.urls = [("info".to_string(), "/{credit_id}".to_string())]
.iter()
.cloned()
.collect();
Credits { tmdb, credit_id }
}
pub fn _get_credit_id_path(&self, key: &str) -> String {
self.tmdb.base_path.replace("{credit_id}", &self.credit_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_credit_id_path("info");
self.tmdb._get(&path, options).await
}
}