Source

ocaml-bitbucket / api.ml

Diff from to
 open Printf
 open Common
 
-open Tiny_json
 open Json_conv  (* for conv(json) *)
 open Ocaml_conv (* for conv(ocaml) *)
-open Meta_conv.Result.Open
 
 (* field of type Json.t mc_leftovers is automatically handled for Json, but not for ocaml *)
 type 'target mc_leftovers = (string * 'target) list with conv(ocaml)
 (* CR jfuruse: mc_fields should be supported in Ocaml_conv *)
 type 'target mc_fields = (string * 'target) list with conv(ocaml)
 
-(* CR jfuruse: can be shared with other json apps *)
-module Json = struct
-  include Json
-
-  let ocaml_of_t : Json.t Ocaml_conv.encoder = fun j -> Ocaml.String (Json.show j)
-  let t_of_ocaml : Json.t Ocaml_conv.decoder = fun o ->
-    try match o with
-    | Ocaml.String s -> `Ok (Json.parse s)
-    | _ -> failwith "Ocaml.String expected"
-    with e -> `Error (Meta_conv.Error.Deconstruction_error e, o)
-
-  let parse s = try `Ok (parse s) with e -> `Error (`Json_parse e)
-end
-
 (** { 6 Types } *)
 
 module Scheme = struct
           (Json.show v)
 end
 
-let curl_get_and_parse (convf : 'a Json_conv.decoder) curlf = 
-  Curl.get_string curlf >>= Json.parse >>= Error.wrap_json_conv convf
-
 module Data = struct
 
   (* CR jfuruse: It seems we should use classes since there are so many name overloads *)
 
     let get ~accountname ~repo_slug = 
       Format.eprintf "%s : %s...@." accountname repo_slug;
-      curl_get_and_parse 
+      Json.curl_get_and_parse 
         t_of_json
         (fun h ->
           (* ~user ~password  *)
 module User = struct
 
   let get ~user ~password = 
-    curl_get_and_parse
+    Json.curl_get_and_parse
       Data.User.t_of_json
       (fun h ->
         h#set_url "https://api.bitbucket.org/1.0/user";
   module Repositories = struct
 
     let get ~user ~password = 
-      curl_get_and_parse
+      Json.curl_get_and_parse
         Data.UserRepo.ts_of_json
         (fun h ->
           h#set_url "https://api.bitbucket.org/1.0/user/repositories/";