aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-02-11 17:23:59 +0000
committerAdelyn Breedlove <[email protected]>2019-02-11 17:23:59 +0000
commit7c9b809078b5cd53e3d54c0004c683da2ec679af (patch)
tree5a1b165b597fc1ad4167115d9a23b12852a4636b /lib/http
parentMerge branch 'sharder_fixes' into 'master' (diff)
downloaddisml-7c9b809078b5cd53e3d54c0004c683da2ec679af.tar.xz
disml-7c9b809078b5cd53e3d54c0004c683da2ec679af.zip
Add a cache
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/endpoints.ml63
-rw-r--r--lib/http/endpoints.mli63
-rw-r--r--lib/http/http.ml360
-rw-r--r--lib/http/http.mli185
4 files changed, 671 insertions, 0 deletions
diff --git a/lib/http/endpoints.ml b/lib/http/endpoints.ml
new file mode 100644
index 0000000..9263207
--- /dev/null
+++ b/lib/http/endpoints.ml
@@ -0,0 +1,63 @@
+open Printf
+
+let gateway = "/gateway"
+let gateway_bot = "/gateway/bot"
+let channel = sprintf "/channels/%d"
+let channel_messages = sprintf "/channels/%d/messages"
+let channel_message = sprintf "/channels/%d/messages/%d"
+let channel_reaction_me = sprintf "/channels/%d/messages/%d/reactions/%s/@me"
+let channel_reaction = sprintf "/channels/%d/messages/%d/reactions/%s/%d"
+let channel_reactions_get = sprintf "/channels/%d/messages/%d/reactions/%s"
+let channel_reactions_delete = sprintf "/channels/%d/messages/%d/reactions"
+let channel_bulk_delete = sprintf "/channels/%d"
+let channel_permission = sprintf "/channels/%d/permissions/%d"
+let channel_permissions = sprintf "/channels/%d/permissions"
+let channels = "/channels"
+let channel_call_ring = sprintf "/channels/%d/call/ring"
+let channel_invites = sprintf "/channels/%d/invites"
+let channel_typing = sprintf "/channels/%d/typing"
+let channel_pins = sprintf "/channels/%d/pins"
+let channel_pin = sprintf "/channels/%d/pins/%d"
+let guilds = "/guilds"
+let guild = sprintf "/guilds/%d"
+let guild_channels = sprintf "/guilds/%d/channels"
+let guild_members = sprintf "/guilds/%d/members"
+let guild_member = sprintf "/guilds/%d/members/%d"
+let guild_member_role = sprintf "/guilds/%d/members/%d/roles/%d"
+let guild_bans = sprintf "/guilds/%d/bans"
+let guild_ban = sprintf "/guilds/%d/bans/%d"
+let guild_roles = sprintf "/guilds/%d/roles"
+let guild_role = sprintf "/guilds/%d/roles/%d"
+let guild_prune = sprintf "/guilds/%d/prune"
+let guild_voice_regions = sprintf "/guilds/%d/regions"
+let guild_invites = sprintf "/guilds/%d/invites"
+let guild_integrations = sprintf "/guilds/%d/integrations"
+let guild_integration = sprintf "/guilds/%d/integrations/%d"
+let guild_integration_sync = sprintf "/guilds/%d/integrations/%d/sync"
+let guild_embed = sprintf "/guilds/%d/embed"
+let guild_emojis = sprintf "/guilds/%d/emojis"
+let guild_emoji = sprintf "/guilds/%d/emojis/%d"
+let webhooks_guild = sprintf "/guilds/%d/webhooks"
+let webhooks_channel = sprintf "/channels/%d/webhooks"
+let webhook = sprintf "/webhooks/%d"
+let webhook_token = sprintf "/webhooks/%d/%s"
+let webhook_git = sprintf "/webhooks/%d/%s/github"
+let webhook_slack = sprintf "/webhooks/%d/%s/slack"
+let user = sprintf "/users/%d"
+let me = "/users/@me"
+let me_guilds = "/users/@me/guilds"
+let me_guild = sprintf "/users/@me/guilds/%d"
+let me_channels = "/users/@me/channels"
+let me_connections = "/users/@me/connections"
+let invite = sprintf "/invites/%s"
+let regions = "/voice/regions"
+let application_information = "/oauth2/applications/@me"
+let group_recipient = sprintf "/channels/%d/recipients/%d"
+let guild_me_nick = sprintf "/guilds/%d/members/@me/nick"
+let guild_vanity_url = sprintf "/guilds/%d/vanity-url"
+let guild_audit_logs = sprintf "/guilds/%d/audit-logs"
+let cdn_embed_avatar = sprintf "/embed/avatars/%s.png"
+let cdn_emoji = sprintf "/emojis/%s.%s"
+let cdn_icon = sprintf "/icons/%d/%s.%s"
+let cdn_avatar = sprintf "/avatars/%d/%s.%s"
+let cdn_default_avatar = sprintf "/embed/avatars/%d" \ No newline at end of file
diff --git a/lib/http/endpoints.mli b/lib/http/endpoints.mli
new file mode 100644
index 0000000..33e2ea5
--- /dev/null
+++ b/lib/http/endpoints.mli
@@ -0,0 +1,63 @@
+(** Endpoint formatters used internally. *)
+
+val gateway : string
+val gateway_bot : string
+val channel : int -> string
+val channel_messages : int -> string
+val channel_message : int -> int -> string
+val channel_reaction_me : int -> int -> string -> string
+val channel_reaction : int -> int -> string -> int -> string
+val channel_reactions_get : int -> int -> string -> string
+val channel_reactions_delete : int -> int -> string
+val channel_bulk_delete : int -> string
+val channel_permission : int -> int -> string
+val channel_permissions : int -> string
+val channels : string
+val channel_call_ring : int -> string
+val channel_invites : int -> string
+val channel_typing : int -> string
+val channel_pins : int -> string
+val channel_pin : int -> int -> string
+val guilds : string
+val guild : int -> string
+val guild_channels : int -> string
+val guild_members : int -> string
+val guild_member : int -> int -> string
+val guild_member_role : int -> int -> int -> string
+val guild_bans : int -> string
+val guild_ban : int -> int -> string
+val guild_roles : int -> string
+val guild_role : int -> int -> string
+val guild_prune : int -> string
+val guild_voice_regions : int -> string
+val guild_invites : int -> string
+val guild_integrations : int -> string
+val guild_integration : int -> int -> string
+val guild_integration_sync : int -> int -> string
+val guild_embed : int -> string
+val guild_emojis : int -> string
+val guild_emoji : int -> int -> string
+val webhooks_guild : int -> string
+val webhooks_channel : int -> string
+val webhook : int -> string
+val webhook_token : int -> string -> string
+val webhook_git : int -> string -> string
+val webhook_slack : int -> string -> string
+val user : int -> string
+val me : string
+val me_guilds : string
+val me_guild : int -> string
+val me_channels : string
+val me_connections : string
+val invite : string -> string
+val regions : string
+val application_information : string
+val group_recipient : int -> int -> string
+val guild_me_nick : int -> string
+val guild_vanity_url : int -> string
+val guild_audit_logs : int -> string
+val cdn_embed_avatar : string -> string
+val cdn_emoji : string -> string -> string
+val cdn_icon : int -> string -> string -> string
+val cdn_avatar : int -> string -> string -> string
+val cdn_default_avatar : int -> string \ No newline at end of file
diff --git a/lib/http/http.ml b/lib/http/http.ml
new file mode 100644
index 0000000..e1b2998
--- /dev/null
+++ b/lib/http/http.ml
@@ -0,0 +1,360 @@
+open Core
+open Async
+open Cohttp
+
+module Base = struct
+ exception Invalid_Method
+
+ let rl = ref Rl.empty
+
+ let base_url = "https://discordapp.com/api/v7"
+
+ let process_url path =
+ Uri.of_string (base_url ^ path)
+
+ let process_request_body body =
+ body
+ |> Yojson.Safe.to_string
+ |> Cohttp_async.Body.of_string
+
+ let process_request_headers () =
+ let h = Header.init () in
+ Header.add_list h [
+ "User-Agent", "Dis.ml (https://gitlab.com/Mishio595/disml, v0.2.3)";
+ "Authorization", ("Bot " ^ !Client_options.token);
+ "Content-Type", "application/json";
+ "Connection", "keep-alive";
+ ]
+
+ let process_response path ((resp:Response.t), body) =
+ (match Response.headers resp
+ |> Rl.rl_of_header with
+ | Some r -> Mvar.put (Rl.find_exn !rl path) r
+ | None -> return ())
+ >>= fun () ->
+ match resp |> Response.status |> Code.code_of_status with
+ | 204 -> Deferred.Or_error.return `Null
+ | code when Code.is_success code -> body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string >>= Deferred.Or_error.return
+ | code ->
+ body |> Cohttp_async.Body.to_string >>= fun body ->
+ let headers = Response.sexp_of_t resp |> Sexp.to_string_hum in
+ Logs.warn (fun m -> m "[Unsuccessful Response] [Code: %d]\n%s\n%s" code body headers);
+ Deferred.Or_error.errorf "Unsuccessful response received: %d - %s" code body
+
+ let request ?(body=`Null) ?(query=[]) m path =
+ rl := Rl.update ~f:(function
+ | None ->
+ let r = Mvar.create () in
+ Mvar.set r Rl.default;
+ r
+ | Some r -> r
+ ) !rl path;
+ let limit = Rl.find_exn !rl path in
+ Mvar.take limit >>= fun limit ->
+ let process () =
+ let uri = Uri.add_query_params' (process_url path) query in
+ let headers = process_request_headers () in
+ let body = process_request_body body in
+ (match m with
+ | `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 path
+ in if limit.remaining > 0 then process ()
+ else Clock.at (Core.Time.(Span.of_int_sec limit.reset |> of_span_since_epoch)) >>= process
+end
+
+let get_gateway () =
+ Base.request `GET Endpoints.gateway
+
+let get_gateway_bot () =
+ Base.request `GET Endpoints.gateway_bot
+
+let get_channel channel_id =
+ Base.request `GET (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap))
+
+let modify_channel channel_id body =
+ Base.request ~body `PATCH (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap))
+
+let delete_channel channel_id =
+ Base.request `DELETE (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap))
+
+let get_messages channel_id limit (kind, id) =
+ Base.request ~query:[(kind, string_of_int id); ("limit", string_of_int limit)] `GET (Endpoints.channel_messages channel_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.of_yojson_exn)
+
+let get_message channel_id message_id =
+ Base.request `GET (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn
+
+let create_message channel_id body =
+ Base.request ~body:body `POST (Endpoints.channel_messages channel_id) >>| Result.map ~f:Message_t.of_yojson_exn
+
+let create_reaction channel_id message_id emoji =
+ Base.request `PUT (Endpoints.channel_reaction_me channel_id message_id emoji) >>| Result.map ~f:ignore
+
+let delete_own_reaction channel_id message_id emoji =
+ Base.request `DELETE (Endpoints.channel_reaction_me channel_id message_id emoji) >>| Result.map ~f:ignore
+
+let delete_reaction channel_id message_id emoji user_id =
+ Base.request `DELETE (Endpoints.channel_reaction channel_id message_id emoji user_id) >>| Result.map ~f:ignore
+
+let get_reactions channel_id message_id emoji =
+ Base.request `GET (Endpoints.channel_reactions_get channel_id message_id emoji)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:User_t.of_yojson_exn)
+
+let delete_reactions channel_id message_id =
+ Base.request `DELETE (Endpoints.channel_reactions_delete channel_id message_id) >>| Result.map ~f:ignore
+
+let edit_message channel_id message_id body =
+ Base.request ~body `PATCH (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn
+
+let delete_message channel_id message_id =
+ Base.request `DELETE (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:ignore
+
+let bulk_delete channel_id body =
+ Base.request ~body `POST (Endpoints.channel_bulk_delete channel_id) >>| Result.map ~f:ignore
+
+let edit_channel_permissions channel_id overwrite_id body =
+ Base.request ~body `PUT (Endpoints.channel_permission channel_id overwrite_id) >>| Result.map ~f:ignore
+
+let get_channel_invites channel_id =
+ Base.request `GET (Endpoints.channel_invites channel_id)
+
+let create_channel_invite channel_id body =
+ Base.request ~body `POST (Endpoints.channel_invites channel_id)
+
+let delete_channel_permission channel_id overwrite_id =
+ Base.request `DELETE (Endpoints.channel_permission channel_id overwrite_id) >>| Result.map ~f:ignore
+
+let broadcast_typing channel_id =
+ Base.request `POST (Endpoints.channel_typing channel_id) >>| Result.map ~f:ignore
+
+let get_pinned_messages channel_id =
+ Base.request `GET (Endpoints.channel_pins channel_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.of_yojson_exn)
+
+let pin_message channel_id message_id =
+ Base.request `PUT (Endpoints.channel_pin channel_id message_id) >>| Result.map ~f:ignore
+
+let unpin_message channel_id message_id =
+ Base.request `DELETE (Endpoints.channel_pin channel_id message_id) >>| Result.map ~f:ignore
+
+let group_recipient_add channel_id user_id =
+ Base.request `PUT (Endpoints.group_recipient channel_id user_id) >>| Result.map ~f:ignore
+
+let group_recipient_remove channel_id user_id =
+ Base.request `DELETE (Endpoints.group_recipient channel_id user_id) >>| Result.map ~f:ignore
+
+let get_emojis guild_id =
+ Base.request `GET (Endpoints.guild_emojis guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Emoji.of_yojson_exn)
+
+let get_emoji guild_id emoji_id =
+ Base.request `GET (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn
+
+let create_emoji guild_id body =
+ Base.request ~body `POST (Endpoints.guild_emojis guild_id) >>| Result.map ~f:Emoji.of_yojson_exn
+
+let edit_emoji guild_id emoji_id body =
+ Base.request ~body `PATCH (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn
+
+let delete_emoji guild_id emoji_id =
+ Base.request `DELETE (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:ignore
+
+let create_guild body =
+ Base.request ~body `POST Endpoints.guilds >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap))
+
+let get_guild guild_id =
+ Base.request `GET (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap))
+
+let edit_guild guild_id body =
+ Base.request ~body `PATCH (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap))
+
+let delete_guild guild_id =
+ Base.request `DELETE (Endpoints.guild guild_id) >>| Result.map ~f:ignore
+
+let get_guild_channels guild_id =
+ Base.request `GET (Endpoints.guild_channels guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Channel_t.(channel_wrapper_of_yojson_exn g |> wrap)))
+
+let create_guild_channel guild_id body =
+ Base.request ~body `POST (Endpoints.guild_channels guild_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap))
+
+let modify_guild_channel_positions guild_id body =
+ Base.request ~body `PATCH (Endpoints.guild_channels guild_id) >>| Result.map ~f:ignore
+
+let get_member guild_id user_id =
+ Base.request `GET (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id))
+
+let get_members guild_id =
+ Base.request `GET (Endpoints.guild_members guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id)))
+
+let add_member guild_id user_id body =
+ Base.request ~body `PUT (Endpoints.guild_member guild_id user_id)
+ >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id))
+
+let edit_member guild_id user_id body =
+ Base.request ~body `PATCH (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:ignore
+
+let remove_member guild_id user_id body =
+ Base.request ~body `DELETE (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:ignore
+
+let change_nickname guild_id body =
+ Base.request ~body `PATCH (Endpoints.guild_me_nick guild_id)
+
+let add_member_role guild_id user_id role_id =
+ Base.request `PUT (Endpoints.guild_member_role guild_id user_id role_id) >>| Result.map ~f:ignore
+
+let remove_member_role guild_id user_id role_id =
+ Base.request `DELETE (Endpoints.guild_member_role guild_id user_id role_id) >>| Result.map ~f:ignore
+
+let get_bans guild_id =
+ Base.request `GET (Endpoints.guild_bans guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Ban_t.of_yojson_exn)
+
+let get_ban guild_id user_id =
+ Base.request `GET (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:Ban_t.of_yojson_exn
+
+let guild_ban_add guild_id user_id body =
+ Base.request ~body `PUT (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:ignore
+
+let guild_ban_remove guild_id user_id body =
+ Base.request ~body `DELETE (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:ignore
+
+let get_roles guild_id =
+ Base.request `GET (Endpoints.guild_roles guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id)))
+
+let guild_role_add guild_id body =
+ Base.request ~body `POST (Endpoints.guild_roles guild_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id))
+
+let guild_roles_edit guild_id body =
+ Base.request ~body `PATCH (Endpoints.guild_roles guild_id)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id)))
+
+let guild_role_edit guild_id role_id body =
+ Base.request ~body `PATCH (Endpoints.guild_role guild_id role_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id))
+
+let guild_role_remove guild_id role_id =
+ Base.request `DELETE (Endpoints.guild_role guild_id role_id) >>| Result.map ~f:ignore
+
+let guild_prune_count guild_id days =
+ Base.request ~query:[("days", Int.to_string days)] `GET (Endpoints.guild_prune guild_id)
+ >>| Result.map ~f:(fun c -> Yojson.Safe.Util.(member "pruned" c |> to_int))
+
+let guild_prune_start guild_id days =
+ Base.request ~query:[("days", Int.to_string days)] `POST (Endpoints.guild_prune guild_id)
+ >>| Result.map ~f:(fun c -> Yojson.Safe.Util.(member "pruned" c |> to_int))
+
+let get_guild_voice_regions guild_id =
+ Base.request `GET (Endpoints.guild_voice_regions guild_id)
+
+let get_guild_invites guild_id =
+ Base.request `GET (Endpoints.guild_invites guild_id)
+
+let get_integrations guild_id =
+ Base.request `GET (Endpoints.guild_integrations guild_id)
+
+let add_integration guild_id body =
+ Base.request ~body `POST (Endpoints.guild_integrations guild_id) >>| Result.map ~f:ignore
+
+let edit_integration guild_id integration_id body =
+ Base.request ~body `POST (Endpoints.guild_integration guild_id integration_id) >>| Result.map ~f:ignore
+
+let delete_integration guild_id integration_id =
+ Base.request `DELETE (Endpoints.guild_integration guild_id integration_id) >>| Result.map ~f:ignore
+
+let sync_integration guild_id integration_id =
+ Base.request `POST (Endpoints.guild_integration_sync guild_id integration_id) >>| Result.map ~f:ignore
+
+let get_guild_embed guild_id =
+ Base.request `GET (Endpoints.guild_embed guild_id)
+
+let edit_guild_embed guild_id body =
+ Base.request ~body `PATCH (Endpoints.guild_embed guild_id)
+
+let get_vanity_url guild_id =
+ Base.request `GET (Endpoints.guild_vanity_url guild_id)
+
+let get_invite invite_code =
+ Base.request `GET (Endpoints.invite invite_code)
+
+let delete_invite invite_code =
+ Base.request `DELETE (Endpoints.invite invite_code)
+
+let get_current_user () =
+ Base.request `GET Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn
+
+let edit_current_user body =
+ Base.request ~body `PATCH Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn
+
+let get_guilds () =
+ Base.request `GET Endpoints.me_guilds
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap)))
+
+let leave_guild guild_id =
+ Base.request `DELETE (Endpoints.me_guild guild_id) >>| Result.map ~f:ignore
+
+let get_private_channels () =
+ Base.request `GET Endpoints.me_channels
+
+let create_dm body =
+ Base.request ~body `POST Endpoints.me_channels
+
+let create_group_dm body =
+ Base.request ~body `POST Endpoints.me_channels
+
+let get_connections () =
+ Base.request `GET Endpoints.me_connections
+
+let get_user user_id =
+ Base.request `GET (Endpoints.user user_id) >>| Result.map ~f:User_t.of_yojson_exn
+
+let get_voice_regions () =
+ Base.request `GET Endpoints.regions
+
+let create_webhook channel_id body =
+ Base.request ~body `POST (Endpoints.webhooks_channel channel_id)
+
+let get_channel_webhooks channel_id =
+ Base.request `GET (Endpoints.webhooks_channel channel_id)
+
+let get_guild_webhooks guild_id =
+ Base.request `GET (Endpoints.webhooks_guild guild_id)
+
+let get_webhook webhook_id =
+ Base.request `GET (Endpoints.webhook webhook_id)
+
+let get_webhook_with_token webhook_id token =
+ Base.request `GET (Endpoints.webhook_token webhook_id token)
+
+let edit_webhook webhook_id body =
+ Base.request ~body `PATCH (Endpoints.webhook webhook_id)
+
+let edit_webhook_with_token webhook_id token body =
+ Base.request ~body `PATCH (Endpoints.webhook_token webhook_id token)
+
+let delete_webhook webhook_id =
+ Base.request `DELETE (Endpoints.webhook webhook_id) >>| Result.map ~f:ignore
+
+let delete_webhook_with_token webhook_id token =
+ Base.request `DELETE (Endpoints.webhook_token webhook_id token) >>| Result.map ~f:ignore
+
+let execute_webhook webhook_id token body =
+ Base.request ~body `POST (Endpoints.webhook_token webhook_id token)
+
+let execute_slack_webhook webhook_id token body =
+ Base.request ~body `POST (Endpoints.webhook_slack webhook_id token)
+
+let execute_git_webhook webhook_id token body =
+ Base.request ~body `POST (Endpoints.webhook_git webhook_id token)
+
+let get_audit_logs guild_id body =
+ Base.request ~body `GET (Endpoints.guild_audit_logs guild_id)
+
+let get_application_info () =
+ Base.request `GET (Endpoints.application_information) \ No newline at end of file
diff --git a/lib/http/http.mli b/lib/http/http.mli
new file mode 100644
index 0000000..fe587c7
--- /dev/null
+++ b/lib/http/http.mli
@@ -0,0 +1,185 @@
+open Async
+
+module Base : sig
+ exception Invalid_Method
+
+ val base_url : string
+
+ val process_url : string -> Uri.t
+ val process_request_body : Yojson.Safe.t -> Cohttp_async.Body.t
+ val process_request_headers : unit -> Cohttp.Header.t
+
+ val process_response :
+ string ->
+ Cohttp_async.Response.t * Cohttp_async.Body.t ->
+ Yojson.Safe.t Deferred.Or_error.t
+
+ val request :
+ ?body:Yojson.Safe.t ->
+ ?query:(string * string) list ->
+ [> `DELETE | `GET | `PATCH | `POST | `PUT ] ->
+ string ->
+ Yojson.Safe.t Deferred.Or_error.t
+end
+
+val get_gateway : unit -> Yojson.Safe.t Deferred.Or_error.t
+val get_gateway_bot : unit -> Yojson.Safe.t Deferred.Or_error.t
+val get_channel : int -> Channel_t.t Deferred.Or_error.t
+val modify_channel :
+ int -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
+val delete_channel : int -> Channel_t.t Deferred.Or_error.t
+val get_messages : int -> int -> string * int -> Message_t.t list Deferred.Or_error.t
+val get_message : int -> int -> Message_t.t Deferred.Or_error.t
+val create_message :
+ int -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
+val create_reaction :
+ int -> int -> string -> unit Deferred.Or_error.t
+val delete_own_reaction :
+ int -> int -> string -> unit Deferred.Or_error.t
+val delete_reaction :
+ int -> int -> string -> int -> unit Deferred.Or_error.t
+val get_reactions :
+ int -> int -> string -> User_t.t list Deferred.Or_error.t
+val delete_reactions :
+ int -> int -> unit Deferred.Or_error.t
+val edit_message :
+ int ->
+ int -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
+val delete_message :
+ int -> int -> unit Deferred.Or_error.t
+val bulk_delete :
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val edit_channel_permissions :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_channel_invites : int -> Yojson.Safe.t Deferred.Or_error.t
+val create_channel_invite :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val delete_channel_permission :
+ int -> int -> unit Deferred.Or_error.t
+val broadcast_typing : int -> unit Deferred.Or_error.t
+val get_pinned_messages : int -> Message_t.t list Deferred.Or_error.t
+val pin_message : int -> int -> unit Deferred.Or_error.t
+val unpin_message : int -> int -> unit Deferred.Or_error.t
+val group_recipient_add :
+ int -> int -> unit Deferred.Or_error.t
+val group_recipient_remove :
+ int -> int -> unit Deferred.Or_error.t
+val get_emojis : int -> Emoji.t list Deferred.Or_error.t
+val get_emoji : int -> int -> Emoji.t Deferred.Or_error.t
+val create_emoji :
+ int -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
+val edit_emoji :
+ int ->
+ int -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
+val delete_emoji : int -> int -> unit Deferred.Or_error.t
+val create_guild :
+ Yojson.Safe.t -> Guild_t.t Deferred.Or_error.t
+val get_guild : int -> Guild_t.t Deferred.Or_error.t
+val edit_guild :
+ int -> Yojson.Safe.t -> Guild_t.t Deferred.Or_error.t
+val delete_guild : int -> unit Deferred.Or_error.t
+val get_guild_channels : int -> Channel_t.t list Deferred.Or_error.t
+val create_guild_channel :
+ int -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
+val modify_guild_channel_positions :
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_member : int -> int -> Member.t Deferred.Or_error.t
+val get_members : int -> Member.t list Deferred.Or_error.t
+val add_member :
+ int ->
+ int -> Yojson.Safe.t -> Member.t Deferred.Or_error.t
+val edit_member :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val remove_member :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val change_nickname :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val add_member_role :
+ int -> int -> int -> unit Deferred.Or_error.t
+val remove_member_role :
+ int -> int -> int -> unit Deferred.Or_error.t
+val get_bans : int -> Ban.t list Deferred.Or_error.t
+val get_ban : int -> int -> Ban.t Deferred.Or_error.t
+val guild_ban_add :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val guild_ban_remove :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_roles : int -> Role_t.t list Deferred.Or_error.t
+val guild_role_add :
+ int -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
+val guild_roles_edit :
+ int -> Yojson.Safe.t -> Role_t.t list Deferred.Or_error.t
+val guild_role_edit :
+ int ->
+ int -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
+val guild_role_remove :
+ int -> int -> unit Deferred.Or_error.t
+val guild_prune_count :
+ int -> int -> int Deferred.Or_error.t
+val guild_prune_start :
+ int -> int -> int Deferred.Or_error.t
+val get_guild_voice_regions :
+ int -> Yojson.Safe.t Deferred.Or_error.t
+val get_guild_invites : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_integrations : int -> Yojson.Safe.t Deferred.Or_error.t
+val add_integration :
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val edit_integration :
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val delete_integration :
+ int -> int -> unit Deferred.Or_error.t
+val sync_integration :
+ int -> int -> unit Deferred.Or_error.t
+val get_guild_embed : int -> Yojson.Safe.t Deferred.Or_error.t
+val edit_guild_embed :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_vanity_url : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_invite : string -> Yojson.Safe.t Deferred.Or_error.t
+val delete_invite : string -> Yojson.Safe.t Deferred.Or_error.t
+val get_current_user : unit -> User_t.t Deferred.Or_error.t
+val edit_current_user :
+ Yojson.Safe.t -> User_t.t Deferred.Or_error.t
+val get_guilds : unit -> Guild_t.t list Deferred.Or_error.t
+val leave_guild : int -> unit Deferred.Or_error.t
+val get_private_channels :
+ unit -> Yojson.Safe.t Deferred.Or_error.t
+val create_dm :
+ Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val create_group_dm :
+ Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_connections : unit -> Yojson.Safe.t Deferred.Or_error.t
+val get_user : int -> User_t.t Deferred.Or_error.t
+val get_voice_regions : unit -> Yojson.Safe.t Deferred.Or_error.t
+val create_webhook :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_channel_webhooks : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_guild_webhooks : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_webhook : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_webhook_with_token :
+ int -> string -> Yojson.Safe.t Deferred.Or_error.t
+val edit_webhook :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val edit_webhook_with_token :
+ int ->
+ string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val delete_webhook : int -> unit Deferred.Or_error.t
+val delete_webhook_with_token :
+ int -> string -> unit Deferred.Or_error.t
+val execute_webhook :
+ int ->
+ string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val execute_slack_webhook :
+ int ->
+ string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val execute_git_webhook :
+ int ->
+ string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_audit_logs :
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_application_info : unit -> Yojson.Safe.t Deferred.Or_error.t \ No newline at end of file