Commit5caa0d31Recorded29 Mar 2026Repositorysigil-youtube
Use shared API client helpers from (sigil http client)
Message
Replace local youtube-api-url, youtube-upload-api-url, and check-youtube-response with build-api-url and make-response-checker from the shared library.
Changed
src/youtube.sgl | 46 ++++++++++------------------------------------
1 file changed, 10 insertions(+), 36 deletions(-)Diff
src/youtube.sglmodified
@@ -111,12 +111,10 @@
111
#{}))) 112
113
(define (youtube-api-url client . parts)−114
(apply string-append (youtube-client-base-url client)−115
(map (lambda (p) (string-append "/" p)) parts)))+114
(apply build-api-url (youtube-client-base-url client) parts)) 115
116
(define (youtube-upload-api-url client . parts)−118
(apply string-append (youtube-client-upload-url client)−119
(map (lambda (p) (string-append "/" p)) parts)))+117
(apply build-api-url (youtube-client-upload-url client) parts)) 118
119
120
;;; Append api-key to query params if client has one and no access-token.@@ -127,38 +125,14 @@
125
(cons (cons "key" key) params) 126
params))) 127
−130
;;; Check an HTTP response and return parsed JSON, or raise a−131
;;; YouTube-specific error with quota/auth context.−132
(define (check-youtube-response response)−133
(if (not (http-response? response))−134
(error "YouTube API request failed: no response"))−135
(let ((status (http-response-status response))−136
(body (http-response-body response)))−137
(cond−138
((= status 401)−139
(error (string-append−140
"YouTube API 401 Unauthorized. "−141
"Access token may be expired — refresh and retry. "−142
"Response: " (or body ""))))−143
((= status 403)−144
(error (string-append−145
"YouTube API 403 Forbidden. "−146
"Possible quota exceeded or insufficient permissions. "−147
"Check quota at console.cloud.google.com. "−148
"Response: " (or body ""))))−149
((= status 429)−150
(error (string-append−151
"YouTube API 429 rate limited. "−152
"Respect Retry-After header and retry with backoff. "−153
"Response: " (or body ""))))−154
((>= status 400)−155
(error (string-append−156
"YouTube API error " (number->string status) ": "−157
(or body ""))))−158
(else−159
(if (and body (not (string=? body "")))−160
(json-decode body)−161
#t)))))+128
;;; Response checker with YouTube-specific quota/auth context.+129
(define check-youtube-response+130
(make-response-checker+131
name: "YouTube API"+132
handlers: (list+133
(cons 401 "Access token may be expired — refresh and retry.")+134
(cons 403 "Possible quota exceeded or insufficient permissions. Check quota at console.cloud.google.com.")+135
(cons 429 "Respect Retry-After header and retry with backoff.")))) 136
137
;;; Authenticated JSON GET request. 138
(define (youtube-get/json client url)