aboutsummaryrefslogtreecommitdiff
path: root/lib/user.ml
blob: 00cd33f0c53f7e6a2f18216aa53ed962d97a38ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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