Skip to content

Commit

Permalink
added delay arg
Browse files Browse the repository at this point in the history
  • Loading branch information
splurf committed Jan 16, 2024
1 parent a93261e commit 3fe71ed
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ use {
json::{Body, DnsRecord, DnsRecordResult, PublicIpAPI},
},
clap::Parser,
humantime::parse_duration,
reqwest::{
blocking::{Client, RequestBuilder},
header::CONTENT_TYPE,
Method,
},
std::net::IpAddr,
std::{net::IpAddr, thread::sleep, time::Duration},
};

#[derive(Parser, Debug)]
#[derive(Parser)]
#[command(author, version, about)]
struct Config {
#[arg(short, long)]
Expand All @@ -26,12 +27,16 @@ struct Config {

#[arg(short, long)]
id: String,

#[arg(short, long, value_parser = parse_duration, default_value = "5min")]
delay: Duration,
}

pub struct BaseClient {
client: Client,
body: Body,
builder_fn: Box<dyn Fn(Method, &Client) -> RequestBuilder>,
delay: Duration,
}

impl BaseClient {
Expand All @@ -47,7 +52,9 @@ impl BaseClient {
api_token,
zone_id,
id,
delay,
} = Config::parse();

let client = Client::default();
let builder_fn = Box::new(move |method: Method, client: &Client| -> RequestBuilder {
client
Expand All @@ -68,6 +75,7 @@ impl BaseClient {
client,
body,
builder_fn,
delay,
})
}

Expand All @@ -94,6 +102,10 @@ impl BaseClient {
.ok_or(Error::API)
}

pub fn delay(&self) {
sleep(self.delay)
}

fn request(
method: Method,
client: &Client,
Expand Down

0 comments on commit 3fe71ed

Please sign in to comment.