Skip to main content

ghost_io_api/
lib.rs

1//! # ghost-io-api
2//!
3//! A strongly-typed, async Rust client for both the
4//! [Ghost CMS](https://ghost.org/) **Content API** and **Admin API**.
5//!
6//! ## Modules
7//!
8//! | Module | Purpose |
9//! |---|---|
10//! | [`auth::content`] | [`ContentApiKey`](auth::content::ContentApiKey) — 26-char hex key for the read-only Content API |
11//! | [`auth::admin`] | [`AdminApiKey`](auth::admin::AdminApiKey) — `id:hex-secret` key pair; mints HS256 JWTs for the Admin API |
12//! | [`client::content`] | [`GhostContentClient`](client::content::GhostContentClient) — browse and read posts, pages, tags, authors, tiers, settings |
13//! | [`client::admin`] | [`GhostAdminClient`](client::admin::GhostAdminClient) — create, update, delete, and browse posts |
14//! | [`models`] | Serde-annotated structs for every Ghost resource |
15//! | [`models::envelope`] | [`BrowseEnvelope<T>`](models::envelope::BrowseEnvelope) / [`SingleEnvelope<T>`](models::envelope::SingleEnvelope) — generic JSON envelope parsing |
16//! | [`error`] | [`GhostError`](error::GhostError) enum and [`Result`](error::Result) alias |
17//! | [`params`] | Fluent [`BrowseParams`](params::browse::BrowseParams) builder for query parameters |
18//!
19//! ## Content API quick-start
20//!
21//! ```no_run
22//! use ghost_io_api::auth::content::ContentApiKey;
23//! use ghost_io_api::client::content::{BrowsePostsParams, GhostContentClient};
24//! use ghost_io_api::error::Result;
25//!
26//! #[tokio::main]
27//! async fn main() -> Result<()> {
28//!     let key = ContentApiKey::new("22444f78447824223cefc48062")?;
29//!     let client = GhostContentClient::new("https://demo.ghost.io", key)?;
30//!
31//!     let response = client.browse_posts(BrowsePostsParams::default()).await?;
32//!     for post in &response.posts {
33//!         println!("{} — {}", post.title, post.slug);
34//!     }
35//!     Ok(())
36//! }
37//! ```
38//!
39//! ## Admin API quick-start
40//!
41//! ```no_run
42//! use ghost_io_api::auth::admin::AdminApiKey;
43//! use ghost_io_api::client::admin::{AdminBrowsePostsParams, GhostAdminClient};
44//! use ghost_io_api::error::Result;
45//! use ghost_io_api::models::post::{PostCreate, PostStatus, PostUpdate};
46//!
47//! #[tokio::main]
48//! async fn main() -> Result<()> {
49//!     let key = AdminApiKey::new(
50//!         "6748592f4b9b7700010f6564:\
51//!          b1b5b9c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1"
52//!     )?;
53//!     let client = GhostAdminClient::new("https://your-site.ghost.io", key)?;
54//!
55//!     // Create a draft
56//!     let draft = client.create_post(PostCreate::new("Hello, Admin!")).await?;
57//!     println!("Draft id: {}", draft.id);
58//!
59//!     // Publish it — updated_at is Ghost's optimistic-concurrency token
60//!     let published = client.update_post(&draft.id, PostUpdate {
61//!         updated_at: draft.updated_at.unwrap(),
62//!         status: Some(PostStatus::Published),
63//!         ..Default::default()
64//!     }).await?;
65//!     println!("Published: {}", published.url.unwrap_or_default());
66//!
67//!     // Delete it
68//!     client.delete_post(&published.id).await?;
69//!     Ok(())
70//! }
71//! ```
72
73#![warn(missing_docs)]
74
75pub mod auth;
76pub mod client;
77pub mod error;
78pub mod models;
79pub mod params;