AtlatestRepositorysigil-discourse
sigil-discourse / tree / src / discoursetopics.sgl
1
;;; (discourse topics) - Topic management.2
;;;3
;;; Functions for listing, creating, updating, and managing the status4
;;; of Discourse topics.6
(define-library (discourse topics)7
(import (sigil core)8
(sigil string)9
(discourse client))11
(export discourse-list-latest-topics12
discourse-list-top-topics13
discourse-list-category-topics14
discourse-get-topic15
discourse-create-topic16
discourse-update-topic17
discourse-set-topic-status18
discourse-delete-topic19
discourse-invite-to-topic)21
(begin23
;;; List the latest topics on the forum.24
(define (discourse-list-latest-topics base-url api-key username)25
(discourse-get/json api-key username26
(discourse-url base-url "latest.json")))28
;;; List the top topics on the forum.29
(define (discourse-list-top-topics base-url api-key username)30
(discourse-get/json api-key username31
(discourse-url base-url "top.json")))33
;;; List topics in a specific category.34
(define (discourse-list-category-topics base-url api-key username slug category-id)35
(discourse-get/json api-key username36
(discourse-url base-url "c" slug (number->string category-id) ".json")))38
;;; Get a specific topic by ID.39
(define (discourse-get-topic base-url api-key username topic-id)40
(discourse-get/json api-key username41
(discourse-url base-url "t" (string-append (number->string topic-id) ".json"))))43
;;; Create a new topic.44
;;;45
;;; Discourse creates topics via the posts endpoint with a title field.46
(define (discourse-create-topic base-url api-key username title raw category-id)47
(discourse-post/json api-key username48
(discourse-url base-url "posts.json")49
#{ title: title50
raw: raw51
category: category-id }))53
;;; Update a topic's title or category.54
(define (discourse-update-topic base-url api-key username topic-id title category-id)55
(discourse-put/json api-key username56
(discourse-url base-url "t" "-" (string-append (number->string topic-id) ".json"))57
#{ title: title58
category_id: category-id }))60
;;; Set the status of a topic (closed, pinned, archived, etc.).61
;;;62
;;; status: "closed", "pinned", "archived", "visible"63
;;; enabled: #t to enable, #f to disable64
(define (discourse-set-topic-status base-url api-key username topic-id status enabled)65
(discourse-put/json api-key username66
(discourse-url base-url "t" (number->string topic-id) "status")67
#{ status: status68
enabled: (if enabled "true" "false") }))70
;;; Delete a topic.71
(define (discourse-delete-topic base-url api-key username topic-id)72
(discourse-delete api-key username73
(discourse-url base-url "t" (string-append (number->string topic-id) ".json"))))75
;;; Invite a user to a topic by email or username.76
;;;77
;;; user is an email address or username string.78
(define (discourse-invite-to-topic base-url api-key username topic-id user)79
(discourse-post/json api-key username80
(discourse-url base-url "t" (number->string topic-id) "invite.json")81
#{ user: user }))83
))