Crate eiga

source · []
Expand description

A synchronous TMDB API client.

Usage

To send a request you need the client, Tmdb, and an endpoint struct. Tmdb has multiple methods for sending requests. Each of them takes an endpoint struct.

For each TMDB API endpoint there’s a corresponding struct. An endpoint’s request path corresponds to the struct’s module path. For example, the struct for the endpoint with path /movie/{movie_id}/alternative_titles is movie::AlternativeTitles.

Example

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 to set 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(())
}

Modules

Movies API endpoints.

Search API endpoints.

Structs

The response type of pageable endpoints.

A pageable results iterator.

A helper type for collecting query string parameters.

A client for sending requests to the TMDB API.

A query string parameter value.

Enums

The possible errors that can occur when sending requests.

Traits

A trait for sending requests to endpoints.

A trait for endpoint objects.

A trait for pageable endpoint objects.