Skip to main content

DiscourseClient

Struct DiscourseClient 

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

HTTP client for the Discourse API.

Implementations§

Source§

impl DiscourseClient

Source

pub fn list_api_keys(&self) -> Result<Vec<ApiKeySummary>>

Source

pub fn create_api_key( &self, description: &str, username: Option<&str>, ) -> Result<CreatedApiKey>

Create a new API key. username of None makes a global all-users key.

Source

pub fn revoke_api_key(&self, key_id: u64) -> Result<()>

Source§

impl DiscourseClient

Source

pub fn create_backup(&self) -> Result<()>

Trigger a backup on the Discourse instance.

Source

pub fn list_backups(&self) -> Result<Value>

List backups available on the Discourse instance.

Source

pub fn restore_backup(&self, backup_path: &str) -> Result<()>

Restore a backup by filename/path.

Source§

impl DiscourseClient

Source

pub fn fetch_category(&self, category_id: u64) -> Result<CategoryResponse>

Fetch a category by ID (topics list included).

Source

pub fn fetch_categories(&self) -> Result<Vec<CategoryInfo>>

Fetch all categories.

Source

pub fn create_category(&self, category: &CategoryInfo) -> Result<u64>

Create a category with basic fields copied from a source category.

Source§

impl DiscourseClient

Source

pub fn new(config: &DiscourseConfig) -> Result<Self>

Create a new Discourse API client.

Source

pub fn baseurl(&self) -> &str

Return the configured base URL.

Source

pub fn fetch_site_title(&self) -> Result<String>

Fetch the Discourse site title.

Source

pub fn fetch_version_info(&self) -> Result<VersionInfo>

Fetch the current Discourse version and commit hash.

Source

pub fn fetch_version(&self) -> Result<Option<String>>

Fetch the current Discourse version (best-effort).

Source§

impl DiscourseClient

Source

pub fn upload_emoji(&self, emoji_path: &Path, emoji_name: &str) -> Result<()>

Upload a custom emoji. Retries on 429 via the shared client helper.

Source

pub fn list_custom_emojis(&self) -> Result<Vec<CustomEmoji>>

List custom emojis.

Source§

impl DiscourseClient

Source

pub fn fetch_groups(&self) -> Result<Vec<GroupSummary>>

Fetch all groups.

Source

pub fn fetch_group_detail( &self, group_id: u64, group_name: Option<&str>, ) -> Result<GroupDetail>

Fetch group details by ID (fallbacks to name lookup if needed).

Source

pub fn fetch_group_members( &self, group_id: u64, group_name: Option<&str>, ) -> Result<Vec<GroupMember>>

Source

pub fn create_group(&self, group: &GroupDetail) -> Result<u64>

Create a group with detailed settings copied from a source group.

Source

pub fn add_group_members_by_username( &self, group_id: u64, usernames: &[String], notify_users: bool, ) -> Result<AddMembersOutcome>

Add members to a group by username (PUT /groups/:id/members.json).

Source

pub fn remove_group_members_by_username( &self, group_id: u64, usernames: &[String], ) -> Result<()>

Remove members from a group by username (DELETE /groups/:id/members.json).

Source

pub fn fetch_user_groups(&self, username: &str) -> Result<Vec<GroupSummary>>

Return the list of groups a user belongs to, by username.

Source

pub fn add_group_members_by_email( &self, group_id: u64, emails: &[String], notify_users: bool, ) -> Result<AddMembersOutcome>

Add members to a group by email (PUT /groups/:id/members.json).

Returns a tuple of (added_usernames, not_found_emails) parsed loosely from the response; both lists may be empty on success if the response doesn’t surface them.

Source§

impl DiscourseClient

Source

pub fn create_invite( &self, email: &str, group_ids: &[u64], topic_id: Option<u64>, custom_message: Option<&str>, ) -> Result<InviteResult>

Create a single email invite.

group_ids is sent as comma-joined group_ids (Discourse accepts both group_ids[]=... repetition and a single comma-list; the latter is simpler in form-encoded bodies). topic_id and custom_message are optional. Returns the created invite (including the magic link).

Source§

impl DiscourseClient

Source

pub fn list_color_schemes(&self) -> Result<Value>

List color schemes (palettes) available on the Discourse instance.

Source

pub fn fetch_color_scheme(&self, scheme_id: u64) -> Result<Value>

Fetch a color scheme (palette) by ID.

Source

pub fn create_color_scheme( &self, name: &str, colors: &BTreeMap<String, String>, ) -> Result<u64>

Create a new color scheme (palette).

Source

