RooTicket.vala
[gitlive] / RooTicket.vala
index d2e49c1..0f36f44 100644 (file)
@@ -16,10 +16,11 @@ class RooTicket : Object
     {
         if (_RooTicket == null) {
             _RooTicket = new RooTicket();
+            _RooTicket.tickets = new Gee.ArrayList<RooTicket>();
         }
         return _RooTicket;
     }
-       public Gee.ArrayList<RooTicket> tickets;
+       public Gee.ArrayList<RooTicket> tickets; // only available for singletonn.
 
        public int id;
        public string summary;
@@ -29,11 +30,75 @@ class RooTicket : Object
 
        static public void loadTickets()
        {
+               var url = "https://roojs.com/admin.php/Roo/mtrack_ticket");
+               
+               var table = new GLib.HashTable<string, string>(str_hash, str_equal);
+        
+               table.insert("query[viewtype]","active");
+               table.insert("developer_id","494");
+               table.insert("limit","999");
+               table.insert("sort","summary");
+               table.insert("dir","ASC");
+
+               
+               var params = Soup.Form.encode_hash(table);
+               
+               url = "%s?%s" . printf(url, params);
+               
+               GLib.debug("request %s", url);
+               
+               var session = new Soup.Session ();
+               session.timeout = 0;
+               var message = new Soup.Message ("GET", url);
+               
+               
+               this.setAuth(message);
+               
+               session.send_message (message);
+               
+               var data = (string) message.response_body.flatten().data;
+               GLib.debug("got %s", data);
+               try {
+                       parser = new Json.Parser ();
+                       parser.load_from_data (data, -1);
+
+                       response = parser.get_root().get_object();
+                       status = response.get_boolean_member("success");
+               
+                       if(!status){
+                               GLib.error(response.get_string_member("errorMsg"));
+                       }
+               
+               } catch (Error e) {
+                       GLib.error(e.message);
+               }
                
+       }
+       
+       static public void setAuth(message) {
+       
+               string str;
+               var username = "";
+               var password = "";
+               GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc"), out str);
+               var lines = str.split("\n");
+               for(var i=0; i< lines.length; i++) {
+               // assumes one line per entry.. if not we are buggered...
+                       var bits =  Regex.split_simple ("[ \t]+", line[i].strip());
+                       if (bits.length < 7 || bits[0] != "machine" || bits[1] != "git.roojs.com") {
+                               continue;
+                       }
+                       // we are gussing.... 
+                       username = bits[3];
+                       password = bits[5];
+                       
+               }
+               var authCode = Base64.encode ("%s:%s".printf(username), password)).data);
+               message.request_headers.append("Authorization", "Basic %s".printf(authCode));
+       
+       
+       }
+       
+       
        
-    "https://roojs.com/admin.php/Roo/mtrack_ticket.php"
-       //query[viewtype]=active
-       //developer_id=494
-       //limit=999
-       //&sort=summary
-       //dir=ASC
\ No newline at end of file
+  
\ No newline at end of file