use chrono::{DateTime, Utc, FixedOffset};
pub mod sources;
#[doc(inline)]
pub use sources::{Source, SourceId, CENCSource, USGSSource};
type DateTimeUtc = DateTime<Utc>;
type DateTimeF = DateTime<FixedOffset>;
#[derive(Debug)]
pub enum ReportStatus {
Automatic,
Reviewed,
Deleted,
}
#[derive(Debug)]
pub struct Event {
pub id: String,
pub url: String,
pub source: SourceId,
pub time: DateTimeUtc,
pub updated: DateTimeUtc,
pub status: ReportStatus,
pub longitude: f64,
pub latitude: f64,
pub depth: f64,
pub magnitude: f64,
pub place: String,
}
impl PartialEq for Event {
fn eq(&self, other: &Self) -> bool {
self.id == other.id && self.source == other.source
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("failed to request data")]
Request(#[from] Box<ureq::Error>),
#[error("invalid response")]
InvalidResponse {
source: std::io::Error,
},
#[error("failed to parse floating number")]
FloatParsing(#[from] std::num::ParseFloatError),
#[error("failed to parse a JSON document")]
Json(#[from] serde_json::Error),
#[error("required field missing value")]
MissingValue,
#[error("unexpected value")]
UnexpectedValue,
#[error("failed to parse a time value")]
ParseTime(#[from] chrono::ParseError),
#[error("failed to parse a time value")]
TimeNone,
}
impl From<ureq::Error> for Error {
fn from(value: ureq::Error) -> Self {
Self::Request(Box::new(value))
}
}