Commits

camlspotter committed d0b5325

meta_conv update

Comments (0)

Files changed (3)

 name="bitbucket"
 version="0.0.0"
 description="Bitbucket API for OCaml"
-requires="meta_conv,json-wheel,spotlib,curl,unix"
+requires="meta_conv,json-wheel,spotlib,curl,unix,sexplib"
 archive(byte)="bitbucket.cmo"
 archive(native)="bitbucket.cmx"
 linkopts = ""
 OCAMLPACKS[] =
     curl
     json-wheel
+    sexplib
     meta_conv
     spotlib
 
 OCAMLFLAGS = -annot -w A-4-9-39 
-OCAMLDEPFLAGS= -syntax camlp4o -package meta_conv.syntax
-OCAMLPPFLAGS= -syntax camlp4o -package meta_conv.syntax
+OCAMLDEPFLAGS= -syntax camlp4o -package meta_conv.syntax,sexplib.syntax
+OCAMLPPFLAGS=  -syntax camlp4o -package meta_conv.syntax,sexplib.syntax
 
 FILES[] =
     xcurl
 open Common
 open Json_wrap
 open Json_conv
+open Sexplib.Conv
+
+module Json = struct
+  include Json_wrap.Json
+  let sexp_of_t j = Sexplib.Sexp.Atom (Json_io.string_of_json j)
+  let t_of_sexp = function
+    | Sexplib.Sexp.Atom s -> Json_io.json_of_string s
+    | _ -> assert false
+end
 
 module Scheme = struct
-  type t = Hg(hg) | Git(git) with conv(json)
+  type t = Hg(:"hg":) | Git(:"git":) with conv(json)
 end
 
 module User = struct
 
-  module Repository = struct
-   
-    type t = { 
+  module Repositories = struct
+
+    type repo = { 
       owner      : string;
       scm        : Scheme.t;
       slug       : string;
       is_private : bool;
       name       : string
-    }
-  
-    and ts = t list
-  
-    with conv(json)
-  
-  end
+    } 
 
-  module Repositories = struct
-
-    type t = Repository.t list with conv(json)
+    and resp = repo list with conv(json)
 
     let get ~user ~password = 
-      t_of_json (Json_io.json_of_string (Curl.get_string (fun h ->
+      resp_of_json (Json_io.json_of_string (Curl.get_string (fun h ->
         h#set_url "https://api.bitbucket.org/1.0/user/repositories/";
         h#set_userpwd (Printf.sprintf "%s:%s" user password))))
   end
 
+  type user = {
+    username     : string;
+    first_name   : string;
+    last_name    : string;
+    is_team      : bool;
+    avatar       : string;
+    resource_uri : string
+  } with conv(json), sexp
+
+  type resp = {
+    user : user;
+    rest (: Rest_in_raw :) : (string * Json.t) list
+  } with conv(json), sexp
+
+  let get ~user ~password = 
+    let s = Curl.get_string (fun h ->
+      h#set_url "https://api.bitbucket.org/1.0/user";
+      h#set_userpwd (Printf.sprintf "%s:%s" user password))
+    in
+    try resp_of_json (Json_io.json_of_string s) with e -> 
+      prerr_endline (Printexc.to_string e);
+      prerr_endline s;
+      raise e
+
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.