Compare commits

...

5 Commits

Author SHA1 Message Date
Anna 6f68e5e041
feat: update a bit 2022-06-16 10:12:13 -04:00
Anna 6db0c20c4e
chore: update dependencies 2020-07-23 14:42:47 -04:00
Kyle Clemens 6d7a07553d
feat: add gunbreaker and dancer 2019-05-28 23:49:37 -04:00
Kyle Clemens 3be994dae6
refactor: update dependencies and add blue mage 2019-01-15 14:38:54 -05:00
Kyle Clemens b0338b2b0d
refactor: remove unused imports 2018-10-28 17:44:20 -04:00
11 changed files with 57 additions and 45 deletions

View File

@ -1,20 +1,24 @@
[package]
name = "lodestone_scraper"
version = "0.1.0"
authors = ["Kyle Clemens <git@kyleclemens.com>"]
name = "lodestone-scraper"
version = "1.0.0"
authors = ["Anna Clemens <git@annaclemens.io>"]
edition = "2018"
edition = "2021"
[dependencies]
reqwest = "0.8"
failure = "0.1"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
thiserror = "1"
lazy_static = "1"
url = "1"
url = "2"
[dependencies.lodestone_parser]
git = "https://github.com/jkcclemens/lodestone_parser"
[dependencies.lodestone-parser]
git = "https://git.annaclemens.io/ascclemens/lodestone-parser.git"
[dependencies.ffxiv_types]
version = "1"
default-features = false
features = ["worlds", "data_centers", "races", "clans"]
[dependencies.tokio]
version = "1"
features = ["rt-multi-thread", "macros"]

View File

@ -1,4 +1,4 @@
# lodestone_scraper
# lodestone-scraper
A Lodestone client library.

View File

