shindan_maker/
lib.rs

1/*!
2[![GitHub]](https://github.com/araea/shindan-maker) [![crates-io]](https://crates.io/crates/shindan-maker) [![docs-rs]](crate)
3
4[GitHub]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
5[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
6[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
7
8<br>
9
10A Rust library for interacting with [ShindanMaker].
11
12This library provides functionality to interact with various ShindanMaker domains, submit shindans, and parse results.
13
14- Asynchronous API (Tokio)
15- Multi-domain support (JP, EN, CN, KR, TH)
16- Easy shindan submission and result parsing
17
18[ShindanMaker]: https://en.shindanmaker.com/
19
20## Example
21
22### Get title
23
24```rust
25use anyhow::Result;
26use shindan_maker::{ShindanClient, ShindanDomain};
27
28#[tokio::main]
29async fn main() -> Result<()> {
30    let client = ShindanClient::new(ShindanDomain::En)?; // Enum variant
31    // let client = ShindanClient::new("Jp".parse()?)?; // String slice
32    // let client = ShindanClient::new("EN".parse()?)?; // Case-insensitive
33    // let client = ShindanClient::new(String::from("cn").parse()?)?; // String
34
35    let title = client
36        .get_title("1222992")
37        .await?;
38
39    assert_eq!("Fantasy Stats", title);
40    Ok(())
41}
42```
43
44### Get segments (need "segments" feature)
45
46```rust
47use shindan_maker::{ShindanClient, ShindanDomain};
48
49#[tokio::main]
50async fn main() {
51    let client = ShindanClient::new(ShindanDomain::En).unwrap();
52
53    let (segments, title) = client
54        .get_segments_with_title("1222992", "test_user")
55        .await
56        .unwrap();
57
58    assert_eq!("Fantasy Stats", title);
59
60    println!("Result title: {}", title);
61    println!("Result text: {}", segments);
62
63    println!("Result segments: {:#?}", segments);
64}
65```
66
67### Get HTML string (need "html" feature)
68
69- HTML string to image: [cdp-html-shot](https://crates.io/crates/cdp-html-shot).
70
71```rust
72#[tokio::main]
73async fn main() {
74    #[cfg(feature = "html")]
75    {
76        use shindan_maker::{ShindanClient, ShindanDomain};
77        let client = ShindanClient::new(ShindanDomain::En).unwrap();
78
79        let (_html_str, title) = client
80            .get_html_str_with_title("1222992", "test_user")
81            .await
82            .unwrap();
83
84        assert_eq!("Fantasy Stats", title);
85    }
86}
87```
88*/
89
90mod client;
91mod selectors;
92mod html_utils;
93mod http_utils;
94mod shindan_domain;
95#[cfg(feature = "segments")]
96mod segment;
97#[cfg(feature = "html")]
98mod html_template;
99
100pub use client::ShindanClient;
101pub use shindan_domain::ShindanDomain;
102#[cfg(feature = "segments")]
103pub use segment::{Segment, Segments};
104
105#[cfg(test)]
106mod tests {
107    use crate::{ShindanClient, ShindanDomain};
108    use tokio;
109
110    #[tokio::test]
111    async fn test_get_title() {
112        let client = ShindanClient::new(ShindanDomain::En).unwrap();
113
114        let (title, _desc) = client.
115            get_title_with_description("1222992")
116            .await
117            .unwrap();
118
119        assert_eq!("Fantasy Stats", title);
120    }
121
122    #[cfg(feature = "segments")]
123    #[tokio::test]
124    async fn test_get_segments() {
125        let client = ShindanClient::new(ShindanDomain::En).unwrap();
126
127        let (_segments, title) = client
128            .get_segments_with_title("1222992", "test_user")
129            .await
130            .unwrap();
131
132        assert_eq!("Fantasy Stats", title);
133    }
134
135    #[cfg(feature = "html")]
136    #[tokio::test]
137    async fn test_get_html_str() {
138        let client = ShindanClient::new(ShindanDomain::En).unwrap();
139
140        let (_html_str, title) = client
141            .get_html_str_with_title("1222992", "test_user")
142            .await
143            .unwrap();
144
145        assert_eq!("Fantasy Stats", title);
146    }
147}