diff options
| author | lukeflo | 2024-12-23 21:02:00 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | 9a33a794167d60ce35030f007674f6e9424b1ff3 (patch) | |
| tree | bf81db50446aa7a8e06553f4e8aff97ea0cfb816 /src/bibiman.rs | |
| parent | 8333136cb770cbfbb7be2160fd85687493d96ea4 (diff) | |
| download | bibiman-9a33a794167d60ce35030f007674f6e9424b1ff3.tar.gz bibiman-9a33a794167d60ce35030f007674f6e9424b1ff3.zip | |
replace doi2bib with ureq crate
Diffstat (limited to 'src/bibiman.rs')
| -rw-r--r-- | src/bibiman.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/bibiman.rs b/src/bibiman.rs index 754e8f6..0c0d99b 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -24,7 +24,6 @@ use crate::tui::Tui; use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList}; use arboard::Clipboard; use color_eyre::eyre::Result; -use doi2bib; use editor_command::EditorBuilder; use futures::executor::block_on; use ratatui::widgets::ScrollbarState; @@ -129,12 +128,22 @@ impl Bibiman { /// ///The method needs two arguments: the CLIArgs struct and the `str` containing the DOI pub fn handle_new_entry_submission(&mut self, args: &CLIArgs, doi_string: &str) { - let doi2bib = doi2bib::Doi2Bib::new().unwrap(); - let new_entry_future = doi2bib.resolve_doi(doi_string); - let new_entry = block_on(new_entry_future); + let doi_string = if doi_string.starts_with("10.") { + "https://doi.org/".to_string() + doi_string + } else { + doi_string.to_owned() + }; + + // Send GET request to doi resolver + let doi_entry = ureq::get(&doi_string) + .set("Accept", "application/x-bibtex") + .call(); - if let Ok(entry) = new_entry { + if let Ok(entry) = doi_entry { // Save generated bibtex entry in structs field + let entry = entry + .into_string() + .expect("Couldn't parse fetched entry into string"); self.popup_area.popup_sel_item = entry; self.popup_area.popup_kind = Some(PopupKind::AppendToFile); self.append_to_file(args); |
