-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
conditional_requests.rs
44 lines (36 loc) · 1.29 KB
/
conditional_requests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#[cfg(feature = "httpcache")]
use hubcaps::{Github, HttpCache};
#[cfg(feature = "httpcache")]
use reqwest::Client;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
pretty_env_logger::init();
#[cfg(not(feature = "httpcache"))]
{
println!("rerun this example with `cargo run --no-default-features --features default-tls,httpcache --example conditional_requests`");
Ok(())
}
#[cfg(feature = "httpcache")]
{
let host = "https://api.github.com";
let agent = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
let client = Client::builder().build()?;
let http_cache = HttpCache::in_home_dir();
let github = Github::custom(host, agent, None, client, http_cache);
let _repos = github
.user_repos("dwijnand")
.list(&Default::default())
.await?;
let status1 = github.rate_limit().get().await?;
let _repos = github
.user_repos("dwijnand")
.list(&Default::default())
.await?;
let status2 = github.rate_limit().get().await?;
let rem1 = status1.resources.core.remaining;
let rem2 = status2.resources.core.remaining;
assert_eq!(rem1, rem2);
Ok(())
}
}