Skip to content

Commit

Permalink
allow dynamic path
Browse files Browse the repository at this point in the history
  • Loading branch information
hewigovens committed Oct 4, 2024
1 parent 8ae080e commit 8179925
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand All @@ -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"
4 changes: 2 additions & 2 deletions examples/ethereum-rpc/src/ethereum_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
16 changes: 11 additions & 5 deletions reqwest-enum/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
}
}

Expand Down Expand Up @@ -306,7 +312,7 @@ mod tests {
let provider = Provider::<HttpBin>::default();
assert_eq!(
provider.request_url(&HttpBin::Get),
"https://httpbin.org/get"
"https://httpbin.org/get?ts=1728044812"
);

let provider =
Expand Down
2 changes: 1 addition & 1 deletion reqwest-enum/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthMethod>;
Expand Down

0 comments on commit 8179925

Please sign in to comment.