package polymarket
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
OCaml client library for the Polymarket prediction market API
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.2.0.tar.gz
md5=4eb4c5d2f63ff081c9713d90be5a51b2
sha512=0e3de0c9b40683e09ab8f9f966a44784ef1b9b482c3eefef84104a7e8042c92f1d79893ee9588b24fa3d0decaed7f365509f4d1c23c66ce8328efb64e721f276
doc/src/polymarket.http/json.ml.html
Source file json.ml
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80(** JSON parsing and body building utilities. *) let src = Logs.Src.create "polymarket.json" ~doc:"JSON parsing" module Log = (val Logs.src_log src : Logs.LOG) (** {1 JSON Parsing} *) let parse (parse_fn : Yojson.Safe.t -> 'a) (body : string) : ('a, string) result = try let json = Yojson.Safe.from_string body in Ok (parse_fn json) with | Ppx_yojson_conv_lib.Yojson_conv.Of_yojson_error (exn, json) -> let msg = Printf.sprintf "JSON parse error: %s\nProblematic value: %s\nFull response:\n%s" (Printexc.to_string exn) (Yojson.Safe.to_string json) body in Log.err (fun m -> m "Parse error: %s" (Printexc.to_string exn)); Error msg | Yojson.Json_error msg -> let err = "JSON error: " ^ msg ^ "\nBody:\n" ^ body in Log.err (fun m -> m "JSON error: %s" msg); Error err | exn -> let msg = Printf.sprintf "Parse error: %s\nFull response:\n%s" (Printexc.to_string exn) body in Log.err (fun m -> m "Error: %s" (Printexc.to_string exn)); Error msg let parse_list (parse_item_fn : Yojson.Safe.t -> 'a) (body : string) : ('a list, string) result = try let json = Yojson.Safe.from_string body in match json with | `List items -> Ok (List.map parse_item_fn items) | _ -> let err = "Expected JSON array\nBody:\n" ^ body in Log.err (fun m -> m "Expected JSON array"); Error err with | Ppx_yojson_conv_lib.Yojson_conv.Of_yojson_error (exn, json) -> let msg = Printf.sprintf "JSON parse error: %s\nProblematic value: %s\nFull response:\n%s" (Printexc.to_string exn) (Yojson.Safe.to_string json) body in Log.err (fun m -> m "Parse error: %s" (Printexc.to_string exn)); Error msg | Yojson.Json_error msg -> let err = "JSON error: " ^ msg ^ "\nBody:\n" ^ body in Log.err (fun m -> m "JSON error: %s" msg); Error err | exn -> let msg = Printf.sprintf "Parse error: %s\nFull response:\n%s" (Printexc.to_string exn) body in Log.err (fun m -> m "Error: %s" (Printexc.to_string exn)); Error msg (** {1 JSON Body Builders} *) let body (json : Yojson.Safe.t) : string = Yojson.Safe.to_string json let obj (fields : (string * Yojson.Safe.t) list) : Yojson.Safe.t = `Assoc fields let string (s : string) : Yojson.Safe.t = `String s let list (f : 'a -> Yojson.Safe.t) (items : 'a list) : string = `List (List.map f items) |> body let list_single_field (key : string) (items : string list) : string = list (fun v -> obj [ (key, string v) ]) items
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>