From be09c23d01b7718103fb457041febb22734b171a Mon Sep 17 00:00:00 2001 From: Tristan Goers Date: Fri, 22 Sep 2023 15:42:24 -0800 Subject: [PATCH] v0.1.0 Add Tasks --- .github/workflows/CHANGELOG.md | 0 .gitignore | 1 + api.go | 33 ++++++++-- function naming scheme.txt | 3 + go.mod | 4 +- go.sum | 4 ++ parameters/tasks.go | 115 +++++++++++++++++++++++++++++++++ tasks.go | 89 +++++++++++++++++++++++-- types/tasks.go | 2 +- 9 files changed, 239 insertions(+), 12 deletions(-) delete mode 100644 .github/workflows/CHANGELOG.md create mode 100644 function naming scheme.txt create mode 100644 go.sum create mode 100644 parameters/tasks.go diff --git a/.github/workflows/CHANGELOG.md b/.github/workflows/CHANGELOG.md deleted file mode 100644 index e69de29..0000000 diff --git a/.gitignore b/.gitignore index 3b735ec..4ee0c3b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ # Go workspace file go.work +test/main.go diff --git a/api.go b/api.go index db10312..f37a5c8 100644 --- a/api.go +++ b/api.go @@ -8,18 +8,39 @@ import ( ) func Get(config Config, path string, params url.Values) ([]byte, error) { + return api("GET", config, path, params) +} + +func Post(config Config, path string, params url.Values) ([]byte, error) { + return api("POST", config, path, params) +} + +func Put(config Config, path string, params url.Values) ([]byte, error) { + return api("PUT", config, path, params) +} + +func Delete(config Config, path string) ([]byte, error) { + return api("DELETE", config, path, nil) +} + +func api(method string, config Config, path string, params url.Values) ([]byte, error) { url := config.BaseUrl + path - if params != nil { url += fmt.Sprintf("?%s", params.Encode()) } + if params != nil { + url += fmt.Sprintf("?%s", params.Encode()) + } client := http.Client{} - req, err := http.NewRequest("GET", url, nil) - req.Header.Add("Authorization", "Bearer " + config.PermAccessToken) + req, err := http.NewRequest(method, url, nil) + req.Header.Add("Authorization", "Bearer "+config.PermAccessToken) res, err := client.Do(req) - if err != nil { fmt.Println("Request Error:", err) } + if err != nil { + fmt.Println("Request Error:", err) + } defer res.Body.Close() response, err := io.ReadAll(res.Body) - if err != nil { fmt.Println("io.ReadAll Error:", err) } - + if err != nil { + fmt.Println("io.ReadAll Error:", err) + } return response, err } diff --git a/function naming scheme.txt b/function naming scheme.txt new file mode 100644 index 0000000..dd00afe --- /dev/null +++ b/function naming scheme.txt @@ -0,0 +1,3 @@ +[Section][Wrike Method[s]][In[(folder / space)]][ById[s]] + +- Add trailing "s" if function will change multiple items at once. \ No newline at end of file diff --git a/go.mod b/go.mod index b43f1a5..d3fa98e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ -module "github.com/TGoers-FNSB/WrikeGo" +module github.com/TGoers-FNSB/WrikeGo go 1.21.1 + +require github.com/google/go-querystring v1.1.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4974eb1 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/parameters/tasks.go b/parameters/tasks.go new file mode 100644 index 0000000..0d491e9 --- /dev/null +++ b/parameters/tasks.go @@ -0,0 +1,115 @@ +package wrikeparams + +type DateOrRange struct { + Start string `url:"start,omitempty"` + End string `url:"end,omitempty"` + Equal string `url:"equal,omitempty"` +} +type TaskDates struct { + Type string `url:"type,omitempty"` + Duration int `url:"duration,omitempty"` + Start string `url:"start,omitempty"` + Due string `url:"due,omitempty"` + WorkOnWeekends bool `url:"workOnWeekends,omitempty"` +} + +type Metadata struct { + Key string `url:"key,omitempty"` + Value string `url:"value,omitempty"` +} + +type CustomField struct { + ID string `url:"id,omitempty"` + Comparator string `url:"comparator,omitempty"` + Value string `url:"value,omitempty"` + MinValue string `url:"minValue,omitempty"` + MaxValue string `url:"maxValue,omitempty"` + Values []string `url:"values,omitempty"` +} + +type EffortAllocation struct { + AllocatedEffort int `url:"allocatedEffort,omitempty"` + DailyAllocationPercentage int `url:"dailyAllocationPercentage,omitempty"` + Mode string `url:"mode,omitempty"` + TotalEffort int `url:"totalEffort,omitempty"` +} + +type QueryTasks struct { + Descendants bool `url:"descendants,omitempty"` + Title string `url:"title,omitempty"` + Status []string `url:"status,omitempty"` + Importance string `url:"importance,omitempty"` + StartDate DateOrRange `url:"startDate,omitempty"` + DueDate DateOrRange `url:"dueDate,omitempty"` + ScheduledDate DateOrRange `url:"scheduledDate,omitempty"` + CreatedDate DateOrRange `url:"createdDate,omitempty"` + UpdatedDate DateOrRange `url:"updatedDate,omitempty"` + CompletedDate DateOrRange `url:"completedDate,omitempty"` + Authors []string `url:"authors,omitempty"` + Responsibles []string `url:"responsibles,omitempty"` + Permalink string `url:"permalink,omitempty"` + Type string `url:"type,omitempty"` + Limit int `url:"limit,omitempty"` + SortField string `url:"sortField,omitempty"` + SortOrder string `url:"sortOrder,omitempty"` + SubTasks bool `url:"subTasks,omitempty"` + PageSize int `url:"pageSize,omitempty"` + NextPageToken string `url:"nextPageToken,omitempty"` + Metadata Metadata `url:"metadata,omitempty"` + CustomField CustomField `url:"customField,omitempty"` + CustomStatuses []string `url:"customStatuses,omitempty"` + BillingTypes []string `url:"billingTypes,omitempty"` + Fields []string `url:"fields,omitempty"` +} + +type CreateTasks struct { + Title string `url:"title,omitempty"` + Description string `url:"description,omitempty"` + Status string `url:"status,omitempty"` + Importance string `url:"importance,omitempty"` + Dates TaskDates `url:"dates,omitempty"` + Shareds []string `url:"shareds,omitempty"` + Parents []string `url:"parents,omitempty"` + Responsibles []string `url:"responsibles,omitempty"` + ResponsiblePlaceholders []string `url:"resopnsiblePlaceholders,omitempty"` + Followers []string `url:"followers,omitempty"` + Follow bool `url:"follow,omitempty"` + PriorityBefore string `url:"priorityBefore,omitempty"` + PriorityAfter string `url:"priorityAfter,omitempty"` + SuperTasks []string `url:"superTasks,omitempty"` + Metadata []Metadata `url:"metadata,omitempty"` + CustomFields []CustomField `url:"customFields,omitempty"` + CustomStatus string `url:"customStatus,omitempty"` + EffortAllocation EffortAllocation `url:"effortAllocation,omitempty"` + BillingType string `url:"billingType,omitempty"` + Fields []string `url:"fields,omitempty"` +} + +type ModifyTasks struct { + Title string `url:"title,omitempty"` + Description string `url:"description,omitempty"` + Status string `url:"status,omitempty"` + Importance string `url:"importance,omitempty"` + Dates TaskDates `url:"dates,omitempty"` + AddParents []string `url:"addParents,omitempty"` + RemoveParents []string `url:"removeParents,omitempty"` + AddShareds []string `url:"addShareds,omitempty"` + RemoveShareds []string `url:"removeShareds,omitempty"` + AddResponsibles []string `url:"addResponsibles,omitempty"` + RemoveResponsibles []string `url:"removeResponsibles,omitempty"` + AddResponsiblePlaceholders []string `url:"addResopnsiblePlaceholders,omitempty"` + RemoveResponsiblePlaceholders []string `url:"removeResopnsiblePlaceholders,omitempty"` + AddFollowers []string `url:"addFollowers,omitempty"` + Follow bool `url:"follow,omitempty"` + PriorityBefore string `url:"priorityBefore,omitempty"` + PriorityAfter string `url:"priorityAfter,omitempty"` + AddSuperTasks []string `url:"addSuperTasks,omitempty"` + RemoveSuperTasks []string `url:"removeSuperTasks,omitempty"` + Metadata []Metadata `url:"metadata,omitempty"` + CustomFields []CustomField `url:"customFields,omitempty"` + CustomStatus string `url:"customStatus,omitempty"` + Restore bool `url:"restore,omitempty"` + EffortAllocation EffortAllocation `url:"effortAllocation,omitempty"` + BillingType string `url:"billingType,omitempty"` + Fields []string `url:"fields,omitempty"` +} \ No newline at end of file diff --git a/tasks.go b/tasks.go index 6f08216..037060a 100644 --- a/tasks.go +++ b/tasks.go @@ -1,16 +1,97 @@ package wrikego import ( - "net/url" + "fmt" + "log" + "strings" + params "github.com/TGoers-FNSB/WrikeGo/parameters" types "github.com/TGoers-FNSB/WrikeGo/types" + query "github.com/google/go-querystring/query" ) -func QueryTasks_Get_Tasks(config Config, params url.Values) (types.Tasks, error) { +func QueryTasks(config Config, params params.QueryTasks) (types.Tasks, error) { path := "/tasks" + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Get(config, path, body) + return types.TasksFromJSON(response) +} - response, _ := Get(config, path, params) +func QueryTasksInFolder(config Config, params params.QueryTasks, pathId string) (types.Tasks, error) { + path := fmt.Sprintf("/folders/%s/tasks", pathId) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Get(config, path, body) + return types.TasksFromJSON(response) +} +func QueryTasksInSpace(config Config, params params.QueryTasks, pathId string) (types.Tasks, error) { + path := fmt.Sprintf("/spaces/%s/tasks", pathId) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Get(config, path, body) return types.TasksFromJSON(response) - // Comments9 } + +func QueryTasksByIDs(config Config, params params.QueryTasks, pathId []string) (types.Tasks, error) { + path := fmt.Sprintf("/tasks/%s", strings.Join(pathId, ",")) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Get(config, path, body) + return types.TasksFromJSON(response) +} + +func QueryTasksFieldsHistoryByIds(config Config, params params.QueryTasks, pathId []string) (types.Tasks, error) { + path := fmt.Sprintf("/tasks/%s/tasks_history", strings.Join(pathId, ",")) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Get(config, path, body) + return types.TasksFromJSON(response) +} + +func CreateTaskInFolder(config Config, params params.CreateTasks, pathId string) (types.Tasks, error) { + path := fmt.Sprintf("/folders/%s/tasks", pathId) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Post(config, path, body) + return types.TasksFromJSON(response) +} + +func ModifyTaskById(config Config, params params.ModifyTasks, pathId string) (types.Tasks, error) { + path := fmt.Sprintf("/tasks/%s", pathId) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Put(config, path, body) + return types.TasksFromJSON(response) +} + +func ModifyTasksByIds(config Config, params params.ModifyTasks, pathId []string) (types.Tasks, error) { + path := fmt.Sprintf("/tasks/%s", strings.Join(pathId, ",")) + body, err := query.Values(params) + if err != nil { + log.Println(err) + } + response, _ := Put(config, path, body) + return types.TasksFromJSON(response) +} + +func DeleteTaskById(config Config, pathId string) (types.Tasks, error) { + path := fmt.Sprintf("/tasks/%s", pathId) + response, _ := Delete(config, path) + return types.TasksFromJSON(response) +} \ No newline at end of file diff --git a/types/tasks.go b/types/tasks.go index 054e2c0..5c5f6d8 100644 --- a/types/tasks.go +++ b/types/tasks.go @@ -52,4 +52,4 @@ type Tasks struct { Value string `json:"value"` } `json:"customFields"` } `json:"data"` -} \ No newline at end of file +}