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 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
|
||||
;;
|
||||
|
|
2
lib/dune
2
lib/dune
|
@ -1,4 +1,4 @@
|
|||
(library
|
||||
(name pusk)
|
||||
(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 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}"
|
||||
;;
|
||||
|
|
Loading…
Reference in a new issue