Skip to content

Commit

Permalink
Merge pull request #15 from rruckley/SegAgentHeaders-14
Browse files Browse the repository at this point in the history
feat: Add User-Agent header to GET
  • Loading branch information
rruckley authored Jan 13, 2025
2 parents 7a5664a + 487a43f commit cc34a79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tmf-client"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["Ryan Ruckley <[email protected]"]
description = "A Rust client library for TMF conformant APIs"
Expand Down
23 changes: 21 additions & 2 deletions src/tmf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ pub mod tmf674;
pub fn get_tmf<T : HasId + DeserializeOwned>(host: Uri, id : String) -> Result<Vec<T>,TMFError> {
// Return results
let url = format!("{}{}/{}",host,T::get_class_href(),id);
let objects = reqwest::blocking::get(url)?.text()?;
// let objects = reqwest::blocking::get(url)?.text()?;
let client = reqwest::blocking::Client::new();
let pkg = env!("CARGO_PKG_NAME");
let ver = env!("CARGO_PKG_VERSION");

let agent = format!("{}/{}",pkg,ver);
let objects = client
.get(url)
.header("User-Agent", agent)
.send()?
.text()?;
let output : Vec<T> = serde_json::from_str(objects.as_str())?;
Ok(output)
}
Expand All @@ -42,7 +52,16 @@ pub fn list_tmf<T : HasId + DeserializeOwned>(host: Uri, filter : Option<QueryOp
};
let url = format!("{}{}?{}",host,T::get_class_href(),filter);
// info!("Filter: {}",filter);
let objects = reqwest::blocking::get(url)?.text()?;
let client = reqwest::blocking::Client::new();
let pkg = env!("CARGO_PKG_NAME");
let ver = env!("CARGO_PKG_VERSION");

let agent = format!("{}/{}",pkg,ver);
let objects = client
.get(url)
.header("User-Agent", agent)
.send()?
.text()?;
let output : Vec<T> = serde_json::from_str(objects.as_str())?;
Ok(output)
}
Expand Down

0 comments on commit cc34a79

Please sign in to comment.