summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2020-07-08 10:37:08 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2020-07-08 10:37:08 +0900
commitc1c2e93f6ea0238444ebaf46f19f13387ac9f99a (patch)
tree2230da26f53fd7438f6db3eab6a432e129bac9db
parent1a47a0dbc7b110763d8d8d3eec776db5efdd30a8 (diff)
qkbox: toot: Add timeline procedure.
-rw-r--r--qkbox/toot.scm66
1 files changed, 50 insertions, 16 deletions
diff --git a/qkbox/toot.scm b/qkbox/toot.scm
index a90389b..3bbc856 100644
--- a/qkbox/toot.scm
+++ b/qkbox/toot.scm
@@ -5,7 +5,7 @@
#:use-module (json builder)
#:use-module (json parser)
#:use-module (rnrs bytevectors)
- #:export (post))
+ #:export (post timeline))
(define current-mastodon-host
(make-parameter (getenv "MASTODON_HOST")))
@@ -38,7 +38,8 @@
sensitive?
reply-to
media-ids)
- (post-json
+ (request
+ 'POST
"/api/v1/statuses"
`(,@(if status
`((status . ,(if (string? status)
@@ -65,21 +66,54 @@
'()))
#:authorization? #t))
-(define* (post-json path json #:key authorization?)
+(define* (timeline #:key max-id since-id min-id limit local?)
(define-values (res body)
- (http-post (string-append "https://"
- (current-mastodon-host)
- path)
- #:headers `((content-type application/json)
- ,@(if authorization?
- `((authorization
- ,(string->symbol
- (string-append
- "Bearer "
- (current-mastodon-access-token)))))
- '()))
- #:decode-body? #t
- #:body (scm->json-string json)))
+ (/api/v1/timelines/home #:max-id max-id
+ #:since-id since-id
+ #:min-id min-id
+ #:limit limit
+ #:local? local?))
+ (case (response-code res)
+ ((200)
+ (map (lambda (status)
+ `((id . ,(assoc-ref status "id"))
+ (name . ,(assoc-ref (assoc-ref status "account")
+ "display_name"))
+ (url . ,(assoc-ref status "url"))
+ (content . ,(assoc-ref status "content"))))
+ (vector->list body)))
+ ((206)
+ (error "timeline: Home feed is regenerating"))
+ (else
+ (error "timeline: failed" res body))))
+
+(define* (/api/v1/timelines/home #:key max-id since-id min-id limit local?)
+ (request
+ 'GET
+ "/api/v1/timelines/home"
+ `(,@(if max-id `((max-id . ,max-id)) '())
+ ,@(if since-id `((since-id . ,since-id)) '())
+ ,@(if min-id `((min-id . ,min-id)) '())
+ ,@(if limit `((limit . ,limit)) '())
+ ,@(if local? `((local . ,local?)) '()))
+ #:authorization? #t))
+
+(define* (request method path json #:key authorization?)
+ (define-values (res body)
+ (http-request (string-append "https://"
+ (current-mastodon-host)
+ path)
+ #:method method
+ #:headers `((content-type application/json)
+ ,@(if authorization?
+ `((authorization
+ ,(string->symbol
+ (string-append
+ "Bearer "
+ (current-mastodon-access-token)))))
+ '()))
+ #:decode-body? #t
+ #:body (scm->json-string json)))
(if (= 200 (response-code res))
(values res (json-string->scm (utf8->string body)))
(values res body)))