pub struct DiscourseClient { /* private fields */ }Expand description
HTTP client for the Discourse API.
Implementations§
Source§impl DiscourseClient
impl DiscourseClient
pub fn list_api_keys(&self) -> Result<Vec<ApiKeySummary>>
Sourcepub fn create_api_key(
&self,
description: &str,
username: Option<&str>,
) -> Result<CreatedApiKey>
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.
pub fn revoke_api_key(&self, key_id: u64) -> Result<()>
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn create_backup(&self) -> Result<()>
pub fn create_backup(&self) -> Result<()>
Trigger a backup on the Discourse instance.
Sourcepub fn list_backups(&self) -> Result<Value>
pub fn list_backups(&self) -> Result<Value>
List backups available on the Discourse instance.
Sourcepub fn restore_backup(&self, backup_path: &str) -> Result<()>
pub fn restore_backup(&self, backup_path: &str) -> Result<()>
Restore a backup by filename/path.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn fetch_category(&self, category_id: u64) -> Result<CategoryResponse>
pub fn fetch_category(&self, category_id: u64) -> Result<CategoryResponse>
Fetch a category by ID (topics list included).
Sourcepub fn fetch_categories(&self) -> Result<Vec<CategoryInfo>>
pub fn fetch_categories(&self) -> Result<Vec<CategoryInfo>>
Fetch all categories.
Sourcepub fn create_category(&self, category: &CategoryInfo) -> Result<u64>
pub fn create_category(&self, category: &CategoryInfo) -> Result<u64>
Create a category with basic fields copied from a source category.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn new(config: &DiscourseConfig) -> Result<Self>
pub fn new(config: &DiscourseConfig) -> Result<Self>
Create a new Discourse API client.
Sourcepub fn fetch_site_title(&self) -> Result<String>
pub fn fetch_site_title(&self) -> Result<String>
Fetch the Discourse site title.
Sourcepub fn fetch_version_info(&self) -> Result<VersionInfo>
pub fn fetch_version_info(&self) -> Result<VersionInfo>
Fetch the current Discourse version and commit hash.
Sourcepub fn fetch_version(&self) -> Result<Option<String>>
pub fn fetch_version(&self) -> Result<Option<String>>
Fetch the current Discourse version (best-effort).
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn upload_emoji(&self, emoji_path: &Path, emoji_name: &str) -> Result<()>
pub fn upload_emoji(&self, emoji_path: &Path, emoji_name: &str) -> Result<()>
Upload a custom emoji. Retries on 429 via the shared client helper.
Sourcepub fn list_custom_emojis(&self) -> Result<Vec<CustomEmoji>>
pub fn list_custom_emojis(&self) -> Result<Vec<CustomEmoji>>
List custom emojis.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn fetch_groups(&self) -> Result<Vec<GroupSummary>>
pub fn fetch_groups(&self) -> Result<Vec<GroupSummary>>
Fetch all groups.
Sourcepub fn fetch_group_detail(
&self,
group_id: u64,
group_name: Option<&str>,
) -> Result<GroupDetail>
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).
pub fn fetch_group_members( &self, group_id: u64, group_name: Option<&str>, ) -> Result<Vec<GroupMember>>
Sourcepub fn create_group(&self, group: &GroupDetail) -> Result<u64>
pub fn create_group(&self, group: &GroupDetail) -> Result<u64>
Create a group with detailed settings copied from a source group.
Sourcepub fn add_group_members_by_username(
&self,
group_id: u64,
usernames: &[String],
notify_users: bool,
) -> Result<AddMembersOutcome>
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).
Sourcepub fn remove_group_members_by_username(
&self,
group_id: u64,
usernames: &[String],
) -> Result<()>
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).
Sourcepub fn fetch_user_groups(&self, username: &str) -> Result<Vec<GroupSummary>>
pub fn fetch_user_groups(&self, username: &str) -> Result<Vec<GroupSummary>>
Return the list of groups a user belongs to, by username.
Sourcepub fn add_group_members_by_email(
&self,
group_id: u64,
emails: &[String],
notify_users: bool,
) -> Result<AddMembersOutcome>
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
impl DiscourseClient
Sourcepub fn create_invite(
&self,
email: &str,
group_ids: &[u64],
topic_id: Option<u64>,
custom_message: Option<&str>,
) -> Result<InviteResult>
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
impl DiscourseClient
Sourcepub fn list_color_schemes(&self) -> Result<Value>
pub fn list_color_schemes(&self) -> Result<Value>
List color schemes (palettes) available on the Discourse instance.
Sourcepub fn fetch_color_scheme(&self, scheme_id: u64) -> Result<Value>
pub fn fetch_color_scheme(&self, scheme_id: u64) -> Result<Value>
Fetch a color scheme (palette) by ID.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn list_plugins(&self) -> Result<Value>
pub fn list_plugins(&self) -> Result<Value>
List installed plugins on the Discourse instance.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn fetch_admin_report(
&self,
report_id: &str,
start: &str,
end: &str,
) -> Result<AdminReport>
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
impl DiscourseClient
Sourcepub fn update_site_setting(&self, setting: &str, value: &str) -> Result<()>
pub fn update_site_setting(&self, setting: &str, value: &str) -> Result<()>
Update a site setting by name (admin only).
Sourcepub fn list_site_settings(&self) -> Result<Value>
pub fn list_site_settings(&self) -> Result<Value>
Fetch all site settings (admin only). Returns raw JSON value.
Sourcepub fn list_site_settings_detailed(&self) -> Result<Vec<SiteSettingDetail>>
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.
Sourcepub fn fetch_site_setting(&self, setting: &str) -> Result<String>
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
impl DiscourseClient
List every tag visible to the authenticated user.
Sourcepub fn get_tag_description(&self, tag_name: &str) -> Result<Option<String>>
pub fn get_tag_description(&self, tag_name: &str) -> Result<Option<String>>
Fetch tag description via the tag detail endpoint.
Sourcepub fn list_tag_groups(&self) -> Result<Option<Vec<TagGroupInfo>>>
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).
Sourcepub fn create_tag_group(&self, payload: &Value) -> Result<u64>
pub fn create_tag_group(&self, payload: &Value) -> Result<u64>
Create a tag group. Returns the created group’s ID.
Sourcepub fn update_tag_group(&self, group_id: u64, payload: &Value) -> Result<()>
pub fn update_tag_group(&self, group_id: u64, payload: &Value) -> Result<()>
Update an existing tag group.
Sourcepub fn delete_tag_group(&self, group_id: u64) -> Result<()>
pub fn delete_tag_group(&self, group_id: u64) -> Result<()>
Delete a tag group.
Sourcepub fn update_tag(
&self,
tag_name: &str,
description: Option<&str>,
) -> Result<()>
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.
Sourcepub fn rename_tag(&self, old_name: &str, new_name: &str) -> Result<()>
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.
Sourcepub fn delete_tag(&self, tag_name: &str) -> Result<()>
pub fn delete_tag(&self, tag_name: &str) -> Result<()>
Delete a tag.
Fetch the current tag list for a topic.
Replace the full tag list on a topic. Returns the resulting tag set.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn list_themes(&self) -> Result<Value>
pub fn list_themes(&self) -> Result<Value>
List installed themes on the Discourse instance.
Sourcepub fn fetch_theme(&self, theme_id: u64) -> Result<Value>
pub fn fetch_theme(&self, theme_id: u64) -> Result<Value>
Fetch a single theme by ID.
Sourcepub fn create_theme(&self, theme: &Value) -> Result<u64>
pub fn create_theme(&self, theme: &Value) -> Result<u64>
Create a new theme and return its ID.
Sourcepub fn delete_theme(&self, theme_id: u64) -> Result<()>
pub fn delete_theme(&self, theme_id: u64) -> Result<()>
Delete a theme by ID.
Source§impl DiscourseClient
impl DiscourseClient
Sourcepub fn fetch_topic(
&self,
topic_id: u64,
include_raw: bool,
) -> Result<TopicResponse>
pub fn fetch_topic( &self, topic_id: u64, include_raw: bool, ) -> Result<TopicResponse>
Fetch a topic by ID.
Sourcepub fn fetch_topic_all_posts(&self, topic_id: u64) -> Result<TopicResponse>
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).
Sourcepub fn fetch_post_raw(&self, post_id: u64) -> Result<Option<String>>
pub fn fetch_post_raw(&self, post_id: u64) -> Result<Option<String>>
Fetch a post by ID and return its raw content.
Sourcepub fn fetch_post(&self, post_id: u64) -> Result<PostInfo>
pub fn fetch_post(&self, post_id: u64) -> Result<PostInfo>
Fetch a post’s metadata (id, topic_id, post_number, raw).
Sourcepub fn delete_post(&self, post_id: u64) -> Result<()>
pub fn delete_post(&self, post_id: u64) -> Result<()>
Soft-delete a post by ID (DELETE /posts/:id.json).
Sourcepub fn move_posts(
&self,
source_topic_id: u64,
post_ids: &[u64],
dest_topic_id: u64,
) -> Result<String>
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.
Sourcepub fn create_topic(
&self,
category_id: u64,
title: &str,
raw: &str,
) -> Result<u64>
pub fn create_topic( &self, category_id: u64, title: &str, raw: &str, ) -> Result<u64>
Create a new topic in a category.
Sourcepub fn create_private_message(
&self,
recipients: &[String],
title: &str,
raw: &str,
) -> Result<u64>
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.
Sourcepub fn list_private_messages(
&self,
username: &str,
direction: &str,
) -> Result<Vec<PmTopicSummary>>
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§impl DiscourseClient
impl DiscourseClient
Sourcepub fn upload_file(
&self,
file_path: &Path,
upload_type: &str,
) -> Result<UploadInfo>
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
impl DiscourseClient
Sourcepub fn fetch_user_actions(
&self,
username: &str,
filter_types: &[u32],
offset: u32,
) -> Result<Vec<UserAction>>
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
impl DiscourseClient
Sourcepub fn admin_list_users(
&self,
listing: &str,
page: u32,
) -> Result<Vec<UserSummary>>
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.
Sourcepub fn fetch_user_detail(&self, username: &str) -> Result<UserDetail>
pub fn fetch_user_detail(&self, username: &str) -> Result<UserDetail>
Look up a user by username (public endpoint).
Sourcepub fn suspend_user(
&self,
user_id: i64,
until: &str,
reason: &str,
) -> Result<()>
pub fn suspend_user( &self, user_id: i64, 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.
Sourcepub fn unsuspend_user(&self, user_id: i64) -> Result<()>
pub fn unsuspend_user(&self, user_id: i64) -> Result<()>
Unsuspend a user by ID.
Sourcepub fn silence_user(
&self,
user_id: i64,
until: &str,
reason: &str,
) -> Result<()>
pub fn silence_user( &self, user_id: i64, until: &str, reason: &str, ) -> Result<()>
Silence a user by ID. Optional silenced_till (Discourse-accepted
timestamp string) and reason; both default to empty.
Sourcepub fn unsilence_user(&self, user_id: i64) -> Result<()>
pub fn unsilence_user(&self, user_id: i64) -> Result<()>
Unsilence a user by ID.
Sourcepub fn grant_admin(&self, user_id: i64) -> Result<()>
pub fn grant_admin(&self, user_id: i64) -> Result<()>
Grant admin to a user.
Sourcepub fn revoke_admin(&self, user_id: i64) -> Result<()>
pub fn revoke_admin(&self, user_id: i64) -> Result<()>
Revoke admin from a user.
Sourcepub fn grant_moderation(&self, user_id: i64) -> Result<()>
pub fn grant_moderation(&self, user_id: i64) -> Result<()>
Grant moderator to a user.
Sourcepub fn revoke_moderation(&self, user_id: i64) -> Result<()>
pub fn revoke_moderation(&self, user_id: i64) -> Result<()>
Revoke moderator from a user.
Sourcepub fn create_user(
&self,
email: &str,
username: &str,
password: Option<&str>,
name: Option<&str>,
approve: bool,
) -> Result<i64>
pub fn create_user( &self, email: &str, username: &str, password: Option<&str>, name: Option<&str>, approve: bool, ) -> Result<i64>
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.
Sourcepub fn trigger_password_reset(&self, login: &str) -> Result<()>
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).
Trait Implementations§
Source§impl Clone for DiscourseClient
impl Clone for DiscourseClient
Source§fn clone(&self) -> DiscourseClient
fn clone(&self) -> DiscourseClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more