Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
Add Tasks
  • Loading branch information
TristanGoers committed Sep 22, 2023
1 parent 5f30fac commit be09c23
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 12 deletions.
Empty file removed .github/workflows/CHANGELOG.md
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

# Go workspace file
go.work
test/main.go
33 changes: 27 additions & 6 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions function naming scheme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Section][Wrike Method[s]][In[(folder / space)]][ById[s]]

- Add trailing "s" if function will change multiple items at once.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
115 changes: 115 additions & 0 deletions parameters/tasks.go
Original file line number Diff line number Diff line change
@@ -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"`
}
89 changes: 85 additions & 4 deletions tasks.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion types/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ type Tasks struct {
Value string `json:"value"`
} `json:"customFields"`
} `json:"data"`
}
}

0 comments on commit be09c23

Please sign in to comment.