RooTicket.vala
[gitlive] / RooTicket.vala
1 /**
2
3 code to fetch ticket info...
4
5
6 */
7 static RooTicket  _RooTicket;
8
9
10
11 class RooTicket : Object
12 {
13         
14         
15         public static RooTicket singleton()
16     {
17         if (_RooTicket == null) {
18             _RooTicket = new RooTicket();
19             _RooTicket.tickets = new Gee.ArrayList<RooTicket>();
20         }
21         return _RooTicket;
22     }
23         public Gee.ArrayList<RooTicket> tickets; // only available for singletonn.
24
25         public int id;
26         public string summary;
27         public string description;
28         public string project_id_name;
29
30
31         public void loadTickets()
32         {
33                 var url = "https://roojs.com/admin.php/Roo/mtrack_ticket");
34                 
35                 var table = new GLib.HashTable<string, string>(str_hash, str_equal);
36          
37                 table.insert("query[viewtype]","active");
38                 table.insert("developer_id","494");
39                 table.insert("limit","999");
40                 table.insert("sort","summary");
41                 table.insert("dir","ASC");
42
43                 
44                 var params = Soup.Form.encode_hash(table);
45                 
46                 url = "%s?%s" . printf(url, params);
47                 
48                 GLib.debug("request %s", url);
49                 
50                 var session = new Soup.Session ();
51                 session.timeout = 0;
52                 var message = new Soup.Message ("GET", url);
53                 
54                 
55                 this.setAuth(message);
56                 
57                 session.send_message (message);
58                 
59                 return (string) message.response_body.flatten().data;
60         }
61         
62         public void setAuth(message) {
63         
64                 string str;
65                 var username = "";
66                 var password = "";
67                 GLib.FileUtils.get_contents(GLib.Environment.get_home_dir() + "/.netrc"), out str);
68                 var lines = str.split("\n");
69                 for(var i=0; i< lines.length; i++) {
70                 // assumes one line per entry.. if not we are buggered...
71                         var bits =  Regex.split_simple ("[ \t]+", line[i].strip());
72                         if (bits.length < 7 || bits[0] != "machine" || bits[1] != "git.roojs.com") {
73                                 continue;
74                         }
75                         // we are gussing.... 
76                         username = bits[3];
77                         password = bits[5];
78                         
79                 }
80                 var authCode = Base64.encode ("%s:%s".printf(username), password)).data);
81                 message.request_headers.append("Authorization", "Basic %s".printf(authCode));
82         
83         
84         }
85         
86         
87         
88