diff --git a/Cargo.toml b/Cargo.toml index c8d3064..d934c5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,10 +6,10 @@ license = "MIT OR Apache-2.0" readme = "README.md" keywords = ["api", "web", "literature", "doi"] repository = "https://github.com/MattsSe/crossref-rs" -description= "Implementation of the Crossref API" +description = "Implementation of the Crossref API" documentation = "https://docs.rs/crossref/" categories = ["api-bindings", "science"] -edition = "2018" +edition = "2021" [badges] travis-ci = { repository = "MattsSe/crossref-rs", branch = "master" } @@ -17,17 +17,18 @@ travis-ci = { repository = "MattsSe/crossref-rs", branch = "master" } [[bin]] name = "crossref" path = "src/crossref.rs" -required-features =["cli"] +required-features = ["cli"] [dependencies] -reqwest = "0.9" +reqwest = { version = "0.12", features = ["blocking"] } serde = { version = "1.0", features = ["derive"] } -failure = "0.1" +failure = "0.1.8" serde_json = "1.0" -chrono = { version = "0.4", features = ["serde"] } -structopt = { version = "0.2", optional = true } -url = "1.7" -pretty_env_logger = { version = "0.3", optional = true } +chrono = { version = "0.4", features = ["serde"] } +structopt = { version = "0.3", optional = true } +url = "2.5" +pretty_env_logger = { version = "0.5", optional = true } +tokio = "1" [features] cli = ["structopt", "pretty_env_logger"] diff --git a/src/lib.rs b/src/lib.rs index cf70f22..d4fca4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -344,11 +344,9 @@ impl Crossref { /// Also fails if the json response body could be parsed into `Response` /// Fails if there was an error in reqwest executing the request [::reqwest::RequestBuilder::send] fn get_response(&self, query: &T) -> Result { - let resp = self - .client - .get(&query.to_url(&self.base_url)?) - .send()? - .text()?; + let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime"); + let url = query.to_url(&self.base_url)?; + let resp = rt.block_on(async { self.client.get(&url).send().await?.text().await })?; if resp.starts_with("Resource not found") { Err(ErrorKind::ResourceNotFound { resource: Box::new(query.clone().resource_component()), diff --git a/src/response/mod.rs b/src/response/mod.rs index 7f840f0..435013a 100644 --- a/src/response/mod.rs +++ b/src/response/mod.rs @@ -499,8 +499,7 @@ mod tests { #[test] fn agency_msg_deserialize() { - let agency_str = - r#"{"status":"ok","message-type":"work-agency","message-version":"1.0.0","message":{"DOI":"10.1037\/0003-066x.59.1.29","agency":{"id":"crossref","label":"Crossref"}}}"#; + let agency_str = r#"{"status":"ok","message-type":"work-agency","message-version":"1.0.0","message":{"DOI":"10.1037\/0003-066x.59.1.29","agency":{"id":"crossref","label":"Crossref"}}}"#; let agency: Response = from_str(agency_str).unwrap(); diff --git a/src/response/work.rs b/src/response/work.rs index 44619f6..666dab5 100644 --- a/src/response/work.rs +++ b/src/response/work.rs @@ -157,9 +157,9 @@ impl DateParts { fn naive(v: &[Option]) -> Option { match v.len() { 0 => None, - 1 => Some(NaiveDate::from_ymd(v[0]? as i32, 0, 0)), - 2 => Some(NaiveDate::from_ymd(v[0]? as i32, v[1]?, 0)), - 3 => Some(NaiveDate::from_ymd(v[0]? as i32, v[1]?, v[2]?)), + 1 => Some(NaiveDate::from_ymd_opt(v[0]? as i32, 0, 0)?), + 2 => Some(NaiveDate::from_ymd_opt(v[0]? as i32, v[1]?, 0)?), + 3 => Some(NaiveDate::from_ymd_opt(v[0]? as i32, v[1]?, v[2]?)?), _ => None, } } @@ -594,5 +594,4 @@ mod tests { let work: Work = from_str(work_str).unwrap(); } - }