diff --git a/bin/main.ml b/bin/main.ml index 4e7dd8f..a973412 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,17 +1,15 @@ -open Pusk.Utils -open Pusk open Pusk.Net open Pusk.Drivers -let main pid = - print_endline (fmt "Driver running as %d" pid); - let body = execute_request "http://localhost:4444/session" Json.connection_payload in +let main = + let session_id = get_session in + let body = close_session session_id in print_endline body ;; let () = let driver = prepare (Gecko "0.33.0") in let driver_process = run_process driver [] in - main (snd driver_process); + main; stop_process driver_process ;; diff --git a/lib/drivers.ml b/lib/drivers.ml index 0d1cdfd..9587f3e 100644 --- a/lib/drivers.ml +++ b/lib/drivers.ml @@ -50,10 +50,9 @@ let prepare = function let archive = fmt "./gecko-%s.tar.gz" version_driver in Lwt_main.run (download_gecko_driver version_driver archive); (* TODO: Use native version instead of relying on Unix tools *) - let _ = Sys.command (fmt "tar xvzf %s" archive) in - let _ = Sys.command (fmt "mv geckodriver %s" driver) in - let _ = Sys.command (fmt "rm %s" archive) in - ()); + ignore (Sys.command (fmt "tar xvzf %s" archive)); + ignore (Sys.command (fmt "mv geckodriver %s" driver)); + ignore (Sys.command (fmt "rm %s" archive))); driver ;; diff --git a/lib/net.ml b/lib/net.ml index 78cadae..c98050f 100644 --- a/lib/net.ml +++ b/lib/net.ml @@ -1,4 +1,7 @@ open Cohttp_lwt_unix +open Utils + +let url = "http://127.0.0.1:4444" let send_post_request url json = let uri = Uri.of_string url in @@ -8,7 +11,23 @@ let send_post_request url json = Cohttp_lwt.Body.to_string body) ;; +let send_delete_request url = + let uri = Uri.of_string url in + Lwt.bind (Client.delete uri) (fun (_response, body) -> Cohttp_lwt.Body.to_string body) +;; + let execute_request url json = let body = send_post_request url json in Lwt_main.run body ;; + +let get_session = + let body = execute_request (fmt "%s/session" url) Json.connection_payload in + print_endline body; + body +;; + +(* 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))