use serde::{Deserialize, Serialize};
use std::{collections::HashMap, error::Error, fmt, fmt::Display};
#[derive(Deserialize, Debug)]
pub struct AccountResponse {
pub message: String,
pub email: String,
pub name: String,
pub api_key: String,
pub created: TimeStrings,
pub settings: AccountSettings,
}
#[derive(Deserialize, Debug)]
pub struct AccountSettings {
pub owner: String,
pub communication: Option<String>, pub date_format: Option<String>,
pub web_editor: String, }
#[derive(Deserialize, Debug)]
pub struct Verification {
pub message: String,
pub verified: bool,
}
#[derive(Deserialize, Debug)]
pub struct Expiration {
pub message: String,
pub expired: bool,
pub will_expire: Option<bool>,
pub unix_epoch_time: Option<String>,
pub iso_8601_time: Option<String>,
pub rfc_2822_time: Option<String>,
pub relative_time: Option<String>,
}
#[derive(Deserialize, Debug)]
pub struct Address {
pub address: String,
pub message: String,
pub registration: TimeStrings,
pub expiration: Expiration,
pub verification: Verification,
pub owner: Option<String>,
}
#[derive(Deserialize, Debug)]
pub struct DNSrecords {
pub message: String,
pub dns: Vec<DNSrecord>,
}
#[derive(Deserialize, Debug)]
pub struct DNSrecord {
pub id: i32,
pub name: String,
pub data: String,
pub priority: Option<i32>,
pub ttl: i32,
pub created_at: Option<String>,
pub updated_at: Option<String>,
#[serde(rename = "type")]
pub record_type: DNStype,
}
#[derive(Deserialize, Debug)]
pub enum DNStype {
A,
AAA,
CAA,
CNAME,
MX,
NS,
SRV,
TXT,
}
impl Display for DNStype {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", &self)
}
}
#[derive(Deserialize, Debug)]
pub struct ForwardingAddresses {
pub message: String,
pub destination_string: String,
pub destination_array: Vec<String>,
pub address: String,
pub email_address: String,
}
#[derive(Deserialize, Debug)]
pub struct MessageResponse {
pub message: String,
}
#[derive(Deserialize, Debug)]
pub struct RequestResponse<T> {
pub request: RequestStatus,
pub response: T,
}
#[derive(Deserialize, Debug)]
pub struct RequestStatus {
pub status_code: u16,
pub success: bool,
}
#[derive(Deserialize, Debug)]
pub struct TimeStrings {
pub unix_epoch_time: String,
pub iso_8601_time: String,
pub rfc_2822_time: String,
pub relative_time: String,
pub message: Option<String>,
}
#[derive(Deserialize, Debug)]
pub struct NowResponse {
pub message: String,
pub now: Vec<NowPage>,
}
#[derive(Deserialize, Debug)]
pub struct NowPage {
pub content: String,
pub updated: u32,
pub listed: u8,
pub nudge: u8,
pub metadata: String,
}
#[derive(Deserialize, Debug)]
pub struct NowGardenResponse {
pub message: String,
pub garden: Vec<NowGarden>,
}
#[derive(Deserialize, Debug)]
pub struct NowGarden {
pub address: String,
pub url: String,
pub updated: TimeStrings,
}
#[derive(Deserialize, Debug)]
pub struct Token {
pub access_token: String,
pub token_type: String,
pub scope: String,
}
#[derive(Deserialize, Debug)]
pub struct PasteResponse {
pub message: String,
pub pastebin: Paste,
}
#[derive(Deserialize, Debug)]
pub struct PastebinResponse {
pub message: String,
pub success: Vec<Paste>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Paste {
pub title: String,
pub content: String,
#[serde(skip_serializing)]
pub modified_on: Option<String>,
}
impl Paste {
pub fn new(title: String, content: String) -> Paste {
Paste {
title,
content,
modified_on: None,
}
}
}
#[derive(Deserialize, Debug)]
pub struct PurlResponse {
pub message: String,
pub purl: Purl,
}
#[derive(Deserialize, Debug)]
pub struct PurlsResponse {
pub message: String,
pub purls: Vec<Purl>,
}
#[derive(Deserialize, Debug)]
pub struct Purl {
pub name: String,
pub url: String,
pub counter: Option<i32>,
}
#[derive(Deserialize, Debug)]
pub struct ServiceStatus {
pub message: String,
pub members: i32,
pub addresses: i32,
pub profiles: i32,
}
pub trait ContentAsJSON {
fn json_content(&self) -> String {
panic!("Error converting to JSON content.")
}
}
impl ContentAsJSON for String {
fn json_content(&self) -> String {
format!("{{\"content\": \"{}\"}}", &self)
}
}
#[derive(Deserialize, Debug)]
pub struct StatuslogResponseArray {
pub message: String,
pub id: String,
pub status: Status,
}
#[derive(Deserialize, Debug)]
pub struct StatuslogUpdateResponse {
pub message: String,
pub id: String,
pub url: String,
}
#[derive(Deserialize, Debug)]
pub struct StatuslogAllStatuses {
pub message: String,
pub statuses: Vec<Status>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Status {
pub emoji: String,
pub content: String,
pub external_url: Option<String>,
#[serde(skip_serializing)]
pub id: String,
#[serde(skip_serializing)]
pub address: String,
#[serde(skip_serializing)]
pub created: String,
#[serde(skip_serializing)]
pub relative_time: String,
}
impl Status {
pub fn new(emoji: String, content: String, external_url: Option<String>) -> Status {
Status {
emoji,
content,
external_url,
id: "".to_string(),
address: "".to_string(),
created: "".to_string(),
relative_time: "".to_string(),
}
}
}
#[derive(Deserialize, Serialize, Debug)]
pub struct StatuslogBio {
pub bio: String,
#[serde(skip_serializing)]
pub css: String,
#[serde(skip_serializing)]
pub message: String,
}
impl StatuslogBio {
pub fn new(bio: String) -> StatuslogBio {
StatuslogBio {
bio,
css: "".to_string(),
message: "".to_string(),
}
}
}
impl ContentAsJSON for StatuslogBio {
fn json_content(&self) -> String {
format!("{{\"content\": \"{}\"}}", &self.message)
}
}
#[derive(Deserialize, Debug)]
pub struct StatusPostResponse {
pub message: String,
pub id: String,
pub status: String,
pub url: String,
pub external_url: String,
}
#[derive(Deserialize, Debug)]
pub struct ProfileThemes {
pub message: String,
pub themes: HashMap<String, Theme>,
}
#[derive(Deserialize, Debug)]
pub struct Theme {
pub id: String,
pub name: String,
pub created: String,
pub updated: String,
pub author: String,
pub author_url: String,
pub version: String,
pub license: String,
pub description: String,
pub preview_css: String,
pub sample_profile: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Web {
pub content: String,
#[serde(skip_serializing)]
pub message: String,
#[serde(skip_serializing)]
pub css: String,
#[serde(skip_serializing)]
pub head: String,
#[serde(skip_serializing)]
pub verified: Option<i8>,
#[serde(skip_serializing)]
pub pfp: Option<String>,
#[serde(skip_serializing)]
pub metadata: String,
#[serde(skip_serializing)]
pub branding: String,
#[serde(rename(deserialize = "type"), skip_serializing)]
pub page_type: String,
}
impl Web {
pub fn new(content: String) -> Web {
Web {
content,
message: " ".to_string(),
css: "".to_string(),
head: "".to_string(),
verified: None,
pfp: None,
metadata: "".to_string(),
branding: "".to_string(),
page_type: "".to_string(),
}
}
}
#[derive(Deserialize, Debug)]
pub struct WeblogEntriesResponse {
pub message: String,
pub entries: Vec<WeblogEntry>,
}
#[derive(Deserialize, Debug)]
pub struct WeblogEntryResponse {
pub message: String,
#[serde(alias = "post")]
pub entry: WeblogEntry,
}
#[derive(Deserialize, Debug)]
pub struct WeblogEntry {
pub location: String,
pub title: String,
pub date: u32,
pub status: String,
pub body: String,
pub source: String,
pub metadata: WeblogMetadata,
pub output: String,
pub entry: String,
#[serde(rename(deserialize = "type"))]
entry_type: String,
}
#[derive(Deserialize, Debug)]
pub struct WeblogMetadata {
pub date: String,
pub slug: String,
}
#[derive(Deserialize, Debug)]
pub struct WeblogConfigurationResponse {
pub message: String,
pub configuration: WeblogConfigurationFormats,
}
#[derive(Deserialize, Debug)]
pub struct WeblogConfigurationFormats {
pub object: WeblogConfiguration,
pub json: String,
pub raw: String,
}
#[derive(Deserialize, Debug)]
pub struct WeblogConfiguration {
pub weblog_title: String,
pub weblog_description: String,
pub author: String,
pub separator: String,
pub tag_path: String,
pub timezone: String,
pub date_format: String,
pub default_post: String,
pub feed_post_count: String,
pub recents_posts_format: String,
pub post_list_format: String,
pub search_satus: String,
pub search_status_success_message: String,
pub search_results_failure_message: String,
pub search_results_format: String,
}
#[derive(Deserialize, Debug)]
pub struct WeblogTemplateResponse {
pub message: String,
pub template: String,
}
#[derive(Debug, Clone)]
pub struct RequestError {
pub status_code: u16,
}
impl Error for RequestError {}
impl fmt::Display for RequestError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Request error. HTTP status code: {}.", &self.status_code)
}
}