diff --git a/Cargo.toml b/Cargo.toml index 5ce6ef0..a925c01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "lodestone_scraper" version = "0.1.0" -authors = ["Kyle Clemens "] +authors = ["Anna Clemens "] edition = "2018" [dependencies] -reqwest = "0.9" +reqwest = "0.10" failure = "0.1" +# futures = "0.3" lazy_static = "1" -url = "1" +url = "2" [dependencies.lodestone_parser] git = "https://github.com/jkcclemens/lodestone_parser" @@ -18,3 +19,7 @@ git = "https://github.com/jkcclemens/lodestone_parser" version = "1" default-features = false features = ["worlds", "data_centers", "races", "clans"] + +[dependencies.tokio] +version = "0.2" +features = ["rt-core", "rt-threaded", "macros"] diff --git a/src/builder/character_search.rs b/src/builder/character_search.rs index 068647b..7a13b8a 100644 --- a/src/builder/character_search.rs +++ b/src/builder/character_search.rs @@ -93,8 +93,8 @@ impl<'a> CharacterSearchBuilder<'a> { self } - pub fn send(&self) -> Result> { - let text = self.scraper.text(self.as_url())?; + pub async fn send(&self) -> Result> { + let text = self.scraper.text(self.as_url()).await?; lodestone_parser::parse_character_search(&text).map_err(Error::Parse) } diff --git a/src/builder/free_company_search.rs b/src/builder/free_company_search.rs index 7f4097f..7191b51 100644 --- a/src/builder/free_company_search.rs +++ b/src/builder/free_company_search.rs @@ -65,8 +65,8 @@ impl<'a> FreeCompanySearchBuilder<'a> { self } - pub fn send(&self) -> Result> { - let text = self.scraper.text(self.as_url())?; + pub async fn send(&self) -> Result> { + let text = self.scraper.text(self.as_url()).await?; lodestone_parser::parse_free_company_search(&text).map_err(Error::Parse) } diff --git a/src/builder/linkshell.rs b/src/builder/linkshell.rs index 3c6029c..1bdd5b8 100644 --- a/src/builder/linkshell.rs +++ b/src/builder/linkshell.rs @@ -29,8 +29,8 @@ impl<'a> LinkshellBuilder<'a> { self } - pub fn send(&self) -> Result { - let text = self.scraper.text(self.as_url())?; + pub async fn send(&self) -> Result { + let text = self.scraper.text(self.as_url()).await?; lodestone_parser::parse_linkshell(self.id, &text).map_err(Error::Parse) } diff --git a/src/builder/linkshell_search.rs b/src/builder/linkshell_search.rs index e3b40d1..24921dc 100644 --- a/src/builder/linkshell_search.rs +++ b/src/builder/linkshell_search.rs @@ -55,8 +55,8 @@ impl<'a> LinkshellSearchBuilder<'a> { self } - pub fn send(&self) -> Result> { - let text = self.scraper.text(self.as_url())?; + pub async fn send(&self) -> Result> { + let text = self.scraper.text(self.as_url()).await?; lodestone_parser::parse_linkshell_search(&text).map_err(Error::Parse) } diff --git a/src/lib.rs b/src/lib.rs index 05cca5a..bae0f22 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,10 +43,11 @@ impl LodestoneScraper { LODESTONE_URL.join(s).map_err(Error::Url) } - crate fn text(&self, url: Url) -> Result { - let mut res = self.client + crate async fn text(&self, url: Url) -> Result { + let res = self.client .get(url) .send() + .await .map_err(Error::Net)?; match res.status() { StatusCode::OK => {}, @@ -55,12 +56,13 @@ impl LodestoneScraper { } res .text() + .await .map_err(Error::Net) } - pub fn character(&self, id: u64) -> Result { + pub async fn character(&self, id: u64) -> Result { let url = LodestoneScraper::route(&format!("character/{}", id))?; - let text = self.text(url)?; + let text = self.text(url).await?; lodestone_parser::parse_character(id, &text).map_err(Error::Parse) } @@ -68,9 +70,9 @@ impl LodestoneScraper { builder::CharacterSearchBuilder::new(self) } - pub fn free_company(&self, id: u64) -> Result { + pub async fn free_company(&self, id: u64) -> Result { let url = LodestoneScraper::route(&format!("freecompany/{}", id))?; - let text = self.text(url)?; + let text = self.text(url).await?; lodestone_parser::parse_free_company(id, &text).map_err(Error::Parse) }