pub fn update_color_scheme( &self, scheme_id: u64, name: Option<&str>, colors: &BTreeMap<String, String>, ) -> Result<()>

Update an existing color scheme (palette).

Source§

impl DiscourseClient

Source

pub fn list_plugins(&self) -> Result<Value>

List installed plugins on the Discourse instance.

Source§

impl DiscourseClient

Source

pub fn fetch_admin_report( &self, report_id: &str, start: &str, end: &str, ) -> Result<AdminReport>

Fetch a single admin report. start and end are ISO-8601 date strings (YYYY-MM-DD) — the format Discourse’s report controller expects.

Source§

impl DiscourseClient

Source

pub fn search_topics(&self, query: &str) -> Result<Vec<SearchHit>>

Search for topics. The query is passed through to Discourse verbatim (so callers can use category:, status:, @user, etc. filters).

Source§

impl DiscourseClient

Source

pub fn update_site_setting(&self, setting: &str, value: &str) -> Result<()>

Update a site setting by name (admin only).

Source

pub fn list_site_settings(&self) -> Result<Value>

Fetch all site settings (admin only). Returns raw JSON value.

Source

pub fn list_site_settings_detailed(&self) -> Result<Vec<SiteSettingDetail>>

Fetch all site settings with full metadata (admin only). Returns one SiteSettingDetail per setting, preserving the default, description, category, and type fields.

Source

pub fn fetch_site_setting(&self, setting: &str) -> Result<String>

Fetch a single site setting by name (admin only). Returns the value as a string, or an error if not found.

Source§

impl DiscourseClient

Source

pub fn list_tags(&self) -> Result<Vec<TagInfo>>

List every tag visible to the authenticated user.

Source

pub fn get_tag_description(&self, tag_name: &str) -> Result<Option<String>>

Fetch tag description via the tag detail endpoint.

Source

pub fn list_tag_groups(&self) -> Result<Option<Vec<TagGroupInfo>>>

List tag groups (admin endpoint). Returns Err on non-2xx other than 403; returns Ok(None) on 403 (non-admin key).

Source

pub fn create_tag_group(&self, payload: &Value) -> Result<u64>

Create a tag group. Returns the created group’s ID.

Source

pub fn update_tag_group(&self, group_id: u64, payload: &Value) -> Result<()>

Update an existing tag group.

Source

pub fn delete_tag_group(&self, group_id: u64) -> Result<()>

Delete a tag group.

Source

pub fn update_tag( &self, tag_name: &str, description: Option<&str>, ) -> Result<()>

Update tag metadata (description). Creates the tag implicitly if it doesn’t exist.

Source

pub fn rename_tag(&self, old_name: &str, new_name: &str) -> Result<()>

Rename a tag, preserving topic associations. Discourse accepts a new id (slug) on the tag-update endpoint and reassigns every topic in-place.

Source

pub fn delete_tag(&self, tag_name: &str) -> Result<()>

Delete a tag.

Source

pub fn fetch_topic_tags(&self, topic_id: u64) -> Result<Vec<String>>

Fetch the current tag list for a topic.

Source

pub fn set_topic_tags( &self, topic_id: u64, tags: &[String], ) -> Result<Vec<String>>

Replace the full tag list on a topic. Returns the resulting tag set.

Source§

impl DiscourseClient

Source

pub fn list_themes(&self) -> Result<Value>

List installed themes on the Discourse instance.

Source

pub fn fetch_theme(&self, theme_id: u64) -> Result<Value>

Fetch a single theme by ID.

Source

pub fn create_theme(&self, theme: &Value) -> Result<u64>

Create a new theme and return its ID.

Source

pub fn delete_theme(&self, theme_id: u64) -> Result<()>

Delete a theme by ID.

Source

pub fn update_theme(&self, theme_id: u64, theme: &Value) -> Result<()>

Update an existing theme.

Source§

impl DiscourseClient

Source

pub fn fetch_topic( &self, topic_id: u64, include_raw: bool, ) -> Result<TopicResponse>

Fetch a topic by ID.

Source

pub fn fetch_topic_all_posts(&self, topic_id: u64) -> Result<TopicResponse>

Fetch every post in a topic, in order.

Discourse paginates /t/{id}.json at 20 posts per page. The first response also includes post_stream.stream, the flat array of every post ID in the thread. We page-1 first to learn the stream, then batch-fetch any remaining post IDs via /t/{id}/posts.json?post_ids[]=…&include_raw=1. Returns posts in stream order (matches topic display order).

Source

pub fn fetch_post_raw(&self, post_id: u64) -> Result<Option<String>>

Fetch a post by ID and return its raw content.

