diff options
| author | Alban Gruin | 2020-09-12 15:09:44 +0200 | 
|---|---|---|
| committer | Alban Gruin | 2020-09-12 15:10:02 +0200 | 
| commit | 6a0b1d0778aacd1e5baf57940f48f940abc80652 (patch) | |
| tree | 8650e645d39e1b4e2ec714da81c24653d27ec53b /src | |
| parent | 94428f9e3c69ebd23e843fa77259b0dd3dc53142 (diff) | |
ucs: fetch group based on URL
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'src')
| -rw-r--r-- | src/ucs.ml | 19 | 
1 files changed, 13 insertions, 6 deletions
| @@ -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 | 
