From ac1402819f222793d5148c4882fb4bfdab42d97f Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Fri, 29 Sep 2023 12:14:02 +0200 Subject: requests: configurable port and http vs https --- neocities/api.scm | 6 +++++- neocities/requests.scm | 13 +++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'neocities') diff --git a/neocities/api.scm b/neocities/api.scm index 5e3d2d0..a2017a7 100644 --- a/neocities/api.scm +++ b/neocities/api.scm @@ -61,11 +61,14 @@ (throw 'neocities "Authentication scheme not supported")))) (define-record-type - (make-neocities-api hostname auth) + (_make-neocities-api hostname port auth) neocities-api? (hostname neocities-api-hostname) + (port neocities-api-port) (auth neocities-api-auth neocities-api-auth-set!)) +(define* (make-neocities-api hostname auth #:optional port) + (_make-neocities-api hostname port auth)) (define* (neocities-delete api files) @@ -73,6 +76,7 @@ (throw 'neocities "files to delete must be a list")) (let ((url (neocities-url "delete" + #:port (neocities-api-port api) #:hostname (neocities-api-hostname api) #:querystring `(("files" . ,files))))) (neocities-request diff --git a/neocities/requests.scm b/neocities/requests.scm index 094b7bf..b6a74ff 100644 --- a/neocities/requests.scm +++ b/neocities/requests.scm @@ -43,7 +43,9 @@ encode-multipart-body)) (define* (neocities-url endpoint #:key (querystring '()) - (hostname #f)) + (hostname #f) + (insecure #f) + (port #f)) (define (encode-querystring querystring) (string-join (map (lambda (x) @@ -59,17 +61,12 @@ querystring) "&")) - ;; This is for testing locally :) - #;(build-uri 'http #:host "localhost" - #:port 1234 - #:path (string-append "/api/" endpoint) - #:query (encode-querystring querystring)) - (build-uri 'https + (build-uri (if insecure 'http 'https) #:host (or hostname "neocities.org") + #:port port #:path (string-append "/api/" endpoint) #:query (encode-querystring querystring))) - (define (encode-multipart-body files) "files is an alist with the filename and destination" -- cgit v1.2.3