Commit3e594802Recorded25 Mar 2026Repositorysigil-youtube
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) instead of re-exporting through (youtube). Test updated for uppercase hex encoding (%3D vs %3d) which is RFC 3986 compliant.
Changed
src/youtube.sgl | 40 +---------------------------------------
src/youtube/analytics.sgl | 1 +
src/youtube/live.sgl | 1 +
src/youtube/playlist.sgl | 1 +
src/youtube/upload.sgl | 1 +
test/youtube-test.sgl | 3 ++-
6 files changed, 7 insertions(+), 40 deletions(-)Diff
src/youtube.sglmodified
@@ -15,6 +15,7 @@
15
(sigil string) 16
(sigil struct) 17
(sigil json)+18
(only (sigil http) url-encode-value build-query-string) 19
(sigil http client)) 20
21
(export ;; Client@@ -54,8 +55,6 @@
55
youtube-post/json 56
youtube-put/json 57
youtube-delete/json−57
url-encode-value−58
build-query-string 58
check-youtube-response 59
60
;; Parsing@@ -119,43 +118,6 @@
118
(apply string-append (youtube-client-upload-url client) 119
(map (lambda (p) (string-append "/" p)) parts))) 120
−122
;; No shared url-encode exists in sigil-http (known gap).−123
(define (url-encode-value s)−124
(let ((len (string-length s)))−125
(let loop ((i 0) (acc '()))−126
(if (>= i len)−127
(list->string (reverse acc))−128
(let ((c (string-ref s i)))−129
(cond−130
((or (char-alphabetic? c)−131
(char-numeric? c)−132
(char=? c #\-)−133
(char=? c #\_)−134
(char=? c #\.)−135
(char=? c #\~))−136
(loop (+ i 1) (cons c acc)))−137
((char=? c #\space)−138
(loop (+ i 1) (cons #\+ acc)))−139
(else−140
(let ((n (char->integer c)))−141
(loop (+ i 1)−142
(append (reverse (string->list−143
(string-append "%"−144
(if (< n 16) "0" "")−145
(number->string n 16))))−146
acc))))))))))−147
−148
;;; Pairs with #f values are omitted.−149
(define (build-query-string params)−150
(let ((parts (filter (lambda (p) (cdr p)) params)))−151
(if (null? parts)−152
""−153
(string-append "?"−154
(string-join−155
(map (lambda (p)−156
(string-append (car p) "=" (url-encode-value (cdr p))))−157
parts)−158
"&"))))) 121
122
;;; Append api-key to query params if client has one and no access-token. 123
(define (maybe-add-api-key client params)src/youtube/analytics.sglmodified
@@ -15,6 +15,7 @@
15
(sigil dict) 16
(sigil string) 17
(sigil json)+18
(only (sigil http) build-query-string) 19
(sigil http client) 20
(youtube)) 21
src/youtube/live.sglmodified
@@ -13,6 +13,7 @@
13
(sigil string) 14
(sigil struct) 15
(sigil json)+16
(only (sigil http) build-query-string) 17
(sigil http client) 18
(youtube)) 19
src/youtube/playlist.sglmodified
@@ -13,6 +13,7 @@
13
(sigil string) 14
(sigil struct) 15
(sigil json)+16
(only (sigil http) build-query-string) 17
(sigil http client) 18
(youtube)) 19
src/youtube/upload.sglmodified
@@ -13,6 +13,7 @@
13
(sigil string) 14
(sigil struct) 15
(sigil json)+16
(only (sigil http) build-query-string) 17
(sigil http client) 18
(youtube)) 19
test/youtube-test.sglmodified
@@ -9,6 +9,7 @@
9
(sigil struct) 10
(sigil json) 11
(sigil test)+12
(only (sigil http request) url-encode-value build-query-string) 13
(youtube)) 14
15
;; ---------------------------------------------------------------@@ -225,7 +226,7 @@
226
(assert-equal "foo%26bar" (url-encode-value "foo&bar"))) 227
228
(test "encode equals sign"−228
(assert-equal "key%3dvalue" (url-encode-value "key=value")))+229
(assert-equal "key%3Dvalue" (url-encode-value "key=value"))) 230
231
(test "preserve unreserved characters" 232
(assert-equal "a-b_c.d~e" (url-encode-value "a-b_c.d~e"))))