diff options
author | Teddy Wing | 2017-06-03 23:08:08 +0200 |
---|---|---|
committer | Teddy Wing | 2017-06-03 23:08:08 +0200 |
commit | d833ffe6cd5efd97b00f907ed426a88275a8c8db (patch) | |
tree | a3c902e1fdea20db4ff369459936bfba76f61176 | |
parent | 8b608aa4dfdff5e1e17664cff8f2f602d326844c (diff) | |
download | timetasker-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.
-rw-r--r-- | main.go | 10 | ||||
-rw-r--r-- | timetask/http.go | 36 |
2 files changed, 46 insertions, 0 deletions
@@ -42,6 +42,7 @@ func main() { ) write_config := kingpin.Flag("write-config", write_config_description). Bool() + list_modules := kingpin.Flag("list-modules", "List sprints with IDs").Bool() kingpin.Version(VERSION) kingpin.Parse() @@ -108,6 +109,15 @@ func main() { os.Exit(1) } + // List modules + if *list_modules { + modules, err := timetask.RequestModules(*client, time_entry) + kingpin.FatalIfError(err, "could not retrieve sprints") + fmt.Println(modules) + + os.Exit(0) + } + resp, err = timetask.SubmitTimeEntry(*client, time_entry) kingpin.FatalIfError(err, "time entry submission request failed") 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 +} |