Commitb0d8af0eRecorded25 Mar 2026Repositorysigil-twitch

Remove local url-encode-value and build-query-string, import from (sigil http)

Message

Sub-modules now import build-query-string directly from (sigil http). Test updated for uppercase hex encoding (%3D vs %3d).

Changed
 src/twitch.sgl           | 41 +----------------------------------------
 src/twitch/analytics.sgl |  1 +
 src/twitch/chat.sgl      |  1 +
 src/twitch/eventsub.sgl  |  1 +
 src/twitch/schedule.sgl  |  1 +
 test/twitch-test.sgl     |  3 ++-
 6 files changed, 7 insertions(+), 41 deletions(-)
Diff
src/twitch.sglmodified
@@ -13,6 +13,7 @@
13
(sigil string)
14
(sigil struct)
15
(sigil json)
+16
(only (sigil http) url-encode-value build-query-string)
17
(sigil http client))
18
19
(export ;; Client
@@ -63,8 +64,6 @@
64
twitch-put/json
65
twitch-patch/json
66
twitch-delete/json
66
url-encode-value
67
build-query-string
67
build-repeated-params
68
ensure-list
69
check-twitch-response
@@ -139,44 +138,6 @@
138
(apply string-append (twitch-client-base-url client)
139
(map (lambda (p) (string-append "/" p)) parts)))
140
142
;; No shared url-encode exists in sigil-http (known gap).
143
(define (url-encode-value s)
144
(let ((len (string-length s)))
145
(let loop ((i 0) (acc '()))
146
(if (>= i len)
147
(list->string (reverse acc))
148
(let ((c (string-ref s i)))
149
(cond
150
((or (char-alphabetic? c)
151
(char-numeric? c)
152
(char=? c #\-)
153
(char=? c #\_)
154
(char=? c #\.)
155
(char=? c #\~))
156
(loop (+ i 1) (cons c acc)))
157
((char=? c #\space)
158
(loop (+ i 1) (cons #\+ acc)))
159
(else
160
(let ((n (char->integer c)))
161
(loop (+ i 1)
162
(append (reverse (string->list
163
(string-append "%"
164
(if (< n 16) "0" "")
165
(number->string n 16))))
166
acc))))))))))
167
168
;;; Build a query string from (key . value) pairs.
169
;;; Pairs with #f values are omitted.
170
(define (build-query-string params)
171
(let ((parts (filter (lambda (p) (cdr p)) params)))
172
(if (null? parts)
173
""
174
(string-append "?"
175
(string-join
176
(map (lambda (p)
177
(string-append (car p) "=" (url-encode-value (cdr p))))
178
parts)
179
"&")))))
141
142
;;; Build repeated query params for Twitch-style multi-value parameters.
143
;;; e.g., (build-repeated-params "id" '("1" "2")) => "id=1&id=2"
src/twitch/analytics.sglmodified
@@ -10,6 +10,7 @@
10
(sigil string)
11
(sigil struct)
12
(sigil json)
+13
(only (sigil http) build-query-string)
14
(sigil http client)
15
(twitch))
16
src/twitch/chat.sglmodified
@@ -9,6 +9,7 @@
9
(sigil string)
10
(sigil struct)
11
(sigil json)
+12
(only (sigil http) build-query-string)
13
(sigil http client)
14
(twitch))
15
src/twitch/eventsub.sglmodified
@@ -21,6 +21,7 @@
21
(sigil string)
22
(sigil struct)
23
(sigil json)
+24
(only (sigil http) build-query-string)
25
(sigil http client)
26
(twitch))
27
src/twitch/schedule.sglmodified
@@ -12,6 +12,7 @@
12
(sigil string)
13
(sigil struct)
14
(sigil json)
+15
(only (sigil http) build-query-string)
16
(sigil http client)
17
(twitch))
18
test/twitch-test.sglmodified
@@ -9,6 +9,7 @@
9
(sigil struct)
10
(sigil json)
11
(sigil test)
+12
(only (sigil http) url-encode-value build-query-string)
13
(twitch))
14
15
;; ---------------------------------------------------------------
@@ -266,7 +267,7 @@
267
(assert-equal "foo%26bar" (url-encode-value "foo&bar")))
268
269
(test "encode equals sign"
269
(assert-equal "key%3dvalue" (url-encode-value "key=value")))
+270
(assert-equal "key%3Dvalue" (url-encode-value "key=value")))
271
272
(test "preserve unreserved characters"
273
(assert-equal "a-b_c.d~e" (url-encode-value "a-b_c.d~e"))))