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;
91#[cfg(feature = "html")]
92mod html_template;
93mod html_utils;
94mod http_utils;
95#[cfg(feature = "segments")]
96mod segment;
97mod selectors;
98mod shindan_domain;
99
100pub use client::ShindanClient;
101#[cfg(feature = "segments")]
102pub use segment::{Segment, Segments};
103pub use shindan_domain::ShindanDomain;
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.get_title_with_description("1222992").await.unwrap();
115
116 assert_eq!("Fantasy Stats", title);
117 }
118
119 #[cfg(feature = "segments")]
120 #[tokio::test]
121 async fn test_get_segments() {
122 let client = ShindanClient::new(ShindanDomain::En).unwrap();
123
124 let (_segments, title) = client
125 .get_segments_with_title("1222992", "test_user")
126 .await
127 .unwrap();
128
129 assert_eq!("Fantasy Stats", title);
130 }
131
132 #[cfg(feature = "html")]
133 #[tokio::test]
134 async fn test_get_html_str() {
135 let client = ShindanClient::new(ShindanDomain::En).unwrap();
136
137 let (_html_str, title) = client
138 .get_html_str_with_title("1222992", "test_user")
139 .await
140 .unwrap();
141
142 assert_eq!("Fantasy Stats", title);
143 }
144}