Spaces:
Paused
Paused
Download api/src/services/omdb.rs from stremio-db/a: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/stremio-db/a/resolve/main/api/src/services/omdb.rs
- Command line
-
hf download hf://spaces/stremio-db/a/api/src/services/omdb.rs
-
curl -L -o omdb.rs https://huggingface.co/spaces/stremio-db/a/resolve/main/api/src/services/omdb.rs
1.32 kB
| use std::sync::Arc; | |
| use crate::error::AppError; | |
| use crate::services::retry::{self, OMDB_RETRY}; | |
| use serde::Deserialize; | |
| use zeroize::Zeroizing; | |
| pub struct OmdbClient { | |
| api_key: Arc<Zeroizing<String>>, | |
| http: reqwest::Client, | |
| } | |
| pub struct OmdbResponse { | |
| pub ratings: Vec<OmdbRating>, | |
| pub imdb_rating: Option<String>, | |
| pub metascore: Option<String>, | |
| } | |
| pub struct OmdbRating { | |
| pub source: String, | |
| pub value: String, | |
| } | |
| impl OmdbClient { | |
| pub fn new(api_key: String, http: reqwest::Client) -> Self { | |
| Self { api_key: Arc::new(Zeroizing::new(api_key)), http } | |
| } | |
| pub async fn get_ratings(&self, imdb_id: &str) -> Result<OmdbResponse, AppError> { | |
| let imdb_id = imdb_id.to_owned(); | |
| let resp = retry::send_with_retry(&OMDB_RETRY, || { | |
| self.http | |
| .get("https://www.omdbapi.com/") | |
| .query(&[("apikey", self.api_key.as_str()), ("i", imdb_id.as_str())]) | |
| .send() | |
| }) | |
| .await? | |
| .error_for_status()?; | |
| Ok(resp.json().await?) | |
| } | |
| } | |