pub struct GhostAdminClient { /* private fields */ }Expand description
Write-capable client for the Ghost Admin API.
Communicates with /ghost/api/admin/ using a AdminApiKey that is
converted to a short-lived HS256 JWT on every request so tokens never
sit long enough to expire. The Accept-Version: v5.0 header is sent
automatically.
§Security
Keep the AdminApiKey secret — it grants write access to your Ghost
installation.
§Example
use ghost_io_api::auth::admin::AdminApiKey;
use ghost_io_api::client::admin::GhostAdminClient;
let key = AdminApiKey::new(
"6748592f4b9b7700010f6564:b1b5b9c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1"
)?;
let client = GhostAdminClient::new("https://example.ghost.io", key)?;Implementations§
Source§impl GhostAdminClient
impl GhostAdminClient
Sourcepub fn new(base_url: impl Into<String>, api_key: AdminApiKey) -> Result<Self>
pub fn new(base_url: impl Into<String>, api_key: AdminApiKey) -> Result<Self>
Creates a new GhostAdminClient.
Trailing slashes on base_url are stripped automatically.
§Errors
Returns GhostError::Http if the underlying reqwest client cannot
be built.
§Example
use ghost_io_api::auth::admin::AdminApiKey;
use ghost_io_api::client::admin::GhostAdminClient;
let key = AdminApiKey::new(
"6748592f4b9b7700010f6564:b1b5b9c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1"
).unwrap();
let client = GhostAdminClient::new("https://example.ghost.io", key).unwrap();Sourcepub fn api_key(&self) -> &AdminApiKey
pub fn api_key(&self) -> &AdminApiKey
Returns a reference to the stored AdminApiKey.
Sourcepub async fn browse_posts(
&self,
params: AdminBrowsePostsParams,
) -> Result<AdminPostsResponse>
pub async fn browse_posts( &self, params: AdminBrowsePostsParams, ) -> Result<AdminPostsResponse>
Browses posts with optional filtering, sorting, and pagination.
Unlike the Content API, the Admin API returns all posts regardless of status (drafts, scheduled, published).
§Errors
Returns GhostError on network failure, a non-2xx HTTP response, or
a JSON decoding error.
§Example
use ghost_io_api::client::admin::{GhostAdminClient, AdminBrowsePostsParams};
let response = client.browse_posts(AdminBrowsePostsParams {
limit: Some(10),
filter: Some("status:draft".to_string()),
..Default::default()
}).await?;
println!("{} drafts found", response.posts.len());Sourcepub async fn read_post_by_id(
&self,
id: &str,
include: Option<&str>,
) -> Result<Post>
pub async fn read_post_by_id( &self, id: &str, include: Option<&str>, ) -> Result<Post>
Reads a single post by its Ghost ID.
include is an optional comma-separated list of relations to embed,
e.g. "authors,tags".
§Errors
Returns GhostError::Api with type "NotFoundError" when no post
matches id.
§Example
let post = client.read_post_by_id("5ddc9141c35e7700383b2937", None).await?;
println!("{}", post.title);Sourcepub async fn read_post_by_slug(
&self,
slug: &str,
include: Option<&str>,
) -> Result<Post>
pub async fn read_post_by_slug( &self, slug: &str, include: Option<&str>, ) -> Result<Post>
Reads a single post by its slug.
include is an optional comma-separated list of relations to embed,
e.g. "authors,tags".
§Errors
Returns GhostError::Api with type "NotFoundError" when no post
matches slug.
§Example
let post = client.read_post_by_slug("welcome", Some("authors")).await?;
println!("{}", post.title);Sourcepub async fn create_post(&self, post: PostCreate) -> Result<Post>
pub async fn create_post(&self, post: PostCreate) -> Result<Post>
Creates a new post.
Returns the created post as stored by Ghost (with server-assigned id,
slug, created_at, updated_at, etc.).
§Errors
Returns GhostError::Api on validation failures (e.g. empty title).
§Example
use ghost_io_api::models::post::{PostCreate, PostStatus};
let post = client.create_post(PostCreate {
title: "My New Post".to_string(),
status: Some(PostStatus::Draft),
..Default::default()
}).await?;
println!("Created post: {}", post.id);Sourcepub async fn update_post(&self, id: &str, post: PostUpdate) -> Result<Post>
pub async fn update_post(&self, id: &str, post: PostUpdate) -> Result<Post>
Updates an existing post.
The PostUpdate must carry the post’s current updated_at timestamp
(obtained from a prior read). Ghost rejects the request if the value
does not match, protecting against concurrent-edit overwrites.
Returns the updated post as stored by Ghost.
§Errors
Returns GhostError::Api with type "NotFoundError" if id is
unknown, or "ConflictError" if updated_at is stale.
§Example
use ghost_io_api::models::post::{PostUpdate, PostStatus};
let post = client.read_post_by_id("abc123", None).await?;
let updated = client.update_post("abc123", PostUpdate {
updated_at: post.updated_at.unwrap(),
status: Some(PostStatus::Published),
..Default::default()
}).await?;
println!("Now published: {}", updated.id);Sourcepub async fn delete_post(&self, id: &str) -> Result<()>
pub async fn delete_post(&self, id: &str) -> Result<()>
Deletes a post by its Ghost ID.
Ghost returns 204 No Content on success. The post is permanently
removed and cannot be recovered.
§Errors
Returns GhostError::Api with type "NotFoundError" if id is
unknown.
§Example
client.delete_post("abc123").await?;