aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2020-09-12 15:09:44 +0200
committerAlban Gruin2020-09-12 15:10:02 +0200
commit6a0b1d0778aacd1e5baf57940f48f940abc80652 (patch)
tree8650e645d39e1b4e2ec714da81c24653d27ec53b
parent94428f9e3c69ebd23e843fa77259b0dd3dc53142 (diff)
ucs: fetch group based on URL
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
-rw-r--r--src/ucs.ml19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/ucs.ml b/src/ucs.ml
index 16fce75..92814f6 100644
--- a/src/ucs.ml
+++ b/src/ucs.ml
@@ -19,11 +19,11 @@ open Lwt
open Cohttp
open Cohttp_lwt_unix
-let body () =
+let fetch group =
let parameters = Uri.encoded_of_query
["start", ["2020-09-01"]; "end", ["2020-10-01"];
"resType", ["103"]; "calView", ["month"];
- "federationIds[]", ["IINS9CMA"]; "colourScheme", ["3"]] in
+ "federationIds[]", [group]; "colourScheme", ["3"]] in
let body = Cohttp_lwt.Body.of_string parameters and
headers = Header.init_with "Content-Type" "application/x-www-form-urlencoded" in
Client.post ~body ~headers (Uri.of_string "https://edt.univ-tlse3.fr/calendar2/Home/GetCalendarData")
@@ -32,13 +32,20 @@ let body () =
let server =
let callback _conn req _body =
- let meth = Request.meth req in
- match meth with
- | `GET ->
- body () >>= fun body ->
+ let meth = Request.meth req and
+ uri = Request.uri req
+ |> Uri.path
+ |> Astring.String.cuts ~empty:false ~sep:"/"
+ |> List.map Uri.pct_decode in
+ match meth, uri with
+ | `GET, ["ics"; file] when Astring.String.is_suffix ~affix:".ics" file ->
+ let group = String.(sub file 0 (length file - 4)) in
+ fetch group >>= fun body ->
let body = Ics.to_string @@ Course.decode body and
headers = Header.init_with "Content-Type" "text/calendar" in
Server.respond_string ~status:`OK ~body ~headers ()
+ | `GET, _ ->
+ Server.respond_string ~status:`Not_found ~body:"Not found\n" ()
| _ ->
Server.respond_string
~status:`Method_not_allowed ~body:"Method not allowed\n" () in