@ -93,8 +93,8 @@ impl<'a> CharacterSearchBuilder<'a> {
self
}
pub fn send(&self) -> Result<Paginated<CharacterSearchItem>> {
let text = self.scraper.text(self.as_url())?;
pub async fn send(&self) -> Result<Paginated<CharacterSearchItem>> {
let text = self.scraper.text(self.as_url()).await?;
lodestone_parser::parse_character_search(&text).map_err(Error::Parse)
}

View File

@ -65,8 +65,8 @@ impl<'a> FreeCompanySearchBuilder<'a> {
self
}
pub fn send(&self) -> Result<Paginated<FreeCompanySearchItem>> {
let text = self.scraper.text(self.as_url())?;
pub async fn send(&self) -> Result<Paginated<FreeCompanySearchItem>> {
let text = self.scraper.text(self.as_url()).await?;
lodestone_parser::parse_free_company_search(&text).map_err(Error::Parse)
}

View File

@ -3,8 +3,6 @@ use crate::{
error::*,
};
use ffxiv_types::{World, DataCenter};
use lodestone_parser::models::linkshell::Linkshell;
use url::Url;
@ -31,8 +29,8 @@ impl<'a> LinkshellBuilder<'a> {
self
}
pub fn send(&self) -> Result<Linkshell> {
let text = self.scraper.text(self.as_url())?;
pub async fn send(&self) -> Result<Linkshell> {
let text = self.scraper.text(self.as_url()).await?;
lodestone_parser::parse_linkshell(self.id, &text).map_err(Error::Parse)
}

View File

@ -55,8 +55,8 @@ impl<'a> LinkshellSearchBuilder<'a> {
self
}
pub fn send(&self) -> Result<Paginated<LinkshellSearchItem>> {
let text = self.scraper.text(self.as_url())?;
pub async fn send(&self) -> Result<Paginated<LinkshellSearchItem>> {
let text = self.scraper.text(self.as_url()).await?;
lodestone_parser::parse_linkshell_search(&text).map_err(Error::Parse)
}

View File

@ -2,16 +2,16 @@ use reqwest::StatusCode;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[fail(display = "not found")]
#[error("not found")]
NotFound,
#[fail(display = "lodestone responded with an unexpected code: {}", _0)]
#[error("lodestone responded with an unexpected code: {0}")]
UnexpectedResponse(StatusCode),
#[fail(display = "network error: {}", _0)]
#[error("network error: {0}")]
Net(reqwest::Error),
#[fail(display = "url parse error: {}", _0)]
#[error("url parse error: {0}")]
Url(url::ParseError),
#[fail(display = "lodestone parse error: {}", _0)]
#[error("lodestone parse error: {0}")]
Parse(lodestone_parser::error::Error),
}

View File

@ -1,13 +1,10 @@
#![feature(crate_visibility_modifier)]
#[macro_use] extern crate failure;
pub extern crate lodestone_parser;
use lazy_static::lazy_static;
use lodestone_parser::models::{
character::Character,
free_company::FreeCompany,
linkshell::Linkshell,
};
use reqwest::{Client, StatusCode};
@ -19,7 +16,7 @@ use std::str::FromStr;
pub mod builder;
pub mod error;
pub mod models;
crate mod util;
pub(crate) mod util;
use crate::error::*;
@ -44,24 +41,26 @@ impl LodestoneScraper {
LODESTONE_URL.join(s).map_err(Error::Url)
}
crate fn text(&self, url: Url) -> Result<String> {
let mut res = self.client
pub(crate) async fn text(&self, url: Url) -> Result<String> {
let res = self.client
.get(url)
.send()
.await
.map_err(Error::Net)?;
match res.status() {
StatusCode::Ok => {},
StatusCode::NotFound => return Err(Error::NotFound),
StatusCode::OK => {},
StatusCode::NOT_FOUND => return Err(Error::NotFound),
x => return Err(Error::UnexpectedResponse(x)),
}
res
.text()
.await
.map_err(Error::Net)
}
pub fn character(&self, id: u64) -> Result<Character> {
pub async fn character(&self, id: u64) -> Result<Character> {
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)
}
@ -69,9 +68,9 @@ impl LodestoneScraper {
builder::CharacterSearchBuilder::new(self)
}
pub fn free_company(&self, id: u64) -> Result<FreeCompany> {
pub async fn free_company(&self, id: u64) -> Result<FreeCompany> {
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)
}

View File

@ -1,5 +1,5 @@
crate mod as_lodestone;
crate mod either;
pub(crate) mod as_lodestone;
pub(crate) mod either;
crate use self::as_lodestone::AsLodestone;
crate use self::either::Either;
pub(crate) use self::as_lodestone::AsLodestone;
pub(crate) use self::either::Either;

View File

@ -7,7 +7,7 @@ use lodestone_parser::models::{
character::Job,
};
crate trait AsLodestone {
pub(crate) trait AsLodestone {
type Representation;
fn as_lodestone(&self) -> Self::Representation;
@ -78,6 +78,11 @@ impl AsLodestone for Job {
Job::Astrologian => 33,
Job::Samurai => 34,
Job::RedMage => 35,
Job::BlueMage => 36,
Job::Gunbreaker => 37,
Job::Dancer => 38,
Job::Reaper => 39,
Job::Sage => 40,
}
}
}
@ -105,6 +110,8 @@ impl AsLodestone for Race {
Race::Miqote => 4,
Race::Roegadyn => 5,
Race::AuRa => 6,
Race::Hrothgar => 7,
Race::Viera => 8,
}
}
}
@ -126,6 +133,10 @@ impl AsLodestone for Clan {
Clan::Hellsguard => 10,
Clan::Raen => 11,
Clan::Xaela => 12,
Clan::Helion => 13,
Clan::TheLost => 14,
Clan::Rava => 15,
Clan::Veena => 16,
}
}
}

View File

@ -1,4 +1,4 @@
crate enum Either<L, R> {
pub(crate) enum Either<L, R> {
Left(L),
Right(R),
}