Source

pub fn fetch_post(&self, post_id: u64) -> Result<PostInfo>

Fetch a post’s metadata (id, topic_id, post_number, raw).

Source

pub fn delete_post(&self, post_id: u64) -> Result<()>

Soft-delete a post by ID (DELETE /posts/:id.json).

Source

pub fn move_posts( &self, source_topic_id: u64, post_ids: &[u64], dest_topic_id: u64, ) -> Result<String>

Move one or more posts from their current topic to another topic.

source_topic_id is the topic the posts currently live in. post_ids are the post IDs to move. dest_topic_id is where they land. Returns the new URL of the moved posts’ topic.

Source

pub fn update_post(&self, post_id: u64, raw: &str) -> Result<()>

Update a post by ID.

Source

pub fn create_topic( &self, category_id: u64, title: &str, raw: &str, ) -> Result<u64>

Create a new topic in a category.

Source

pub fn create_private_message( &self, recipients: &[String], title: &str, raw: &str, ) -> Result<u64>

Send a private message. recipients is comma-joined into Discourse’s target_recipients field (usernames or group names accepted). Returns the new topic_id of the PM thread.

Source

pub fn list_private_messages( &self, username: &str, direction: &str, ) -> Result<Vec<PmTopicSummary>>

List private messages for the given user. direction is one of inbox (received), sent, archive, unread, new. Returns distilled topic summaries.

Source

pub fn create_post(&self, topic_id: u64, raw: &str) -> Result<u64>

Create a reply post in a topic.

Source§

impl DiscourseClient

Source

pub fn upload_file( &self, file_path: &Path, upload_type: &str, ) -> Result<UploadInfo>

Upload a file. upload_type is Discourse’s type field — typical values: composer (default; for embedding in posts), avatar, profile_background, card_background, custom_emoji.

Source§

impl DiscourseClient

Source

pub fn fetch_user_actions( &self, username: &str, filter_types: &[u32], offset: u32, ) -> Result<Vec<UserAction>>

Fetch a page of a user’s activity. filter_types is a slice of Discourse’s numeric action-type filters (e.g. 4 = new_topic, 5 = reply); they’re joined with commas. offset paginates — Discourse returns ~10 items per page.

Source§

impl DiscourseClient

Source

pub fn admin_list_users( &self, listing: &str, page: u32, ) -> Result<Vec<UserSummary>>

List users via the admin users endpoint.

listing is one of: active (default), new, staff, suspended, silenced, staged. Discourse paginates 100 per page.

Source

pub fn fetch_user_detail(&self, username: &str) -> Result<UserDetail>

Look up a user by username (public endpoint).

Source

pub fn suspend_user( &self, user_id: u64, until: &str, reason: &str, ) -> Result<()>

Suspend a user by ID. until is an ISO-8601 timestamp (or any string Discourse accepts, like “forever”); reason is mandatory from the UI but Discourse accepts empty via the API.

Source

pub fn unsuspend_user(&self, user_id: u64) -> Result<()>

Unsuspend a user by ID.

Source

pub fn silence_user( &self, user_id: u64, until: &str, reason: &str, ) -> Result<()>

Silence a user by ID. Optional silenced_till (Discourse-accepted timestamp string) and reason; both default to empty.

Source

pub fn unsilence_user(&self, user_id: u64) -> Result<()>

Unsilence a user by ID.

Source

pub fn grant_admin(&self, user_id: u64) -> Result<()>

Grant admin to a user.

Source

pub fn revoke_admin(&self, user_id: u64) -> Result<()>

Revoke admin from a user.

Source

pub fn grant_moderation(&self, user_id: u64) -> Result<()>

Grant moderator to a user.

Source

pub fn revoke_moderation(&self, user_id: u64) -> Result<()>

Revoke moderator from a user.

Source

pub fn create_user( &self, email: &str, username: &str, password: Option<&str>, name: Option<&str>, approve: bool, ) -> Result<u64>

Create a user. password is optional — omit to require the new user to reset it via the email flow. active=true and approved=true are passed so admin-created accounts skip the activation and approval dances. Returns the new user id on success.

Source

pub fn trigger_password_reset(&self, login: &str) -> Result<()>

Trigger the “forgot password” email flow for a user. Accepts username or email as login. Discourse returns a generic success message regardless of whether the user exists (to prevent enumeration).

Source

pub fn set_user_email(&self, username: &str, email: &str) -> Result<()>

Admin-set a user’s primary email address.

Trait Implementations§

Source§

impl Clone for DiscourseClient

Source§

fn clone(&self) -> DiscourseClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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