-
Notifications
You must be signed in to change notification settings - Fork 11
/
task.go
46 lines (40 loc) · 1.11 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
package harvest
import (
"fmt"
"time"
)
type TasksResponse struct {
PagedResponse
Tasks []*Task `json:"tasks"`
}
type TaskStub struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
type Task struct {
ID int64 `json:"id"`
Name string `json:"name"`
BillableByDefault bool `json:"billable_by_default"`
Deactivated bool `json:"deactivated"`
DefaultHourlyRate float64 `json:"default_hourly_rate"`
IsDefault bool `json:"is_default"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (a *API) GetTask(taskID int64, args Arguments) (task *Task, err error) {
task = &Task{}
path := fmt.Sprintf("/tasks/%v", taskID)
err = a.Get(path, args, task)
return task, err
}
func (a *API) GetTasks(args Arguments) (tasks []*Task, err error) {
tasks = make([]*Task, 0)
tasksResponse := TasksResponse{}
err = a.GetPaginated("/tasks", args, &tasksResponse, func() {
for _, t := range tasksResponse.Tasks {
tasks = append(tasks, t)
}
tasksResponse.Tasks = make([]*Task, 0)
})
return tasks, err
}