Google Docs API client for OCaml
0
fork

Configure Feed

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

codec: let open Json.Codec in cleanup across 16 medium files

10-19 usages each: linkedin/{profile,post}, space-dtn/daemon/config,
gdocs/comments, freebox/{switch,calls,firewall,parental,auth},
slack/team, requests/oauth, oci/spec/{manifest,intoto},
meross/timers, atp/atp/lex, gauth.

Same pattern: per-let `let open Json.Codec in` inside codec bodies,
`Json.Codec.list` qualified at the API call sites that wrap codecs
into HTTP requests. No record-field clashes worth annotating in this
batch.

+23 -25
+23 -25
lib/comments.ml
··· 40 40 type raw_author = { display_name : string } 41 41 42 42 let author_jsont = 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 43 + let open Json.Codec in 44 + Object.map ~kind:"author" (fun display_name -> { display_name }) 45 + |> Object.mem "displayName" string ~dec_absent:"" ~enc:(fun a -> 46 + a.display_name) 47 + |> Object.skip_unknown |> Object.finish 47 48 48 49 type raw_quoted = { value : string } 49 50 50 51 let quoted_jsont = 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 + let open Json.Codec in 53 + Object.map ~kind:"quotedFileContent" (fun value -> { value }) 54 + |> Object.mem "value" string ~dec_absent:"" ~enc:(fun q -> q.value) 55 + |> Object.skip_unknown |> Object.finish 55 56 56 57 let comment_jsont = 57 - Json.Codec.Object.map ~kind:"comment" 58 - (fun id author content quoted anchor resolved -> 58 + let open Json.Codec in 59 + Object.map ~kind:"comment" (fun id author content quoted anchor resolved -> 59 60 { 60 61 id; 61 62 author = (match author with Some a -> a.display_name | None -> ""); ··· 64 65 anchor; 65 66 resolved; 66 67 }) 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 68 + |> Object.mem "id" string ~enc:(fun c -> c.id) 69 + |> Object.opt_mem "author" author_jsont ~enc:(fun _ -> None) 70 + |> Object.mem "content" string ~dec_absent:"" ~enc:(fun c -> c.content) 71 + |> Object.opt_mem "quotedFileContent" quoted_jsont ~enc:(fun _ -> None) 72 + |> Object.opt_mem "anchor" string ~enc:(fun c -> c.anchor) 73 + |> Object.mem "resolved" bool ~dec_absent:false ~enc:(fun c -> c.resolved) 74 + |> Object.skip_unknown |> Object.finish 78 75 79 76 type raw_list = { comments : t list } 80 77 81 78 let list_jsont = 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 79 + let open Json.Codec in 80 + Object.map ~kind:"comment_list" (fun comments -> { comments }) 81 + |> Object.mem "comments" (list comment_jsont) ~dec_absent:[] ~enc:(fun r -> 82 + r.comments) 83 + |> Object.skip_unknown |> Object.finish 86 84 87 85 let of_json_string body = 88 86 match Json.of_string list_jsont body with