-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_account.rs
More file actions
33 lines (27 loc) · 1.29 KB
/
Copy pathget_account.rs
File metadata and controls
33 lines (27 loc) · 1.29 KB
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
//! Get the current account's details and monthly usage.
//!
//! Run with: `APIFY_TOKEN=... cargo run --example get_account`
use apify_client::ApifyClient;
use chrono::Utc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let token = std::env::var("APIFY_TOKEN").expect("set APIFY_TOKEN");
let client = ApifyClient::new(token);
let user = client.me().get().await?.expect("current user");
println!("Account id: {}", user.id);
println!("Username: {:?}", user.username);
// Monthly usage for the current billing cycle (`None` == current cycle).
let usage = client.me().monthly_usage().await?;
if let Some(cycle) = usage.get("usageCycle") {
println!("Current usage cycle: {cycle}");
}
// Usage for the billing cycle that contains a specific `YYYY-MM-DD` date — pass `Some(date)`
// to look up a particular cycle, or `None` for the current one. We derive the date from the
// current day (rather than hard-coding one) so the lookup always lands on a real cycle.
let date = Utc::now().format("%Y-%m-%d").to_string();
let dated_usage = client.me().monthly_usage_for_date(Some(&date)).await?;
if let Some(cycle) = dated_usage.get("usageCycle") {
println!("Usage cycle containing {date}: {cycle}");
}
Ok(())
}