From 81799258b00fcce7493389645fc620157c90617c Mon Sep 17 00:00:00 2001 From: hewigovens <360470+hewigovens@users.noreply.github.com> Date: Fri, 4 Oct 2024 21:31:49 +0900 Subject: [PATCH] allow dynamic path --- Cargo.lock | 4 ++-- Cargo.toml | 5 ++--- examples/ethereum-rpc/src/ethereum_rpc.rs | 4 ++-- reqwest-enum/src/provider.rs | 16 +++++++++++----- reqwest-enum/src/target.rs | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12364b7..7ede3c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,7 @@ dependencies = [ [[package]] name = "ethereum-rpc" -version = "0.3.1" +version = "0.3.2" dependencies = [ "reqwest", "reqwest-enum", @@ -749,7 +749,7 @@ dependencies = [ [[package]] name = "reqwest-enum" -version = "0.3.1" +version = "0.3.2" dependencies = [ "futures", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 7e394e4..e9b4526 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -package.version = "0.3.1" +package.version = "0.3.2" package.edition = "2021" package.documentation = "https://docs.rs/reqwest_enum" package.authors = ["Tao Xu "] @@ -11,10 +11,9 @@ resolver = "2" [workspace.dependencies] reqwest-enum = { path = "./reqwest-enum" } -reqwest = { version = "^0.12.0", features = ["json"] } +reqwest = { version = "^0.12.0", features = ["json"] } serde = { version = "^1.0.0", features = ["derive"] } serde_json = "^1.0.0" - futures = "^0.3.0" tokio-test = "0.4.2" diff --git a/examples/ethereum-rpc/src/ethereum_rpc.rs b/examples/ethereum-rpc/src/ethereum_rpc.rs index 8c0949e..4596a9d 100644 --- a/examples/ethereum-rpc/src/ethereum_rpc.rs +++ b/examples/ethereum-rpc/src/ethereum_rpc.rs @@ -150,8 +150,8 @@ impl Target for EthereumRPC { HTTPMethod::POST } - fn path(&self) -> &'static str { - "/eth" + fn path(&self) -> String { + "/eth".into() } fn query(&self) -> HashMap<&'static str, &'static str> { diff --git a/reqwest-enum/src/provider.rs b/reqwest-enum/src/provider.rs index 3fdf979..fa15e24 100644 --- a/reqwest-enum/src/provider.rs +++ b/reqwest-enum/src/provider.rs @@ -239,7 +239,9 @@ mod tests { use std::collections::hash_map::DefaultHasher; use std::collections::HashMap; use std::hash::{Hash, Hasher}; + use std::time::{Duration, UNIX_EPOCH}; use tokio_test::block_on; + #[derive(Serialize, Deserialize)] struct Person { name: String, @@ -266,11 +268,15 @@ mod tests { } } - fn path(&self) -> &'static str { + fn path(&self) -> String { + let ts = UNIX_EPOCH + Duration::from_secs(1728044812); match self { - HttpBin::Get => "/get", - HttpBin::Post => "/post", - HttpBin::Bearer => "/bearer", + HttpBin::Get => format!( + "/get?ts={}", + ts.duration_since(UNIX_EPOCH).unwrap().as_secs(), + ), + HttpBin::Post => "/post".into(), + HttpBin::Bearer => "/bearer".into(), } } @@ -306,7 +312,7 @@ mod tests { let provider = Provider::::default(); assert_eq!( provider.request_url(&HttpBin::Get), - "https://httpbin.org/get" + "https://httpbin.org/get?ts=1728044812" ); let provider = diff --git a/reqwest-enum/src/target.rs b/reqwest-enum/src/target.rs index 3f24764..d3d7312 100644 --- a/reqwest-enum/src/target.rs +++ b/reqwest-enum/src/target.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; pub trait Target { fn base_url(&self) -> &'static str; fn method(&self) -> HTTPMethod; - fn path(&self) -> &'static str; + fn path(&self) -> String; fn query(&self) -> HashMap<&'static str, &'static str>; fn headers(&self) -> HashMap<&'static str, &'static str>; fn authentication(&self) -> Option;