hydrus_api/lib.rs
1//! ## About
2//! This crate provides a rust wrapper for the hydrus client API. All request require an access
3//! token that can be retrieved in the hydrus client from the *review services* dialog.
4//! Different actions require different permissions, you can read about it in the [official docs](https://hydrusnetwork.github.io/hydrus/help/client_api.html).
5//!
6//! Starting with hydrus version 477, CBOR can be used as an alternative to JSON.
7//! CBOR support can be enabled with the `cbor` feature of this crate. This feature is
8//! incompatible with the `json` feature which is enabled by default.
9//!
10//! ## Hydrus Usage Example
11//!
12//! ```
13//! use hydrus_api::{Hydrus, Client};
14//! use std::env;
15//! use hydrus_api::wrapper::tag::Tag;
16//! use hydrus_api::wrapper::service::ServiceName;
17//! use hydrus_api::wrapper::hydrus_file::FileStatus;
18//! use hydrus_api::wrapper::page::PageIdentifier;
19//! use hydrus_api::wrapper::builders::tag_builder::{SystemTagBuilder, Comparator};
20//! use hydrus_api::wrapper::builders::search_builder::SortType;
21//! use hydrus_api::wrapper::builders::or_chain_builder::OrChainBuilder;
22//!
23//! # #[tokio::test]
24//! # async fn doctest() {
25//! let hydrus_url = env::var("HYDRUS_URL").unwrap();
26//! let access_key = env::var("HYDRUS_ACCESS_KEY").unwrap();
27//! let hydrus = Hydrus::new(Client::new(hydrus_url, access_key));
28//! let files = hydrus.search()
29//! .add_tag(Tag::from("character:megumin"))
30//! .add_tag(SystemTagBuilder::new().archive().build())
31//! .add_tag(SystemTagBuilder::new()
32//! .tag_namespace_as_number("page", Comparator::Equal, 5).negate().build())
33//! .add_or_chain(
34//! OrChainBuilder::new()
35//! .add_tag("summer".into())
36//! .add_tag("winter".into())
37//! .build(),
38//! )
39//! .sort_by(SortType::NumberOfPixels)
40//! .sort_descending()
41//! .run().await.unwrap();
42//!
43//! for mut file in files {
44//! file.add_tags(ServiceName::my_tags().into(), vec![Tag::from("ark mage")]).await.unwrap();
45//! }
46//!
47//! let url = hydrus.import()
48//! .url("https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium")
49//! .page(PageIdentifier::name("My Import Page"))
50//! .add_additional_tag(ServiceName::my_tags().into(), Tag::from("character:megumin"))
51//! .show_page(true)
52//! .run().await.unwrap();
53//! # }
54//! ```
55//!
56//! ## Client Usage Example
57//! ```
58//! use hydrus_api::Client;
59//! use hydrus_api::api_core::endpoints::adding_tags::{AddTagsRequestBuilder, TagAction};
60//! use std::env;
61//! use hydrus_api::api_core::common::ServiceIdentifier;
62//! # #[tokio::test]
63//! # async fn doctest() {
64//!
65//! Client::new(
66//! env::var("HYDRUS_URL").unwrap(),
67//! env::var("HYDRUS_ACCESS_KEY").unwrap(),
68//! );
69//! // let's first import a file
70//! let hash = client.add_file("/path/to/my/file").await.unwrap().hash;
71//!
72//! // and now let's add tags to it
73//! let request = AddTagsRequestBuilder::default()
74//! .add_hash(hash)
75//! // for each tag the service has to be specified
76//! .add_tags(ServiceIdentifier::name("my tags"), vec!["beach".into(), "summer".into()])
77//! // with tag actions tags can also be removed. It's especially useful for the PTR
78//! .add_tag_with_action(ServiceIdentifier::name("my tags"), "rain", TagAction::DeleteFromLocalService)
79//! .build();
80//!
81//! client.add_tags(request).await.unwrap();
82//! # }
83//! ```
84
85#[macro_use]
86extern crate serde;
87
88pub use api_core::client::Client;
89pub use wrapper::hydrus::Hydrus;
90
91pub mod api_core;
92pub mod error;
93pub mod utils;
94pub mod wrapper;
95
96#[cfg(all(feature = "cbor", feature = "json"))]
97compile_error!("Feature 'cbor' and 'json' cannot be enabled at the same time");
98
99#[cfg(not(any(feature = "cbor", feature = "json")))]
100compile_error!("Either the 'json' or 'cbor' feature must be selected.");