retrieve sessionId

This commit is contained in:
Mylloon 2023-05-13 13:33:46 +02:00
parent 1e80074dd6
commit 685412114c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 18 additions and 12 deletions

View file

@ -9,15 +9,14 @@ let start driver =
;;
let stop (driver_process, session_id) =
let data = close_session session_id in
print_endline data;
if not (close_session session_id) then print_endline "Can't close the session";
stop_process driver_process
;;
let main () = ()
let main session_id = print_endline session_id
let () =
let data = start (Gecko "0.33.0") in
main ();
main (snd data);
stop data
;;

View file

@ -1,4 +1,4 @@
(library
(name pusk)
(modules utils drivers net json)
(libraries cohttp-lwt-unix))
(libraries cohttp-lwt-unix yojson))

View file

@ -22,12 +22,19 @@ let execute_request url json =
;;
let get_session () =
let body = execute_request (fmt "%s/session" url) Json.connection_payload in
print_endline body;
body
let response = execute_request (fmt "%s/session" url) Json.connection_payload in
match Yojson.Safe.from_string response with
| `Assoc fields ->
let value = List.assoc "value" fields in
let rec find_session_id = function
| ("sessionId", `String session_id) :: _ -> session_id
| _ :: rest -> find_session_id rest
| [] -> failwith "Session ID not found"
in
find_session_id (Yojson.Safe.Util.to_assoc value)
| _ -> failwith "Invalid JSON"
;;
(* match Yojson.Safe.from_string body with
| _ as e -> print_endline e *)
let close_session id = Lwt_main.run (send_delete_request (fmt "%s/session/%s" url id))
let close_session id =
Lwt_main.run (send_delete_request (fmt "%s/session/%s" url id)) = "{\"value\":null}"
;;