Source

ocaml-bitbucket / api.ml

Diff from to
+open Printf
 open Common
 open Tiny_json
 open Json_conv
 open Meta_conv.Open
 open Sexplib.Conv
 
+type 'target mc_fields = (string * 'target) list with sexp
+type 'target mc_leftovers = 'target mc_fields with sexp
+
 module Json = struct
   include Json
   let sexp_of_t j = Sexplib.Sexp.Atom (Json.show j)
     | _ -> assert false
 end
 
-module Address = struct
-  include Meta_conv.Types.Address
-  let sexp_of_t _ = Sexplib.Sexp.Atom ""
-  let t_of_sexp _ = top
-end
-
-type 'target fields = (string * ('target * Address.t)) list with sexp
-
 module Scheme = struct
   type t = Hg(:"hg":) | Git(:"git":) with conv(json), sexp
 end
 
   module Repository = struct
     type t = {
+      name              : string;
       scm               : Scheme.t;
       has_wiki          : bool;
       last_updated      : LocalTime.t;
       is_fork           : bool;
       slug              : string;
       is_private        : bool;
-      name              : string;
       language          : string;
       email_writers     : bool;
       no_public_forks   : bool;
   end
 
 
+  (* https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/branches *)
+  module Branches = struct
+
+    type branch = {
+      unknown : Json.t mc_leftovers;
+    } with conv(json), sexp
+
+    type t = branch mc_fields with conv(json), sexp
+
+    let get ~accountname ~repo_slug = 
+      let s = Curl.get_string (fun h ->
+        h#set_url (sprintf "https://api.bitbucket.org/1.0/repositories/%s/%s/branches" accountname repo_slug);
+        (* h#set_userpwd (Printf.sprintf "%s:%s" user password) *))
+      in
+      try t_of_json_exn (Json.parse s) with e -> 
+        prerr_endline (Printexc.to_string e);
+        prerr_endline s;
+        raise e
+      
+  end
 end
 
 (** user Endpoint *)
     resource_uri : string
   } with conv(json), sexp
 
-  type resp = {
+  type t = {
     user : user;
     repositories : Repositories.Repository.t list;
-    rest (: Leftovers :) : Json.t fields;
+    rest (: Leftovers :) : Json.t mc_fields;
   } with conv(json), sexp
 
   let get ~user ~password = 
       h#set_url "https://api.bitbucket.org/1.0/user";
       h#set_userpwd (Printf.sprintf "%s:%s" user password))
     in
-    try resp_of_json_exn (Json.parse s) with e -> 
+    try t_of_json_exn (Json.parse s) with e -> 
       prerr_endline (Printexc.to_string e);
       prerr_endline s;
       raise e