Skip to main content

GhostAdminClient

Struct GhostAdminClient 

Source
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

Source

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();
Source

pub fn base_url(&self) -> &str

Returns the normalised base URL (no trailing slash).

Source

pub fn api_key(&self) -> &AdminApiKey

Returns a reference to the stored AdminApiKey.

Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more