diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2020-07-08 10:48:35 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2020-07-08 10:48:35 +0900 |
commit | 9a63f2aebc1a1d15c04915cd27ee72027768d116 (patch) | |
tree | b101783c1f466ca6412a56821092e97a5ab3a2bd | |
parent | c1c2e93f6ea0238444ebaf46f19f13387ac9f99a (diff) |
qkbox: toot: Add favourite and unfavourite procedures.
-rw-r--r-- | qkbox/toot.scm | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/qkbox/toot.scm b/qkbox/toot.scm index 3bbc856..0ccad60 100644 --- a/qkbox/toot.scm +++ b/qkbox/toot.scm @@ -41,6 +41,7 @@ (request 'POST "/api/v1/statuses" + #:json `(,@(if status `((status . ,(if (string? status) status @@ -91,6 +92,7 @@ (request 'GET "/api/v1/timelines/home" + #:json `(,@(if max-id `((max-id . ,max-id)) '()) ,@(if since-id `((since-id . ,since-id)) '()) ,@(if min-id `((min-id . ,min-id)) '()) @@ -98,7 +100,36 @@ ,@(if local? `((local . ,local?)) '())) #:authorization? #t)) -(define* (request method path json #:key authorization?) + +(define (favourite id) + (define-values (res body) + (/api/v1/statuses/:id/favourite id)) + (case (response-code res) + ((200) #t) + (else + (error "favourite: failed" res body)))) + +(define (/api/v1/statuses/:id/favourite id) + (request + 'POST + (format #f "/api/v1/statuses/~a/favourite" id) + #:authorization? #t)) + +(define (unfavourite id) + (define-values (res body) + (/api/v1/statuses/:id/unfavourite id)) + (case (response-code res) + ((200) #t) + (else + (error "unfavourite: failed" res body)))) + +(define (/api/v1/statuses/:id/unfavourite id) + (request + 'POST + (format #f "/api/v1/statuses/~a/unfavourite" id) + #:authorization? #t)) + +(define* (request method path #:key json authorization?) (define-values (res body) (http-request (string-append "https://" (current-mastodon-host) @@ -113,7 +144,9 @@ (current-mastodon-access-token))))) '())) #:decode-body? #t - #:body (scm->json-string json))) + #:body (if json + (scm->json-string json) + #f))) (if (= 200 (response-code res)) (values res (json-string->scm (utf8->string body))) (values res body))) |