-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ss
148 lines (127 loc) · 4.26 KB
/
api.ss
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#lang scheme
(require "base.ss")
(require srfi/19
"config.ss"
"request.ss"
"result-parse.ss"
"result-struct.ss"
"url.ss")
; API wrapper procedures -----------------------
; -> date
(define (last-updated)
(parse-update-element
(send-request (last-updated-url))))
; -> (alist-of string integer)
(define (get-tags)
(parse-tags-element
(send-request (get-tags-url))))
; string string -> void
(define (rename-tag! old new)
(parse-result-element
(send-request (rename-tag-url old new))))
; [(U string void)]
; [(U date void)]
; [(U string void)]
; ->
; (listof post)
(define (get-posts [tag (void)] [date (void)] [url (void)])
(parse-posts-element
(send-request (get-posts-url tag date url))))
; [(U string void)] [(U number void)] -> (listof post)
(define (recent-posts [tag (void)] [count (void)])
(parse-posts-element
(send-request (recent-posts-url tag count))))
; [(U string void)] -> (listof post)
(define (all-posts [tag (void)])
(parse-posts-element
(send-request (all-posts-url tag))))
; [(U string void)] -> (alist-of date integer)
(define (post-dates [tag (void)])
(parse-dates-element
(send-request (post-dates-url tag))))
; post
; [(U boolean void)]
; [(U boolean void)]
; ->
; void
(define (add-post! p [replace? (void)] [shared? (void)])
(match p
[(struct post (url description extended tags date))
(add-post/raw! url
description
(if extended extended (void))
(if (null? tags) (void) tags)
(if date date (void))
replace?
shared?)]))
; string
; string
; [(U string void)]
; [(U (listof string) void)]
; [(U date void)]
; [(U boolean void)]
; [(U boolean void)]
; ->
; void
(define (add-post/raw! url description [extended (void)] [tags (void)] [date (void)] [replace? (void)] [shared? (void)])
(parse-result-element
(send-request (add-post-url url description extended tags date replace? shared?))))
; post -> void
(define (delete-post! post)
(delete-post/raw! (post-url post)))
; string -> void
(define (delete-post/raw! url)
(parse-result-element
(send-request (delete-post-url url))))
; -> (listof bundle)
(define (all-bundles)
(parse-bundles-element
(send-request (all-bundles-url))))
; bundle -> void
(define (update-bundle! bundle)
(update-bundle/raw! (bundle-name bundle)
(bundle-tags bundle)))
; string (listof string) -> void
(define (update-bundle/raw! name tags)
(parse-result-element
(send-request (set-bundle-url name tags))))
; bundle -> void
(define (delete-bundle! bundle)
(delete-bundle/raw! (bundle-name bundle)))
; string -> void
(define (delete-bundle/raw! name)
(parse-result-element
(send-request (delete-bundle-url name))))
; Provide statements ---------------------------
(provide/contract
[last-updated (-> date?)]
[get-tags (-> (listof (cons/c string? integer?)))]
[rename-tag! (-> string? string? void?)]
[get-posts (->* ()
((maybe/c string?)
(maybe/c date?)
(maybe/c string?))
(listof post?))]
[recent-posts (->* ()
((maybe/c string?) (maybe/c (and/c integer? (between/c 0 100))))
(listof post?))]
[all-posts (->* () ((maybe/c string?)) (listof post?))]
[post-dates (->* () ((maybe/c string?)) (listof (cons/c date? integer?)))]
[add-post! (->* (post?)
((maybe/c boolean?)
(maybe/c boolean?))
void?)]
[add-post/raw! (->* (string? string?)
((maybe/c string?)
(maybe/c (listof string?))
(maybe/c date?)
(maybe/c boolean?)
(maybe/c boolean?))
void?)]
[delete-post! (-> post? void?)]
[delete-post/raw! (-> string? void?)]
[all-bundles (-> (listof string?))]
[update-bundle! (-> bundle? void?)]
[update-bundle/raw! (-> string? (listof string?) void?)]
[delete-bundle! (-> bundle? void?)]
[delete-bundle/raw! (-> string? void?)])