retrieve sessionId
This commit is contained in:
parent
1e80074dd6
commit
685412114c
3 changed files with 18 additions and 12 deletions
|
@ -9,15 +9,14 @@ let start driver =
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let stop (driver_process, session_id) =
|
let stop (driver_process, session_id) =
|
||||||
let data = close_session session_id in
|
if not (close_session session_id) then print_endline "Can't close the session";
|
||||||
print_endline data;
|
|
||||||
stop_process driver_process
|
stop_process driver_process
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let main () = ()
|
let main session_id = print_endline session_id
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let data = start (Gecko "0.33.0") in
|
let data = start (Gecko "0.33.0") in
|
||||||
main ();
|
main (snd data);
|
||||||
stop data
|
stop data
|
||||||
;;
|
;;
|
||||||
|
|
2
lib/dune
2
lib/dune
|
@ -1,4 +1,4 @@
|
||||||
(library
|
(library
|
||||||
(name pusk)
|
(name pusk)
|
||||||
(modules utils drivers net json)
|
(modules utils drivers net json)
|
||||||
(libraries cohttp-lwt-unix))
|
(libraries cohttp-lwt-unix yojson))
|
||||||
|
|
21
lib/net.ml
21
lib/net.ml
|
@ -22,12 +22,19 @@ let execute_request url json =
|
||||||
;;
|
;;
|
||||||
|
|
||||||
let get_session () =
|
let get_session () =
|
||||||
let body = execute_request (fmt "%s/session" url) Json.connection_payload in
|
let response = execute_request (fmt "%s/session" url) Json.connection_payload in
|
||||||
print_endline body;
|
match Yojson.Safe.from_string response with
|
||||||
body
|
| `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
|
let close_session id =
|
||||||
| _ as e -> print_endline e *)
|
Lwt_main.run (send_delete_request (fmt "%s/session/%s" url id)) = "{\"value\":null}"
|
||||||
|
;;
|
||||||
let close_session id = Lwt_main.run (send_delete_request (fmt "%s/session/%s" url id))
|
|
||||||
|
|
Loading…
Reference in a new issue