AtlatestRepositorysigil-discourse
1;;; (discourse topics) - Topic management.
2;;;
3;;; Functions for listing, creating, updating, and managing the status
4;;; of Discourse topics.
5
6(define-library (discourse topics)
7 (import (sigil core)
8 (sigil string)
9 (discourse client))
11 (export discourse-list-latest-topics
12 discourse-list-top-topics
13 discourse-list-category-topics
14 discourse-get-topic
15 discourse-create-topic
16 discourse-update-topic
17 discourse-set-topic-status
18 discourse-delete-topic
19 discourse-invite-to-topic)
21 (begin
23 ;;; List the latest topics on the forum.
24 (define (discourse-list-latest-topics base-url api-key username)
25 (discourse-get/json api-key username
26 (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 username
31 (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 username
36 (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 username
41 (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 username
48 (discourse-url base-url "posts.json")
49 #{ title: title
50 raw: raw
51 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 username
56 (discourse-url base-url "t" "-" (string-append (number->string topic-id) ".json"))
57 #{ title: title
58 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 disable
64 (define (discourse-set-topic-status base-url api-key username topic-id status enabled)
65 (discourse-put/json api-key username
66 (discourse-url base-url "t" (number->string topic-id) "status")
67 #{ status: status
68 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 username
73 (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 username
80 (discourse-url base-url "t" (number->string topic-id) "invite.json")
81 #{ user: user }))
83 ))