OCaml client for the LinkedIn Voyager API
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.

+42 -54
+17 -22
lib/post.ml
··· 30 30 { urn; text; author_name; created_time; num_likes; num_comments } 31 31 32 32 let json = 33 - Json.Codec.Object.map ~kind:"post" 33 + let open Json.Codec in 34 + Object.map ~kind:"post" 34 35 (fun urn text author_name created_time num_likes num_comments -> 35 36 { 36 37 urn = Option.value ~default:"" urn; ··· 40 41 num_likes = Option.value ~default:0 num_likes; 41 42 num_comments = Option.value ~default:0 num_comments; 42 43 }) 43 - |> Json.Codec.Object.opt_mem "urn" Json.Codec.string ~enc:(fun p -> 44 - Some p.urn) 45 - |> Json.Codec.Object.opt_mem "commentary" Json.Codec.string ~enc:(fun p -> 46 - Some p.text) 47 - |> Json.Codec.Object.opt_mem "authorName" Json.Codec.string ~enc:(fun p -> 48 - Some p.author_name) 49 - |> Json.Codec.Object.opt_mem "createdTime" Json.Codec.int ~enc:(fun p -> 50 - Some p.created_time) 51 - |> Json.Codec.Object.opt_mem "numLikes" Json.Codec.int ~enc:(fun p -> 52 - Some p.num_likes) 53 - |> Json.Codec.Object.opt_mem "numComments" Json.Codec.int ~enc:(fun p -> 54 - Some p.num_comments) 55 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 44 + |> Object.opt_mem "urn" string ~enc:(fun p -> Some p.urn) 45 + |> Object.opt_mem "commentary" string ~enc:(fun p -> Some p.text) 46 + |> Object.opt_mem "authorName" string ~enc:(fun p -> Some p.author_name) 47 + |> Object.opt_mem "createdTime" int ~enc:(fun p -> Some p.created_time) 48 + |> Object.opt_mem "numLikes" int ~enc:(fun p -> Some p.num_likes) 49 + |> Object.opt_mem "numComments" int ~enc:(fun p -> Some p.num_comments) 50 + |> Object.skip_unknown |> Object.finish 56 51 57 52 let feed_json = 58 - Json.Codec.Object.map ~kind:"feed_response" (fun elements -> 53 + let open Json.Codec in 54 + Object.map ~kind:"feed_response" (fun elements -> 59 55 Option.value ~default:[] elements) 60 - |> Json.Codec.Object.opt_mem "elements" (Json.Codec.list json) ~enc:(fun ps -> 61 - Some ps) 62 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 56 + |> Object.opt_mem "elements" (list json) ~enc:(fun ps -> Some ps) 57 + |> Object.skip_unknown |> Object.finish 63 58 64 59 (** Codec for a single post from a normalized Voyager API response. Extracts the 65 60 first update from the [included] array that has a [commentary] field. *) 66 61 let normalized_json = 67 - Json.Codec.Object.map ~kind:"normalized_post_response" (fun included -> 62 + let open Json.Codec in 63 + Object.map ~kind:"normalized_post_response" (fun included -> 68 64 match included with Some (p :: _) -> p | _ -> v ~urn:"" ()) 69 - |> Json.Codec.Object.opt_mem "included" (Json.Codec.list json) ~enc:(fun p -> 70 - Some [ p ]) 71 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 65 + |> Object.opt_mem "included" (list json) ~enc:(fun p -> Some [ p ]) 66 + |> Object.skip_unknown |> Object.finish
+25 -32
lib/profile.ml
··· 43 43 { public_id; entity_urn; first_name; last_name; headline; summary; location } 44 44 45 45 let json = 46 - Json.Codec.Object.map ~kind:"profile" 46 + let open Json.Codec in 47 + Object.map ~kind:"profile" 47 48 (fun public_id entity_urn first_name last_name headline summary location -> 48 49 { 49 50 public_id = Option.value ~default:"" public_id; ··· 54 55 summary = Option.value ~default:"" summary; 55 56 location = Option.value ~default:"" location; 56 57 }) 57 - |> Json.Codec.Object.opt_mem "miniProfile.publicIdentifier" Json.Codec.string 58 - ~enc:(fun p -> Some p.public_id) 59 - |> Json.Codec.Object.opt_mem "miniProfile.entityUrn" Json.Codec.string 60 - ~enc:(fun p -> Some p.entity_urn) 61 - |> Json.Codec.Object.opt_mem "firstName" Json.Codec.string ~enc:(fun p -> 62 - Some p.first_name) 63 - |> Json.Codec.Object.opt_mem "lastName" Json.Codec.string ~enc:(fun p -> 64 - Some p.last_name) 65 - |> Json.Codec.Object.opt_mem "headline" Json.Codec.string ~enc:(fun p -> 66 - Some p.headline) 67 - |> Json.Codec.Object.opt_mem "summary" Json.Codec.string ~enc:(fun p -> 68 - Some p.summary) 69 - |> Json.Codec.Object.opt_mem "locationName" Json.Codec.string ~enc:(fun p -> 70 - Some p.location) 71 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 58 + |> Object.opt_mem "miniProfile.publicIdentifier" string ~enc:(fun p -> 59 + Some p.public_id) 60 + |> Object.opt_mem "miniProfile.entityUrn" string ~enc:(fun p -> 61 + Some p.entity_urn) 62 + |> Object.opt_mem "firstName" string ~enc:(fun p -> Some p.first_name) 63 + |> Object.opt_mem "lastName" string ~enc:(fun p -> Some p.last_name) 64 + |> Object.opt_mem "headline" string ~enc:(fun p -> Some p.headline) 65 + |> Object.opt_mem "summary" string ~enc:(fun p -> Some p.summary) 66 + |> Object.opt_mem "locationName" string ~enc:(fun p -> Some p.location) 67 + |> Object.skip_unknown |> Object.finish 72 68 73 69 (** Codec for miniProfile objects found in the [included] array of normalized 74 70 LinkedIn Voyager API responses. Maps [occupation] to [headline]. *) 75 71 let mini_profile_json = 76 - Json.Codec.Object.map ~kind:"mini_profile" 72 + let open Json.Codec in 73 + Object.map ~kind:"mini_profile" 77 74 (fun public_id entity_urn first_name last_name occupation -> 78 75 { 79 76 public_id = Option.value ~default:"" public_id; ··· 84 81 summary = ""; 85 82 location = ""; 86 83 }) 87 - |> Json.Codec.Object.opt_mem "publicIdentifier" Json.Codec.string 88 - ~enc:(fun p -> Some p.public_id) 89 - |> Json.Codec.Object.opt_mem "entityUrn" Json.Codec.string ~enc:(fun p -> 90 - Some p.entity_urn) 91 - |> Json.Codec.Object.opt_mem "firstName" Json.Codec.string ~enc:(fun p -> 92 - Some p.first_name) 93 - |> Json.Codec.Object.opt_mem "lastName" Json.Codec.string ~enc:(fun p -> 94 - Some p.last_name) 95 - |> Json.Codec.Object.opt_mem "occupation" Json.Codec.string ~enc:(fun p -> 96 - Some p.headline) 97 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 84 + |> Object.opt_mem "publicIdentifier" string ~enc:(fun p -> Some p.public_id) 85 + |> Object.opt_mem "entityUrn" string ~enc:(fun p -> Some p.entity_urn) 86 + |> Object.opt_mem "firstName" string ~enc:(fun p -> Some p.first_name) 87 + |> Object.opt_mem "lastName" string ~enc:(fun p -> Some p.last_name) 88 + |> Object.opt_mem "occupation" string ~enc:(fun p -> Some p.headline) 89 + |> Object.skip_unknown |> Object.finish 98 90 99 91 let empty = 100 92 { ··· 110 102 (** Codec for the normalized [/voyager/api/me] response. Extracts the first 111 103 miniProfile from the [included] array. *) 112 104 let me_json = 113 - Json.Codec.Object.map ~kind:"me_response" (fun included -> 105 + let open Json.Codec in 106 + Object.map ~kind:"me_response" (fun included -> 114 107 match included with Some (p :: _) -> p | _ -> empty) 115 - |> Json.Codec.Object.opt_mem "included" (Json.Codec.list mini_profile_json) 116 - ~enc:(fun p -> Some [ p ]) 117 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 108 + |> Object.opt_mem "included" (list mini_profile_json) ~enc:(fun p -> 109 + Some [ p ]) 110 + |> Object.skip_unknown |> Object.finish