meeting vectors and special characters

 7th February 2024 at 2:08pm

I haven't worked much these last two days — I deserve a rest, every once in a while too! — but I left off at the JSON response.

; sends the request and gets the response
; -> intarweb#response
(define (get-snatched-response)
  (with-input-from-request (make-request-to-snatched API-KEY) #f read-json))

And the response comes in the form

((status . success) (response (snatched . #(((groupId . 36086) (name . Freedom of Choice) (torrentId . 478574) (torrentSize . 58286640) (artistName . Devo) (artistId . 13183)) [...]

I did not know what the # meant; now I know it is a vector construct. This is not part of the standard Scheme, but added on a later SRFI.

; sends the request and gets the response
; -> intarweb#response
(define (get-snatched-response)
  (with-input-from-request (make-request-to-snatched API-KEY) #f read-json))
(define snatched-response (get-snatched-response))
(test "response from API is a successful JSON" (cons 'status "success") (car snatched-response))

; retrieves a vector of records from the intarweb#response
; intarweb#response -> Vector
(define (get-records-from-snatched-response json-response)
	(cdr (car (cdr (car (cdr json-response))))))
(test "can obtain vector of records" #t (vector? (get-records-from-snatched-response snatched-response)))

And with a vector of records available, it can now be the subject of a mapping that creates record-info objects (a struct, probably).

Before advancing, I'd like to save a copy of an API response, just so I don't overload the API when testing. And then I came across this interesting situation: artistName . Conan Osíris).

This was troublesome because I tried writing the whole response as data in a file; However, the ; character starts a comment, and thus there's some necessary maneauvering here.