~evhan/chicken-sourcehut

ref: 60c9a2d2d4e282eb37c637d21b9c625283083734 chicken-sourcehut/topham.builds.scm -rw-r--r-- 1.4 KiB
60c9a2d2Evan Hanson Add missing space to command in README 3 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; REST API bindings for paste.sr.ht
;;;
;;; Copyright (c) 2019, Evan Hanson
;;;
;;; See LICENSE for details.
;;;

(declare (module (topham builds))
         (export job manifest start))

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

(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-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
      '(topham)
      '(arity)
      '(exn location job message "job id or #:manifest must be given")))))