aboutsummaryrefslogtreecommitdiffstats
path: root/timetask
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 23:08:08 +0200
committerTeddy Wing2017-06-03 23:08:08 +0200
commitd833ffe6cd5efd97b00f907ed426a88275a8c8db (patch)
treea3c902e1fdea20db4ff369459936bfba76f61176 /timetask
parent8b608aa4dfdff5e1e17664cff8f2f602d326844c (diff)
downloadtimetasker-d833ffe6cd5efd97b00f907ed426a88275a8c8db.tar.bz2
Add an option to list "Modules" (sprints & their IDs)
Sprints will change with time while the other IDs of a project will stay the same. Thus sprints, which live in the `Module` field, must be updated regularly. In order to facilitate that updating, instead of requiring users to get those IDs directly from the TimeTask website every time, have them use this command to get the names of sprints and their IDs. They can then update the ID manually in their config file. This code makes a request to the endpoint that returns module IDs for the site (the site queries this via AJAX to update its interface). The result of the request is some XML containing the modules and their IDs. For now I'm just printing this out. We'll want to parse the XML and display it in a nicer way.
Diffstat (limited to 'timetask')
-rw-r--r--timetask/http.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/timetask/http.go b/timetask/http.go
index 8c41b4f..3ff6f4f 100644
--- a/timetask/http.go
+++ b/timetask/http.go
@@ -1,6 +1,7 @@
package timetask
import (
+ "io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
@@ -126,3 +127,38 @@ func buildSubmissionParams(time_entry TimeEntry) url.Values {
return v
}
+
+func RequestModules(
+ client http.Client,
+ time_entry TimeEntry,
+) (string, error) {
+ params := url.Values{
+ "module": {"projects"},
+ "action": {"listmodulesxref"},
+ "f_ID": {strconv.Itoa(time_entry.Project)},
+ "f_active": {"t"},
+ "f_clientID": {strconv.Itoa(time_entry.Client)},
+ "f_personID": {strconv.Itoa(time_entry.PersonID)},
+ "f_milestoneID": {""},
+ }
+ modules_url, err := url.Parse(baseURL)
+ if err != nil {
+ return "", err
+ }
+
+ modules_url.RawQuery = params.Encode()
+
+ resp, err := client.Get(modules_url.String())
+ if err != nil {
+ return "", err
+ }
+
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return "", err
+ }
+ response_body := string(body)
+
+ return response_body, nil
+}