ref: 0.1.6 topham/topham.paste.scm -rw-r--r-- 1.5 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; REST API bindings for paste.sr.ht
;;;
;;; Copyright (c) 2019, Evan Hanson
;;;
;;; See LICENSE for details.
;;;

(declare (module (topham paste))
         (export blob paste pastes))

(import (chicken format)
        (chicken keyword)
        (chicken type)
        (topham))

(define-inline (make-crud path #!optional (body '()))
  `((#:service "paste" #:path ,path) . ,body))

(define-inline (make-paste #!key (filename 'null) contents (visibility "unlisted"))
  `((visibility . ,visibility)
    (files . #(((filename . ,filename)
                (contents . ,contents))))))

;;
;; https://man.sr.ht/paste.sr.ht/api.md#get-apipastes
;;
(: pastes (-> (list-of pair)))
(define (pastes)
  (make-crud "/api/pastes"))

;;
;; https://man.sr.ht/paste.sr.ht/api.md#get-apiblobssha
;;
(: blob (string -> (list-of pair)))
(define (blob sha)
  (make-crud (format "/api/blobs/~A" sha)))

;;
;; https://man.sr.ht/paste.sr.ht/api.md#get-apipastessha
;; https://man.sr.ht/paste.sr.ht/api.md#post-apipastes
;;
(: paste (#!optional any #!rest any -> (list-of pair)))
(define (paste #!optional id #!rest details)
  (cond
    ((string? id)
     (make-crud (format "/api/pastes/~A" id)))
    ((get-keyword #:contents (cons id details))
     (make-crud "/api/pastes" (apply make-paste id details)))
    (else
     (signal-condition
      '(topham)
      '(arity)
      '(exn location paste message "paste id or #:contents must be given")))))