aboutsummaryrefslogtreecommitdiff
path: root/lib/http.ml
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2018-11-18 19:05:53 +0000
committerAdelyn Breedlove <[email protected]>2018-11-18 19:05:53 +0000
commit84d98bd3b227ac2bba5163d4e616d73e355494ee (patch)
tree7ec65e89673ad8d9e70b12482206e27e9fa77704 /lib/http.ml
parentMerge branch 'dev' into 'master' (diff)
parentEvent dispatch and client abstraction (diff)
downloaddisml-84d98bd3b227ac2bba5163d4e616d73e355494ee.tar.xz
disml-84d98bd3b227ac2bba5163d4e616d73e355494ee.zip
Merge branch 'dev' into 'master'
Add event dispatch and the Client module See merge request Mishio595/disml!4
Diffstat (limited to 'lib/http.ml')
-rw-r--r--lib/http.ml24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/http.ml b/lib/http.ml
index b6b0298..8d0b679 100644
--- a/lib/http.ml
+++ b/lib/http.ml
@@ -1,6 +1,5 @@
-open Lwt.Infix
+open Async
open Cohttp
-open Cohttp_lwt_unix
module Base = struct
exception Invalid_Method
@@ -14,30 +13,31 @@ 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
let headers = process_request_headers () in
let body = process_request_body body in
(match m with
- | `DELETE -> Client.delete ~headers ~body uri
- | `GET -> Client.get ~headers uri
- | `PATCH -> Client.patch ~headers ~body uri
- | `POST -> Client.post ~headers ~body uri
- | `PUT -> Client.put ~headers ~body uri
+ | `DELETE -> Cohttp_async.Client.delete ~headers ~body uri
+ | `GET -> Cohttp_async.Client.get ~headers uri
+ | `PATCH -> Cohttp_async.Client.patch ~headers ~body uri
+ | `POST -> Cohttp_async.Client.post ~headers ~body uri
+ | `PUT -> Cohttp_async.Client.put ~headers ~body uri
| _ -> raise Invalid_Method)
>>= process_response
end