diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2023-09-29 12:14:02 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2023-09-30 16:16:02 +0200 |
commit | ac1402819f222793d5148c4882fb4bfdab42d97f (patch) | |
tree | 608027ec092eae409746999f75045b7a96b129cc /neocities | |
parent | 20a6598147a3cba39edf3a5c63ba059814fa5aab (diff) |
requests: configurable port and http vs https
Diffstat (limited to 'neocities')
-rw-r--r-- | neocities/api.scm | 6 | ||||
-rw-r--r-- | neocities/requests.scm | 13 |
2 files changed, 10 insertions, 9 deletions
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 <neocities-api> - (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" |