text stringlengths 0 601k |
|---|
type name_error = [ | ` Name_taken ] |
type kick_error = [ | ` Cant_kick_self ] |
type channel_kick_error = [ | kick_error | ` Cant_kick_from_general | ` Cant_kick_from_last_channel ] |
type restriction_error = [ | ` Restricted_action ] |
type leave_general_error = [ | ` Cant_leave_general ] |
type message_error = [ | ` Cant_delete_message | ` Message_not_found ] |
type message_length_error = [ | ` Msg_too_long ] |
type attachments_error = [ | ` Too_many_attachments ] |
type rate_error = [ | ` Rate_limited ] |
type message_update_error = [ | ` Message_not_found | ` Cant_update_message | ` Edit_window_closed ] |
type file_error = [ | ` File_not_found | ` File_deleted ] |
type unknown_type_error = [ | ` Unknown_type ] |
type already_archived_error = [ | ` Already_archived ] |
type not_in_group_error = [ | ` Not_in_group ] |
type leave_last_channel_error = [ | ` Cant_leave_last_channel ] |
type last_member_error = [ | ` Last_member ] |
type oauth_error = [ | ` Invalid_client_id | ` Bad_client_secret | ` Invalid_code | ` Bad_redirect_uri | ` Unknown_error ] |
type presence_error = [ | ` Invalid_presence ] |
type user_visibility_error = [ | ` User_not_visible ] |
type invalid_name_error = [ | ` Invalid_name ] |
type bot_error = [ | ` User_is_bot ] |
type parsed_auth_error = [ | parsed_api_error | auth_error ] |
type topic_result = [ | ` Success of string | parsed_auth_error | channel_error | archive_error | not_in_channel_error | ` User_is_restricted ] |
type session = { base_url : string ; token : string ; } |
type channel = ChannelId of string | ChannelName of string |
type user = UserId of string | UserName of string |
type bot = BotId of string |
type group = GroupId of string | GroupName of string |
type chat = Channel of channel | Im of conversation | User of user | Group of group |
type sort_criterion = Score | Timestamp |
type sort_direction = Ascending | Descending |
type presence = Auto | Away |
let user_of_yojson = function | ` String x -> Result . Ok ( UserId x ) | _ -> Result . Error " Couldn ' t parse user type " |
let bot_of_string s = if s . [ 0 ] = ' B ' then BotId s else invalid_arg ( " bot_of_string " ^ s ) |
let bot_of_yojson = function | ` String x -> Result . Ok ( bot_of_string x ) | _ -> Result . Error " Couldn ' t parse bot type " |
let channel_of_yojson = function | ` String x -> Result . Ok ( ChannelId x ) | _ -> Result . Error " Couldn ' t parse channel type " |
let group_of_yojson = function | ` String x -> Result . Ok ( GroupId x ) | _ -> Result . Error " Couldn ' t parse group type " |
let conversation_of_yojson = function | ` String x -> Result . Ok x | _ -> Result . Error " Couldn ' t parse conversation type " |
type topic_obj = { value : string ; creator : user ; last_set : Timestamp . t ; |
type channel_obj = { id : channel ; name : string ; is_channel : bool ; created : Timestamp . t ; creator : user ; is_archived : bool ; is_general : bool ; is_member : bool ; members : user list ; topic : topic_obj ; purpose : topic_obj ; last_read : Timestamp . t option [ @ default None ] ; latest : Yojson . Safe . t ... |
type user_obj = { id : user ; name : string ; deleted : bool ; color : string option [ @ default None ] ; real_name : string option [ @ default None ] ; tz : string option [ @ default None ] ; tz_label : string option [ @ default None ] ; tz_offset : int [ @ default 0 ] ; profile : Yojson . Safe . t ; is_admin : bool [... |
type group_obj = { id : group ; name : string ; is_group : bool ; created : Timestamp . t ; creator : user ; is_archived : bool ; members : user list ; topic : topic_obj ; purpose : topic_obj ; is_open : bool option [ @ default None ] ; last_read : Timestamp . t option [ @ default None ] ; unread_count : int option [ @... |
type file_obj = { id : string ; created : Timestamp . t ; timestamp : Timestamp . t ; name : string option [ @ default None ] ; title : string ; mimetype : string ; pretty_type : string ; user : user ; mode : string ; editable : bool ; is_external : bool ; external_type : string ; size : int ; url_private : string ; ur... |
type field_obj = { title : string option [ @ default None ] ; value : string [ @ default " " ] ; short : bool [ @ default false ] ; |
let field ? title ( ? short = false ) value = { title ; value ; short ; } |
type attachment_obj = { fallback : string option [ @ default None ] ; color : string option [ @ default None ] ; pretext : string option [ @ default None ] ; author_name : string option [ @ default None ] ; author_link : string option [ @ default None ] ; author_icon : string option [ @ default None ] ; title : string ... |
let if_none a b = match a with | Some v -> Some v | None -> b |
let attachment ? fallback ? color ? pretext ? author_name ? author_link ? author_icon ? title ? title_link ? text ? fields ? image_url ? thumb_url ? footer ? footer_icon ? ts ? mrkdwn_in ( ) = { fallback = if_none fallback text ; color ; pretext ; author_name ; author_link ; author_icon ; title ; title_link ; text ; fi... |
type message_obj = { type ' : string [ @ key " type " ] ; ts : Timestamp . t ; user : user option [ @ default None ] ; bot_id : bot option [ @ default None ] ; text : string option ; is_starred : bool option [ @ default None ] ; |
type history_obj = { latest : Timestamp . t option [ @ default None ] ; messages : message_obj list ; has_more : bool ; |
type authed_obj = { url : string ; team : string ; user : string ; team_id : string ; user_id : user ; |
type channel_leave_obj = { not_in_channel : bool option [ @ default None ] ; |
type channel_rename_obj = { id : channel ; is_channel : bool ; name : string ; created : Timestamp . t ; |
let chat_of_yojson = function | ` String c -> ( match c . [ 0 ] with | ' C ' -> Result . Ok ( Channel ( ChannelId c ) ) | ' D ' -> Result . Ok ( Im c ) | ' G ' -> Result . Ok ( Group ( GroupId c ) ) | _ -> Result . Error " Failed to parse chat " ) | _ -> Result . Error " Failed to parse chat " |
type chat_obj = { ts : Timestamp . t ; chat : chat [ @ key " channel " ] ; text : string option [ @ default None ] ; |
type emoji = ( string * string ) |
type emoji_list_obj = { emoji : ( string * string ) list ; |
type chat_close_obj = { no_op : bool option [ @ default None ] ; already_closed : bool option [ @ default None ] ; |
type groups_invite_obj = { already_in_group : bool option [ @ default None ] ; group : group_obj ; |
type groups_open_obj = { no_op : bool option [ @ default None ] ; already_open : bool option [ @ default None ] ; |
type groups_rename_obj = { id : channel ; is_group : bool ; name : string ; created : Timestamp . t |
type im_obj = { id : string ; is_im : bool ; user : user ; created : Timestamp . t ; is_user_deleted : bool ; unread_count : int option [ @ default None ] ; unread_count_display : int option [ @ default None ] ; |
type im_channel_obj = { id : string ; |
type im_open_obj = { no_op : bool option [ @ default None ] ; already_open : bool option [ @ default None ] ; channel : im_channel_obj ; |
type oauth_obj = { access_token : string ; scope : string ; |
type comment_obj = { id : string ; timestamp : Timestamp . t ; user : user ; comment : string ; |
type paging_obj = { count : int ; total : int ; page : int ; pages : int ; |
type files_info_obj = { file : file_obj ; comments : comment_obj list ; paging : paging_obj ; |
type files_list_obj = { files : file_obj list ; paging : paging_obj ; |
type stars_list_obj = { items : Yojson . Safe . t list ; paging : paging_obj ; |
type message_search_obj = { total : int ; paging : paging_obj ; matches : message_obj list ; |
type file_search_obj = { total : int ; paging : paging_obj ; matches : file_obj list ; |
type search_obj = { query : string ; messages : message_search_obj option [ @ default None ] ; files : file_search_obj option [ @ default None ] ; |
type team_obj = { id : string ; name : string ; domain : string ; email_domain : string ; icon : Yojson . Safe . t ; |
type login_obj = { user_id : user ; username : string ; date_first : Timestamp . t ; date_last : Timestamp . t ; count : int ; ip : string ; user_agent : string ; isp : string ; country : string ; region : string ; |
type team_access_log_obj = { logins : login_obj list ; paging : paging_obj ; |
type history_result = [ | ` Success of history_obj | parsed_auth_error | channel_error | timestamp_error ] |
let optionally_add key value uri = match value with | None -> uri | Some value -> Uri . add_query_param ' uri ( key , value ) |
let definitely_add key value = optionally_add key ( Some value ) |
let unauthed_endpoint ~ base_url method ' = let base_url = match base_url with | None -> default_base_url | Some base_url -> base_url in base_url ^ method ' |> Uri . of_string |
let endpoint method ' session = unauthed_endpoint ~ base_url ( : Some session . base_url ) method ' |> definitely_add " token " session . token |
type api_answer = { ok : bool ; error : string option [ @ default None ] |
let validate json = match api_answer_of_yojson json with | Result . Error str -> ` ParseFailure str | Result . Ok parsed -> match parsed . ok , parsed . error with | true , _ -> ` Json_response json | _ , Some " account_inactive " -> ` Account_inactive | _ , Some " already_archived " -> ` Already_archived | _ , Some " ... |
let filter_useless = function | ` Json_response ` Assoc items -> ` Json_response ( ` Assoc ( List . filter ( fun ( k , _ ) -> k <> " ok " && k <> " error " ) items ) ) | otherwise -> otherwise |
let process request = request >|= snd >>= Cohttp_body . to_string >|= Yojson . Safe . from_string >|= validate >|= filter_useless |
let ( ) << f g x = f @@ g x |
let query = process << Cohttp_unix . Client . get |
let query_post body = process << Cohttp_unix . Client . post ~ body |
let identity x = x |
let maybe fn = function | Some v -> Some ( fn v ) | None -> None |
type channels_list_obj = { channels : channel_obj list |
type users_list_obj = { members : user_obj list |
type groups_list_obj = { groups : group_obj list ; |
type im_list_obj = { ims : im_obj list ; |
let channels_list ? exclude_archived session = endpoint " channels . list " session |> optionally_add " exclude_archived " @@ maybe string_of_bool @@ exclude_archived |> query >|= function | ` Json_response d -> ( match d |> channels_list_obj_of_yojson with | Result . Ok x -> ` Success x . channels | Result . Error x -... |
let users_list session = endpoint " users . list " session |> query >|= function | ` Json_response d -> ( match d |> users_list_obj_of_yojson with | Result . Ok x -> ` Success x . members | Result . Error x -> ` ParseFailure x ) | # parsed_auth_error as res -> res | _ -> ` Unknown_error |
let groups_list ? exclude_archived session = endpoint " groups . list " session |> optionally_add " exclude_archived " @@ maybe string_of_bool exclude_archived |> query >|= function | ` Json_response d -> ( match d |> groups_list_obj_of_yojson with | Result . Ok x -> ` Success x . groups | Result . Error x -> ` ParseFa... |
type ' a listfn = session -> [ ` Success of ' a list | parsed_auth_error ] Lwt . t |
let lookupk session ( listfn : ' a listfn ) filterfn k = match % lwt listfn session with | # parsed_auth_error as e -> Lwt . return e | ` Success items -> Lwt . return @@ k @@ List . filter filterfn items |
let id_of_channel session = function | ChannelId id -> Lwt . return @@ ` Found id | ChannelName name -> let base = String . sub name 1 @@ String . length name - 1 in lookupk session channels_list ( fun ( x : channel_obj ) -> x . name = base ) @@ function | [ ] -> ` Channel_not_found | [ { id = ChannelId s ; _ } ] -> ` ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.