Google Docs API client for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

claude: complete Err -> Error module rename across call sites

Follow up to the module rename: update the remaining callers that
still referenced [Err] (library [claude.ml{,i}], [client.ml], the test
driver [test.ml]), and fix one stray [^ e] string concatenation in
hermest's CLI that needed [Json.Error.to_string e] now that
[Json.of_string] yields a structured error.

+41 -38
+29 -24
lib/comments.ml
··· 5 5 module Log = (val Logs.src_log src : Logs.LOG) 6 6 7 7 let err_msg fmt = Fmt.kstr (fun m -> Error (`Msg m)) fmt 8 - let err_json_decode e = err_msg "comments JSON decode: %s" e 8 + 9 + let err_json_decode e = 10 + err_msg "comments JSON decode: %s" (Json.Error.to_string e) 11 + 9 12 let err_http status body = err_msg "Drive comments HTTP %d: %s" status body 10 13 let scope = "https://www.googleapis.com/auth/drive.readonly" 11 14 ··· 37 40 type raw_author = { display_name : string } 38 41 39 42 let author_jsont = 40 - Json.Object.map ~kind:"author" (fun display_name -> { display_name }) 41 - |> Json.Object.mem "displayName" Json.string ~dec_absent:"" ~enc:(fun a -> 42 - a.display_name) 43 - |> Json.Object.skip_unknown |> Json.Object.finish 43 + Json.Codec.Object.map ~kind:"author" (fun display_name -> { display_name }) 44 + |> Json.Codec.Object.mem "displayName" Json.Codec.string ~dec_absent:"" 45 + ~enc:(fun a -> a.display_name) 46 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 44 47 45 48 type raw_quoted = { value : string } 46 49 47 50 let quoted_jsont = 48 - Json.Object.map ~kind:"quotedFileContent" (fun value -> { value }) 49 - |> Json.Object.mem "value" Json.string ~dec_absent:"" ~enc:(fun q -> 50 - q.value) 51 - |> Json.Object.skip_unknown |> Json.Object.finish 51 + Json.Codec.Object.map ~kind:"quotedFileContent" (fun value -> { value }) 52 + |> Json.Codec.Object.mem "value" Json.Codec.string ~dec_absent:"" 53 + ~enc:(fun q -> q.value) 54 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 52 55 53 56 let comment_jsont = 54 - Json.Object.map ~kind:"comment" 57 + Json.Codec.Object.map ~kind:"comment" 55 58 (fun id author content quoted anchor resolved -> 56 59 { 57 60 id; ··· 61 64 anchor; 62 65 resolved; 63 66 }) 64 - |> Json.Object.mem "id" Json.string ~enc:(fun c -> c.id) 65 - |> Json.Object.opt_mem "author" author_jsont ~enc:(fun _ -> None) 66 - |> Json.Object.mem "content" Json.string ~dec_absent:"" ~enc:(fun c -> 67 - c.content) 68 - |> Json.Object.opt_mem "quotedFileContent" quoted_jsont ~enc:(fun _ -> None) 69 - |> Json.Object.opt_mem "anchor" Json.string ~enc:(fun c -> c.anchor) 70 - |> Json.Object.mem "resolved" Json.bool ~dec_absent:false ~enc:(fun c -> 71 - c.resolved) 72 - |> Json.Object.skip_unknown |> Json.Object.finish 67 + |> Json.Codec.Object.mem "id" Json.Codec.string ~enc:(fun c -> c.id) 68 + |> Json.Codec.Object.opt_mem "author" author_jsont ~enc:(fun _ -> None) 69 + |> Json.Codec.Object.mem "content" Json.Codec.string ~dec_absent:"" 70 + ~enc:(fun c -> c.content) 71 + |> Json.Codec.Object.opt_mem "quotedFileContent" quoted_jsont ~enc:(fun _ -> 72 + None) 73 + |> Json.Codec.Object.opt_mem "anchor" Json.Codec.string ~enc:(fun c -> 74 + c.anchor) 75 + |> Json.Codec.Object.mem "resolved" Json.Codec.bool ~dec_absent:false 76 + ~enc:(fun c -> c.resolved) 77 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 73 78 74 79 type raw_list = { comments : t list } 75 80 76 81 let list_jsont = 77 - Json.Object.map ~kind:"comment_list" (fun comments -> { comments }) 78 - |> Json.Object.mem "comments" (Json.list comment_jsont) ~dec_absent:[] 79 - ~enc:(fun r -> r.comments) 80 - |> Json.Object.skip_unknown |> Json.Object.finish 82 + Json.Codec.Object.map ~kind:"comment_list" (fun comments -> { comments }) 83 + |> Json.Codec.Object.mem "comments" (Json.Codec.list comment_jsont) 84 + ~dec_absent:[] ~enc:(fun r -> r.comments) 85 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 81 86 82 87 let of_json_string body = 83 - match Json_bytesrw.decode_string list_jsont body with 88 + match Json.of_string list_jsont body with 84 89 | Error e -> err_json_decode e 85 90 | Ok r -> Ok r.comments 86 91
+4 -4
lib/document.ml
··· 1 1 (** A parsed Google Docs document. *) 2 2 3 3 let err_msg fmt = Fmt.kstr (fun m -> Error (`Msg m)) fmt 4 - let err_json_decode e = err_msg "JSON decode: %s" e 4 + let err_json_decode e = err_msg "JSON decode: %s" (Json.Error.to_string e) 5 5 6 6 type t = { document_id : string; title : string; raw : string } 7 7 ··· 27 27 so we just concatenate -- no manual newline insertion (which would 28 28 double-space the output). *) 29 29 let extract_text value = 30 - let open Jsont in 30 + let open Json in 31 31 let buf = Buffer.create 1024 in 32 32 let rec walk_root = function 33 33 | Object (members, _) -> ··· 108 108 | _ -> "" 109 109 110 110 let of_json_string body = 111 - match Json_bytesrw.decode_string Json.json body with 111 + match Json.Value.of_string body with 112 112 | Error e -> err_json_decode e 113 113 | Ok json -> 114 114 let document_id = top_string json "documentId" in ··· 116 116 Ok { document_id; title; raw = body } 117 117 118 118 let to_text d = 119 - match Json_bytesrw.decode_string Json.json d.raw with 119 + match Json.Value.of_string d.raw with 120 120 | Error _ -> "" 121 121 | Ok json -> extract_text json
-1
lib/dune
··· 8 8 gauth 9 9 http 10 10 json 11 - json.bytesrw 12 11 logs 13 12 oauth 14 13 requests
+1 -1
lib/markdown.ml
··· 413 413 | None -> () 414 414 415 415 let of_document doc = 416 - match Json_bytesrw.decode_string Json.json (Document.to_json doc) with 416 + match Json.Value.of_string (Document.to_json doc) with 417 417 | Error _ -> "" 418 418 | Ok json -> 419 419 let buf = Buffer.create 4096 in
+7 -8
lib/store.ml
··· 12 12 type client = { client_id : string; client_secret : string } 13 13 14 14 let client_jsont = 15 - Json.Object.map ~kind:"gdocs_client" (fun client_id client_secret -> 15 + Json.Codec.Object.map ~kind:"gdocs_client" (fun client_id client_secret -> 16 16 { client_id; client_secret }) 17 - |> Json.Object.mem "client_id" Json.string ~enc:(fun c -> c.client_id) 18 - |> Json.Object.mem "client_secret" Json.string ~enc:(fun c -> 17 + |> Json.Codec.Object.mem "client_id" Json.Codec.string ~enc:(fun c -> 18 + c.client_id) 19 + |> Json.Codec.Object.mem "client_secret" Json.Codec.string ~enc:(fun c -> 19 20 c.client_secret) 20 - |> Json.Object.skip_unknown |> Json.Object.finish 21 + |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 21 22 22 23 let save_file path data = 23 24 Eio.Path.save ~create:(`Or_truncate 0o600) path data; ··· 29 30 if Eio.Path.is_file path then Some (Eio.Path.load path) else None 30 31 31 32 let save_client fs c = 32 - match Json_bytesrw.encode_string client_jsont c with 33 - | Ok s -> save_file (client_path fs) s 34 - | Error e -> Fmt.failwith "encode client: %s" e 33 + save_file (client_path fs) (Json.to_string client_jsont c) 35 34 36 35 let load_client fs = 37 36 match load_file (client_path fs) with 38 37 | None -> None 39 38 | Some body -> ( 40 - match Json_bytesrw.decode_string client_jsont body with 39 + match Json.of_string client_jsont body with 41 40 | Ok c -> Some c 42 41 | Error _ -> None) 43 42