From 288da883a3a4a91fec67029b7695ec03099cfc46 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 14:16:29 +0200 Subject: Initial stab at submitting time entries for real main.go: * Login as the configured user (haven't yet handled making `PasswordCmd` an actual shell command) * Create a test time entry * Submit that time entry using `SubmitTimeEntry()` http.go: * Create a `baseURL` global that stores the base TimeTask URL to make requests to * Return an `http.Client` from `Login()` that can then be passed to `SubmitTimeEntry()` to reuse the login session. Needed to return a pointer to allow us to return `nil` from the first error handler in the function. Don't like that at all, but we're just trying to get it to work at this point. * Actually make an HTTP POST request in `SubmitTimeEntry()` using the given HTTP Client and existing time entry submission params * Take an `http.Client` argument in `SubmitTimeEntry()` to allow us to use a logged-in session to POST. Otherwise we'd be locked out. * Change `v` variable to `values` in `SubmitTimeEntry()` for better readability --- main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index aea2112..1cc56c7 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( // "io/ioutil" "log" // "os" + "time" "github.com/teddywing/timetasker/timetask" @@ -25,6 +26,28 @@ var config Config func main() { loadConfig() + resp, client, err := timetask.Login( + config.Auth.Username, + config.Auth.PasswordCmd, + ) + if err != nil { + log.Fatalln(err) + } + log.Printf("%+v\n", resp) + + time_entry := timetask.NewTimeEntry( + config.Profile, + config.Projects["example"], + time.Now(), + 7, + "timetasker test", + ) + resp, err = timetask.SubmitTimeEntry(*client, time_entry) + if err != nil { + log.Fatalln(err) + } + log.Printf("%+v\n", resp) + // if len(os.Args) == 1 { // fmt.Println("Not enough arguments") // os.Exit(1) -- cgit v1.2.3