#![doc = include_str!("../README.md")]
pub mod article;
pub mod content;
pub mod envelope;
pub mod error;
pub mod metadata;
pub mod reference;
pub mod structured;
pub mod version;
pub mod request;
pub use article::{Article, ProjectRef, StructuredArticle, Visibility};
pub use content::{ArticleBody, Image, License};
pub use envelope::ArticleEnvelope;
pub use error::ModelError;
pub use metadata::{
BatchInfo, ChunkInfo, EventMetadata, EventType, Language, Namespace, Project, ProjectInfo,
ProjectType, RealtimeBatchInfo, RealtimeProject, SimplifiedLanguage, SimplifiedNamespace, Size,
SnapshotInfo,
};
pub use reference::{Citation, Reference};
pub use request::{Filter, FilterValue, RequestParams};
pub use structured::{Infobox, Section, Table, TableReference};
pub use version::{
ArticleSize, Editor, MaintenanceTags, PreviousVersion, Protection, ReferenceNeed,
ReferenceRisk, RevertRisk, Scores, Version,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct WikidataEntity {
pub identifier: String,
pub url: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct RealtimeWikidataEntity {
pub identifier: String,
pub url: String,
pub aspects: Vec<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct WikidataEntityUsage {
pub identifier: String,
pub url: String,
pub aspects: Vec<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Category {
pub name: String,
pub url: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Template {
pub name: String,
pub url: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Redirect {
pub name: String,
pub url: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Link {
pub text: String,
pub url: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SnapshotIdentifier {
pub language: String,
pub project: String,
pub namespace: u32,
}
impl SnapshotIdentifier {
pub fn new(language: &str, project: &str, namespace: u32) -> Self {
Self {
language: language.to_string(),
project: project.to_string(),
namespace,
}
}
pub fn enwiki_namespace_0() -> Self {
Self::new("en", "wiki", 0)
}
pub fn dewiki_namespace_0() -> Self {
Self::new("de", "wiki", 0)
}
}
impl std::str::FromStr for SnapshotIdentifier {
type Err = error::ModelError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let parts: Vec<&str> = s.split("_namespace_").collect();
if parts.len() != 2 {
return Err(error::ModelError::InvalidSnapshotId(s.to_string()));
}
let namespace = parts[1]
.parse::<u32>()
.map_err(|_| error::ModelError::InvalidSnapshotId(s.to_string()))?;
let lang_project = parts[0];
let project_suffixes = [
"wiktionary",
"wikibooks",
"wikinews",
"wikiquote",
"wikisource",
"wikiversity",
"wikivoyage",
"commons",
"wiki",
];
let (language, project) = project_suffixes
.iter()
.find_map(|&suffix| {
lang_project
.strip_suffix(suffix)
.map(|lang| (lang.to_string(), suffix.to_string()))
})
.ok_or_else(|| error::ModelError::InvalidSnapshotId(s.to_string()))?;
Ok(Self {
language,
project,
namespace,
})
}
}
impl std::fmt::Display for SnapshotIdentifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}{}_namespace_{}",
self.language, self.project, self.namespace
)
}
}