Improve parameter decoding
This commit is contained in:
parent
fb6cc611c7
commit
6dd42c3331
1 changed files with 7 additions and 9 deletions
16
server.ss
16
server.ss
|
@ -45,22 +45,20 @@
|
||||||
"Missing SNCF API authentication key\n")
|
"Missing SNCF API authentication key\n")
|
||||||
(return))
|
(return))
|
||||||
(def headers (http-request-headers req))
|
(def headers (http-request-headers req))
|
||||||
(def accept-header (assoc "Accept" headers))
|
(def accept-header (assget "Accept" headers))
|
||||||
(when accept-header (set! accept-header (cdr accept-header)))
|
|
||||||
(def params (parse-request-params (http-request-params req)))
|
(def params (parse-request-params (http-request-params req)))
|
||||||
(def datetime-str (assoc "datetime" params))
|
(def datetime-str (assget "datetime" params))
|
||||||
(def datetime (if datetime-str
|
(def datetime (if datetime-str
|
||||||
(try
|
(try
|
||||||
(string->date (cdr datetime-str) "~Y~m~dT~H~M~S")
|
(string->date datetime-str "~Y~m~dT~H~M~S")
|
||||||
(catch _
|
(catch _
|
||||||
(warnf "Badly formatted date string: ~a" (cdr datetime-str))
|
(warnf "Badly formatted date string: ~a" datetime-str)
|
||||||
(http-response-write res 400 '(("Content-Type" . "text/plain; charset=utf-8"))
|
(http-response-write res 400 '(("Content-Type" . "text/plain; charset=utf-8"))
|
||||||
(format "Badly formatted date string, expected %Y%m%dT%H%M%S: ~a\n"
|
(format "Badly formatted date string, expected %Y%m%dT%H%M%S: ~a\n"
|
||||||
(cdr datetime-str)))
|
datetime-str))
|
||||||
(return)))
|
(return)))
|
||||||
#f))
|
#f))
|
||||||
(def station (assoc "station" params))
|
(def station (assget "station" params))
|
||||||
(when station (set! station (cdr station)))
|
|
||||||
(define-values (station-name station-id)
|
(define-values (station-name station-id)
|
||||||
(if (string? station)
|
(if (string? station)
|
||||||
(get-station-id sncf-key station)
|
(get-station-id sncf-key station)
|
||||||
|
@ -75,7 +73,7 @@
|
||||||
(http-request-path req)
|
(http-request-path req)
|
||||||
station-name
|
station-name
|
||||||
station
|
station
|
||||||
(if datetime (string-append " at " (cdr datetime-str)) ""))
|
(if datetime (string-append " at " datetime-str) ""))
|
||||||
(define-values (departures disruptions) (get-departures sncf-key station-id datetime))
|
(define-values (departures disruptions) (get-departures sncf-key station-id datetime))
|
||||||
(def content
|
(def content
|
||||||
(cond
|
(cond
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue