codeforces_api/lib.rs
1#![allow(clippy::needless_doctest_main)]
2
3//! codeforces-api crate - interact with the
4//! [Codeforces](https://codeforces.com/) API.
5//!
6//! This crate uses the [official API](https://codeforces.com/apiHelp) of the
7//! Codeforces platform.
8//!
9//! As of this version, an API key and secret is required with every request
10//! made. Instructions to generate these can be found
11//! [here](https://codeforces.com/apiHelp) (in the Authorization section).
12//!
13//! This crate solely uses `reqwest`'s blocking network client meaning that all
14//! requests made through this crate are also blocking. No client object is
15//! provided with this crate and thus no rate-limiting provided. This could
16//! also impact performance since a new `reqwest` client is created and
17//! destroyed with every network interaction.
18//!
19//! # Usage
20//!
21//! ```no_run
22//! use codeforces_api::requests::{CFBlogEntryCommand, CFAPIRequestable};
23//! use codeforces_api::responses::CFResult;
24//!
25//! fn main() {
26//! // This is equivalent to the Codeforces `blogEntry.view` API method.
27//! let x = CFBlogEntryCommand::View {
28//! blog_entry_id: 82347,
29//! };
30//!
31//! // The `.get(..)` method on API commands returns a result with either
32//! // an error or an `Ok(CFResult)`.
33//! match x.get("<api_key>", "<api_secret>") {
34//! Ok(CFResult::CFBlogEntry(blog_entry)) => {
35//! assert_eq!(blog_entry.id, 82347);
36//! println!("Your blog entry: {:?}", blog_entry);
37//! },
38//! Ok(_) => {
39//! // In very rare cases, an unexpected type may be returned by
40//! // `.get()`. If this happens, then you may wish to throw a
41//! // custom error.
42//! panic!("`.get()` returned an unexpected type.");
43//! }
44//! Err(e) => {
45//! // Errors returned are of a custom Error type. This could be
46//! // returned if, for example, an invalid API key/secret was used
47//! // or if there was no internet connection.
48//! panic!("something failed {:?}", e);
49//! }
50//! }
51//! }
52//! ```
53
54mod obj;
55pub use obj::error::Error;
56pub use obj::{requests, responses};
57
58#[cfg(test)]
59mod test;
60
61#[doc(hidden)]
62/// Testing api key not to be abused, refers to user "MikeWazowski". Not to be
63/// abused.
64pub const TEST_API_KEY: &str = "7dd1c6a92bf0a6cb22b0e9fa9c08d1dac4948023";
65#[doc(hidden)]
66/// Testing api secret not to be abused, refers to user "MikeWazowski". Not to
67/// be abused.
68pub const TEST_API_SECRET: &str = "acc9a26087164935d62610ed693c063463e123c2";