Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ 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" }

[[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"]
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: CrossrefQuery>(&self, query: &T) -> Result<Response> {
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()),
Expand Down
3 changes: 1 addition & 2 deletions src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 3 additions & 4 deletions src/response/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ impl DateParts {
fn naive(v: &[Option<u32>]) -> Option<NaiveDate> {
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,
}
}
Expand Down Expand Up @@ -594,5 +594,4 @@ mod tests {

let work: Work = from_str(work_str).unwrap();
}

}