Crates.io | eiga |
lib.rs | eiga |
version | 0.3.0 |
source | src |
created_at | 2022-08-29 00:15:16.692411 |
updated_at | 2022-09-11 20:23:59.16694 |
description | A WIP TMDB API client |
homepage | |
repository | https://github.com/zachcmadsen/eiga |
max_upload_size | |
id | 654103 |
size | 79,426 |
eiga
is a WIP TMDB API client.
eiga
is usable, but it doesn't cover much of the TMDB API yet.
Add eiga
as a dependency in your Cargo.toml
:
[dependencies]
eiga = "0.3.0"
This example shows how to get details about a movie. You can find other
examples in the examples
folder.
use std::env;
use std::error::Error;
use serde::Deserialize;
use eiga::{movie, Client, Tmdb};
// eiga doesn't provide types for endpoint responses. Instead, users provide
// their own structs to deserialize into.
#[derive(Deserialize)]
struct MovieDetails {
release_date: String,
title: String,
}
fn main() -> Result<(), Box<dyn Error>> {
// Create a TMDB client by providing an API access token. Here, the token
// is stored in the TMDB_TOKEN environment variable.
let token = env::var("TMDB_TOKEN")?;
let tmdb = Tmdb::new(token);
// Build an endpoint to get details about "Tokyo Drifter" (1966). Each
// endpoint has setter methods for optional query string parameters.
let tokyo_drifter_id = 45706;
let movie_details_endpoint =
movie::Details::new(tokyo_drifter_id).language("en-US");
// Send the request! Type annotations are required because `send` can
// deserialize the response to any type that implements `Deserialize`.
let movie_details: MovieDetails = tmdb.send(&movie_details_endpoint)?;
assert_eq!(movie_details.title, "Tokyo Drifter");
assert_eq!(movie_details.release_date, "1966-04-10");
Ok(())
}