Skip to main content

GhostContentClient

Struct GhostContentClient 

Source
pub struct GhostContentClient { /* private fields */ }
Expand description

Read-only client for the Ghost Content API.

Communicates with /ghost/api/content/ using a ContentApiKey passed as a query parameter. All methods are async and require a Tokio runtime.

The client sets Accept-Version: v5.0 on every request.

§Example

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

let key = ContentApiKey::new("22444f78447824223cefc48062")?;
let client = GhostContentClient::new("https://demo.ghost.io", key)?;

// Browse posts
let posts = client.browse_posts(BrowsePostsParams::default()).await?;

// Read by ID
let post = client.read_post_by_id("5ddc9141c35e7700383b2937", None).await?;

// Read by slug
let post = client.read_post_by_slug("welcome", None).await?;

Implementations§

Source§

impl GhostContentClient

Source

pub fn new(base_url: impl Into<String>, api_key: ContentApiKey) -> Result<Self>

Creates a new GhostContentClient.

Trailing slashes on base_url are stripped automatically.

§Errors

Returns GhostError::Http if the underlying reqwest client cannot be built.

Source

pub async fn browse_posts( &self, params: BrowsePostsParams, ) -> Result<PostsResponse>

Browses published posts with optional filtering, sorting, and pagination.

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

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 "NotFoundError" if no post matches the ID, or a network / decoding error otherwise.

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 "NotFoundError" if no post matches the slug, or a network / decoding error otherwise.

Source

pub async fn browse_pages( &self, params: BrowsePagesParams, ) -> Result<PagesResponse>

Browses published pages with optional filtering, sorting, and pagination.

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

Source

pub async fn read_page_by_id( &self, id: &str, include: Option<&str>, ) -> Result<Page>

Reads a single page by its Ghost ID.

include is an optional comma-separated list of relations to embed, e.g. "authors".

§Errors

Returns GhostError::Api with "NotFoundError" if no page matches the ID, or a network / decoding error otherwise.

Source

pub async fn read_page_by_slug( &self, slug: &str, include: Option<&str>, ) -> Result<Page>

Reads a single page by its slug.

include is an optional comma-separated list of relations to embed, e.g. "authors".

§Errors

Returns GhostError::Api with "NotFoundError" if no page matches the slug, or a network / decoding error otherwise.

Source

pub async fn browse_tags( &self, params: BrowseTagsParams, ) -> Result<TagsResponse>

Browses tags with optional filtering, sorting, and pagination.

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

Source

pub async fn read_tag_by_id( &self, id: &str, include: Option<&str>, ) -> Result<Tag>

Reads a single tag by its Ghost ID.

include accepts "count.posts" to embed the post count for this tag.

§Errors

Returns GhostError::Api with "NotFoundError" if no tag matches the ID, or a network / decoding error otherwise.

Source

pub async fn read_tag_by_slug( &self, slug: &str, include: Option<&str>, ) -> Result<Tag>

Reads a single tag by its slug.

include accepts "count.posts" to embed the post count for this tag.

§Errors

Returns GhostError::Api with "NotFoundError" if no tag matches the slug, or a network / decoding error otherwise.

Source

pub async fn browse_authors( &self, params: BrowseAuthorsParams, ) -> Result<AuthorsResponse>

Browses authors with optional filtering, sorting, and pagination.

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

Source

pub async fn read_author_by_id( &self, id: &str, include: Option<&str>, ) -> Result<Author>

Reads a single author by their Ghost ID.

include accepts "count.posts" to embed the post count for this author.

§Errors

Returns GhostError::Api with "NotFoundError" if no author matches the ID, or a network / decoding error otherwise.

Source

pub async fn read_author_by_slug( &self, slug: &str, include: Option<&str>, ) -> Result<Author>

Reads a single author by their slug.

include accepts "count.posts" to embed the post count for this author.

§Errors

Returns GhostError::Api with "NotFoundError" if no author matches the slug, or a network / decoding error otherwise.

Source

pub async fn browse_tiers( &self, params: BrowseTiersParams, ) -> Result<TiersResponse>

Browses membership tiers (free and paid).

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

Source

pub async fn get_settings(&self) -> Result<Settings>

Fetches site-wide settings (title, logo, navigation, social links, etc.).

§Errors

Returns GhostError on network failure, a non-2xx HTTP response, or a JSON decoding error.

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