torznab_toolkit/notes/
tutorial.rs

1//! ## Structure of the program using this library
2//!
3//! First off, you should create a search function. This function will handle all search types, with what type being specified in the parameter's `search_type` field (`search`, `tv-search`, `movie-search`, `audio-search`, or `movie-search`). Given those parameters, the search function then returns a [`Result`]<[`Vec`]<[`Torrent`]>, [`String`]> object.
4//! The torrents will be listed by the API in the order they're returned here
5//!
6//! ```
7//! use torznab_toolkit::data::{SearchParameters, Torrent};
8//!
9//! fn search(parameters: SearchParameters) -> Result<Vec<Torrent>, String> {
10//!     return Ok(vec![Torrent {
11//!         title: "totally normal torrent".to_string(),
12//!         description: None,
13//!         size: 2484345508,
14//!         category_ids: vec![1010],
15//!         torrent_file_url: Some("http://localhost/totally-normal.torrent".to_string()),
16//!         magnet_uri: Some("magnet:?xt=urn:btih:blahblahblahdothechachacha".to_string()),
17//!         other_attributes: None,
18//!     }]);
19//! }
20//! ```
21//!
22//! If you want authentication, you can also create a function for that; returning true indicates that the apikey is valid.
23//!
24//! ```
25//! fn auth(apikey: String) -> Result<bool, String> {
26//!     if apikey == "letmein".to_string() {    
27//!         return Ok(true);
28//!     }
29//!     return Ok(false);
30//! }
31//! ```
32//!
33//! Now you need to configure torznab-toolkit using a [`Config`] object. In total, you'll need the following objects for the config:
34//! - The search function
35//! - The API function (optional)
36//! - The capabilities of the server - i.e.  ([`Caps`])
37//!
38//! Most of the config will be part of [`Caps`]. For details on all these, just check out the doc pages for each of the fields.
39//!
40//! With all that, you can now start up the server, which is simple:
41//!
42//! ```
43//! use torznab_toolkit;
44//! let config: torznab_toolkit::data::Config = /* config goes here */
45//!
46//! torznab_toolkit::run(config).await.unwrap();
47//! ```
48//!
49//! To easily change what address is listens on and what port, you can use the `ROCKET_ADDRESS` and `ROCKET_PORT` environment variables; the defaults are `127.0.0.1` and `8000`.
50//! For more details on configuring Rocket, see the [Configuration](https://rocket.rs/guide/v0.5/configuration/) page in Rocket's docs - you can also use a `Rocket.toml` file.
51
52// imports for the docs
53use crate::data::*;
54use crate::run;