aboutsummaryrefslogtreecommitdiff
path: root/lib/http.ml
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-11-17 19:49:45 -0700
committerMishio595 <[email protected]>2018-11-17 19:49:45 -0700
commitd92fe94da312c0a69dbe9bd7c2e525c594f20e40 (patch)
treeccd4a634996d97e4ba89f92cd904fbb0632f2fa4 /lib/http.ml
parentstupid dune-project file... (diff)
downloaddisml-d92fe94da312c0a69dbe9bd7c2e525c594f20e40.tar.xz
disml-d92fe94da312c0a69dbe9bd7c2e525c594f20e40.zip
Rewrite from Lwt to Async
Diffstat (limited to 'lib/http.ml')
-rw-r--r--lib/http.ml15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/http.ml b/lib/http.ml
index b6b0298..dbef903 100644
--- a/lib/http.ml
+++ b/lib/http.ml
@@ -1,6 +1,6 @@
-open Lwt.Infix
+open Async
open Cohttp
-open Cohttp_lwt_unix
+open Cohttp_async
module Base = struct
exception Invalid_Method
@@ -14,19 +14,20 @@ module Base = struct
let process_request_body body =
body
|> Yojson.Basic.to_string
- |> Cohttp_lwt.Body.of_string
+ |> Cohttp_async.Body.of_string
let process_request_headers () =
- let token = try
- Sys.getenv "DISCORD_TOKEN"
- with Not_found -> failwith "Please provide a token" in
+ let token = match Sys.getenv "DISCORD_TOKEN" with
+ | Some t -> t
+ | None -> failwith "Please provide a token"
+ in
let h = Header.init_with "User-Agent" "Dis.ml v0.1.0" in
let h = Header.add h "Authorization" ("Bot " ^ token) in
Header.add h "Content-Type" "application/json"
(* TODO Finish processor *)
let process_response (_resp, body) =
- body |> Cohttp_lwt.Body.to_string >|= Yojson.Basic.from_string
+ body |> Cohttp_async.Body.to_string >>| Yojson.Basic.from_string
let request ?(body=`Null) m path =
let uri = process_url path in