~evhan/chicken-sourcehut

ref: 37dc620efa73034094296bf2631624ec85469542 chicken-sourcehut/sourcehut.builds.scm -rw-r--r-- 1.5 KiB
37dc620eEvan Hanson Fix long option parsing 2 years ago
                                                                                
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
56
57
58
59
60
61
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; REST API bindings for paste.sr.ht
;;;
;;; Copyright (c) 2019-2020, Evan Hanson
;;;
;;; See LICENSE for details.
;;;

(declare (module (sourcehut builds))
         (export job jobs manifest start))

(import (chicken format)
        (chicken keyword)
        (chicken type)
        (sourcehut))

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

(define-inline (make-job #!rest args)
  (keyword-arguments->alist args))


;;
;; https://man.sr.ht/builds.sr.ht/api.md#get-apijobs
;;
(: jobs (-> (list-of pair)))
(define (jobs)
  (make-crud (format "/api/jobs")))

;;
;; https://man.sr.ht/builds.sr.ht/api.md#get-apijobsidmanifest
;;
(: manifest (integer -> (list-of pair)))
(define (manifest id)
  (make-crud (format "/api/jobs/~A/manifest" id)))

;;
;; https://man.sr.ht/builds.sr.ht/api.md#post-apijobsidstart
;;
(: start (integer -> (list-of pair)))
(define (start id)
  (make-crud (format "/api/jobs/~A/start" id)))

;;
;; https://man.sr.ht/builds.sr.ht/api.md#get-apijobsid
;; https://man.sr.ht/builds.sr.ht/api.md#post-apijobs
;;
(: job (#!optional integer #!rest any -> (list-of pair)))
(define (job #!optional id #!rest details)
  (cond
    ((integer? id)
     (make-crud (format "/api/jobs/~A" id)))
    ((get-keyword #:manifest (cons id details))
     (make-crud "/api/jobs" (apply make-job id details)))
    (else
     (signal-condition
      '(sourcehut)
      '(arity)
      '(exn location job message "job id or #:manifest must be given")))))