letterboxd/lib.rs
1#![deny(missing_docs, missing_debug_implementations)]
2
3//! This crate wraps the Letterboxd API which provides easy and flexible
4//! access to data on the Letterboxd.com website.
5//!
6//! The [client](struct.Client.html)'s API follows the following rules:
7//!
8//! * All Letterboxd API calls are asynchronous.
9//! * A client is always created from API key and secret. If auth token,
10//! is provided, client calls will be authenticated. Client can be
11//! created from username/password. A token can be set after client was created.
12//! * API key and secret can be created from default environment variables.
13//! * Except GET calls all methods include a path parameter.
14//!
15//! Further, most of the [Client](struct.Client.html)'s methods take a request
16//! struct, which is then serialized to url encoded parameters, and return a
17//! response type, which is deserialized from JSON. However, some methods omit
18//! the request or/and the response struct.
19//!
20//! Entities are identified in the API by Letterboxd ID (or LID), an
21//! alpha-numeric string value that is returned where appropriate. For films,
22//! lists and reviews, the LID can also be found through the Letterboxd website
23//! as the path portion of the entity’s shareable boxd.it link.
24//!
25//! For more information, cf. API docs at <http://api-docs.letterboxd.com>.
26//!
27//! # Examples
28//!
29//! Client without authentication:
30//!
31//! ```rust,no_run
32//! async fn list_films() -> letterboxd::Result<()> {
33//! let api_key_pair = letterboxd::ApiKeyPair::from_env().unwrap();
34//! let client = letterboxd::Client::new(api_key_pair);
35//!
36//! let req = letterboxd::FilmsRequest {
37//! per_page: Some(1),
38//! ..Default::default()
39//! };
40//! let resp = client.films(&req).await?;
41//! println!("{:?}", resp);
42//!
43//! Ok(())
44//! }
45//! ```
46//!
47//! Create and authenticate client with username/password:
48//!
49//! ```rust,no_run
50//! async fn update_film_relationship() -> letterboxd::Result<()> {
51//! let api_key_pair = letterboxd::ApiKeyPair::from_env().unwrap();
52//! let username = std::env::var("LETTERBOXD_USERNAME").unwrap();
53//! let password = std::env::var("LETTERBOXD_PASSWORD").unwrap();
54//!
55//! let client = letterboxd::Client::authenticate(api_key_pair, &username, &password).await?;
56//! // token can be retrieved after authentication for e.g. caching it on disk
57//! println!("{:?}", client.token().unwrap());
58//!
59//! let req = letterboxd::FilmRelationshipUpdateRequest {
60//! watched: Some(true),
61//! ..Default::default()
62//! };
63//! client.update_film_relationship("2a9q", &req).await?; // Fight Club
64//!
65//! Ok(())
66//! }
67//! ```
68
69mod client;
70mod defs;
71mod error;
72
73pub use client::{ApiKeyPair, Client};
74pub use defs::*;
75pub use error::{Error, Result};