wikimedia-api 0.1.1

Interact with Wikimedia REST API.
Documentation
use serde::{Deserialize, Serialize};
use strum::Display;

// Wikimedia Page object: https://api.wikimedia.org/wiki/Core_REST_API/Reference/Pages/Page_object
// NOTE: the schema here slightly deviates from the API, see below and `requester::_Page` for more information.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Page {
    pub id: usize,                   // Page identifier
    pub key: String,                 // Page title in URL-friendly format
    pub title: String,               // Page title in reading-friendly format
    pub latest: PageLatest,          // Latest revision of the page
    pub content_model: ContentModel, // Content model used for the page
    pub license: License,            // Information about the wiki's license
    // The following part deviates from Wikimedia's API:
    // html_url: String -- Get page only: API route to fetch the content of the page in HTML
    // html: String -- Get page offline only: Latest page content in HTML
    // source: String --  Get page source, create page, and edit page only: Latest page content in the format specified by the content_model property
    // Since there is exactly 1 String in each mode, we're doing this instead:
    pub source_or_url: String,
}

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct PageLatest {
    pub id: usize,         // Revision identifier for the latest revision
    pub timestamp: String, // Timestamp of the latest revision in ISO 8601 format
}

// https://api.wikimedia.org/wiki/Core_REST_API/Reference/Pages/Language_object
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Language {
    code: String, // Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
    name: String, // Translated language name
    key: String,  // Translated page title in URL-friendly format
    title: String, // Translated page title in reading-friendly format
}

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct License {
    pub url: String, // URL for a page that describes the terms and conditions of the license
    pub title: String, // Name of the license in plain text
}

#[derive(
    Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display, Serialize, Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum ContentModel {
    WikiText, // (default): MediaWiki-flavored markup, used for most wiki pages
    CSS,
    JavaScript,
    JSON,
    Text,
}