diff options
author | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 11:25:36 -0600 |
---|---|---|
committer | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 11:25:36 -0600 |
commit | 189179574d847e8e9662cf78804ce9371fac988d (patch) | |
tree | 0cc2b8c27fe8cf59d4724100d8b95085fab6432d /lib/user.ml | |
parent | 4fe8c79ce03e12be04b0d928b65b1a7d475f4458 (diff) | |
download | wormhole-189179574d847e8e9662cf78804ce9371fac988d.tar.gz wormhole-189179574d847e8e9662cf78804ce9371fac988d.tar.bz2 wormhole-189179574d847e8e9662cf78804ce9371fac988d.zip |
Add user
Diffstat (limited to 'lib/user.ml')
-rw-r--r-- | lib/user.ml | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/user.ml b/lib/user.ml new file mode 100644 index 0000000..00cd33f --- /dev/null +++ b/lib/user.ml @@ -0,0 +1,29 @@ +open Ppx_yojson_conv_lib.Yojson_conv.Primitives +open Cohttp +open Cohttp_lwt_unix +open Lwt + +type public_key = { + id : string; + owner : string; + public_key_prem : string; [@key "publicKeyPem"] +} +[@@deriving yojson] [@@yojson.allow_extra_fields] + +type t = { name : string; public_key : public_key [@key "publicKey"] } +[@@deriving yojson] [@@yojson.allow_extra_fields] + +let activity_header = + Some (Header.of_list [ ("Accept", "application/activity+json") ]) + +let get_user actor_url = + try%lwt + let%lwt _, body = + Client.get ?headers:activity_header (Uri.of_string actor_url) + in + body |> Cohttp_lwt.Body.to_string >|= fun body -> + let body = Yojson.Safe.from_string body |> t_of_yojson in + Ok body + with exn -> Lwt.return (Error exn) + +let name user = user.name |