-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.go
91 lines (73 loc) · 1.95 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package freeagent
type TaskStatus string
const (
TaskStatusActive TaskStatus = "active"
TaskStatusCompleted TaskStatus = "completed"
TaskStatusHidden TaskStatus = "hidden"
)
type TaskBillingPeriod string
const (
TaskBillingPeriodDay TaskBillingPeriod = "day"
TaskBillingPeriodHour TaskBillingPeriod = "hour"
)
type Task struct {
URL string `json:"url,omitempty"`
Name string `json:"name"`
IsBillable bool `json:"is_billable"`
Status TaskStatus `json:"status"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
BillingRate string `json:"billing_rate"`
BillingPeriod TaskBillingPeriod `json:"billing_period"`
}
type taskDTO struct {
Task *Task `json:"task"`
}
func (c *Client) PostTask(task *Task) (*Task, error) {
request := &taskDTO{task}
response := &taskDTO{}
err := c.post("/tasks", request, response)
if err != nil {
return nil, err
}
return response.Task, nil
}
func (c *Client) GetTask(id string) (*Task, error) {
result := &taskDTO{}
err := c.get("/tasks/"+id, result)
if err != nil {
return nil, err
}
return result.Task, nil
}
type TaskView string
const (
TaskViewAll TaskView = "all"
TaskViewActive TaskView = "active"
TaskViewCompleted TaskView = "completed"
TaskViewHidden TaskView = "hidden"
)
type TaskSort string
const (
TaskSortName TaskSort = "name"
TaskSortProject TaskSort = "project"
TaskSortBillingRate TaskSort = "billing_rate"
TaskSortCreatedAt TaskSort = "created_at"
TaskSortUpdatedAt TaskSort = "updated_at"
)
type TaskQuery struct {
UpdatedSince string
View TaskView
Sort TaskSort
}
type tasksDTO struct {
Tasks []*Task `json:"tasks"`
}
func (c *Client) GetTasks(q *TaskQuery) ([]*Task, error) {
result := &tasksDTO{}
err := c.get("/tasks", result)
if err != nil {
return nil, err
}
return result.Tasks, nil
}