Skip to main content

Crate ghost_io_api

Crate ghost_io_api 

Source
Expand description

§ghost-io-api

A strongly-typed, async Rust client for both the Ghost CMS Content API and Admin API.

§Modules

ModulePurpose
auth::contentContentApiKey — 26-char hex key for the read-only Content API
auth::adminAdminApiKeyid:hex-secret key pair; mints HS256 JWTs for the Admin API
client::contentGhostContentClient — browse and read posts, pages, tags, authors, tiers, settings
client::adminGhostAdminClient — create, update, delete, and browse posts
modelsSerde-annotated structs for every Ghost resource
models::envelopeBrowseEnvelope<T> / SingleEnvelope<T> — generic JSON envelope parsing
errorGhostError enum and Result alias
paramsFluent BrowseParams builder for query parameters

§Content API quick-start

use ghost_io_api::auth::content::ContentApiKey;
use ghost_io_api::client::content::{BrowsePostsParams, GhostContentClient};
use ghost_io_api::error::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let key = ContentApiKey::new("22444f78447824223cefc48062")?;
    let client = GhostContentClient::new("https://demo.ghost.io", key)?;

    let response = client.browse_posts(BrowsePostsParams::default()).await?;
    for post in &response.posts {
        println!("{} — {}", post.title, post.slug);
    }
    Ok(())
}

§Admin API quick-start

use ghost_io_api::auth::admin::AdminApiKey;
use ghost_io_api::client::admin::{AdminBrowsePostsParams, GhostAdminClient};
use ghost_io_api::error::Result;
use ghost_io_api::models::post::{PostCreate, PostStatus, PostUpdate};

#[tokio::main]
async fn main() -> Result<()> {
    let key = AdminApiKey::new(
        "6748592f4b9b7700010f6564:\
         b1b5b9c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1"
    )?;
    let client = GhostAdminClient::new("https://your-site.ghost.io", key)?;

    // Create a draft
    let draft = client.create_post(PostCreate::new("Hello, Admin!")).await?;
    println!("Draft id: {}", draft.id);

    // Publish it — updated_at is Ghost's optimistic-concurrency token
    let published = client.update_post(&draft.id, PostUpdate {
        updated_at: draft.updated_at.unwrap(),
        status: Some(PostStatus::Published),
        ..Default::default()
    }).await?;
    println!("Published: {}", published.url.unwrap_or_default());

    // Delete it
    client.delete_post(&published.id).await?;
    Ok(())
}

Modules§

auth
Authentication modules for Ghost API.
client
API client implementations for Ghost.
error
Error types for the Ghost API client.
models
Data models for Ghost API resources.
params
Query parameter builders for Ghost API requests.