-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproject.go
161 lines (150 loc) · 5.13 KB
/
project.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package teamwork
import (
"encoding/json"
"fmt"
"time"
)
// Projects is a list of Project
type Projects []Project
// The Project structure.
type Project struct {
ActivePages struct {
Billing string `json:"billing"`
Files string `json:"files"`
Links string `json:"links"`
Messages string `json:"messages"`
Milestones string `json:"milestones"`
Notebooks string `json:"notebooks"`
RiskRegister string `json:"riskRegister"`
Tasks string `json:"tasks"`
Time string `json:"time"`
} `json:"active-pages"`
Announcement string `json:"announcement"`
AnnouncementHTML string `json:"announcementHTML"`
Category struct {
Color string `json:"color"`
ID string `json:"id"`
Name string `json:"name"`
} `json:"category"`
Company struct {
ID string `json:"id"`
IsOwner string `json:"is-owner"`
Name string `json:"name"`
} `json:"company"`
CreatedOn time.Time `json:"created-on"`
DefaultPrivacy string `json:"defaultPrivacy"`
Defaults struct {
Privacy string `json:"privacy"`
} `json:"defaults"`
Description string `json:"description"`
EndDate string `json:"endDate"`
FilesAutoNewVersion bool `json:"filesAutoNewVersion"`
HarvestTimersEnabled bool `json:"harvest-timers-enabled"`
ID string `json:"id"`
IsProjectAdmin bool `json:"isProjectAdmin"`
LastChangedOn time.Time `json:"last-changed-on"`
Logo string `json:"logo"`
LogoFromCompany bool `json:"logoFromCompany,omitempty"`
Name string `json:"name"`
NotifyEveryone bool `json:"notifyeveryone"`
People []string `json:"people"`
PrivacyEnabled bool `json:"privacyEnabled"`
ReplyByEmailEnabled bool `json:"replyByEmailEnabled"`
ShowAnnouncement bool `json:"show-announcement"`
Starred bool `json:"starred"`
StartDate string `json:"startDate"`
StartPage string `json:"start-page"`
Status string `json:"status"`
SubStatus string `json:"subStatus"`
Tags []struct {
Color string `json:"color"`
ID string `json:"id"`
Name string `json:"name"`
} `json:"tags"`
}
// GetProjectsOps is used to generate the query params for the
// GetProjects API call.
type GetProjectsOps struct {
// Query projects based on these values.
//
// The category id to filter by.
CategoryID string `param:"catId"`
// The project was created after this date.
// Format: "20100603"
CreatedAfterDate string `param:"createdAfterDate"`
// The project was created after this time.
// Format: "15:21"
CreatedAfterTime string `param:"createdAfterTime"`
// Output the people include in the project.
// Valid Input: true, false
IncludePeople *bool `param:"includePeople"`
// Order the results by this value. (eg: "name", "companyName", etc...)
OrderBy string `param:"orderby"`
// A page is 500 results. Access additional pages. (eg: 2, etc...)
Page *int `param:"page"`
// The status of the project.
// Valid Input: "ALL", "ACTIVE", "ARCHIVED", "CURRENT", "LATE", "COMPLETED"
Status string `param:"status"`
// The project was updated after this date.
// Format: "20100603"
UpdatedAfterDate string `param:"updatedAfterDate"`
// The project was updated after this time.
// Format: "15:21"
UpdatedAfterTime string `param:"updatedAfterTime"`
// Filter project by user
UserID string `param:"userId"`
}
// GetProjects gets all the projects available according to the specified
// GetProjectsOps which are passed in.
//
// ref: http://developer.teamwork.com/projectsapi#retrieve_all_proj
func (conn *Connection) GetProjects(ops *GetProjectsOps) (Projects, Pages, error) {
projects := make(Projects, 0)
pages := &Pages{}
params := buildParams(ops)
method := "GET"
url := fmt.Sprintf("%sprojects.json%s", conn.Account.Url, params)
reader, headers, err := request(conn.ApiToken, method, url, nil)
if err != nil {
return projects, *pages, err
}
getHeaders(headers, pages)
defer reader.Close()
err = json.NewDecoder(reader).Decode(&struct {
*Projects `json:"projects"`
}{&projects})
if err != nil {
return projects, *pages, err
}
return projects, *pages, nil
}
// GetProjectOps is used to generate the query params for the
// GetProject API call.
type GetProjectOps struct {
// Query a project based on these values.
//
// Output the people include in the project.
// Valid Input: true, false
IncludePeople *bool `param:"includePeople"`
}
// GetProject gets a single project based on a project ID.
//
// ref: http://developer.teamwork.com/projectsapi#retrieve_a_single
func (conn *Connection) GetProject(id string, ops *GetProjectOps) (Project, error) {
project := &Project{}
params := buildParams(ops)
method := "GET"
url := fmt.Sprintf("%sprojects/%s.json%s", conn.Account.Url, id, params)
reader, _, err := request(conn.ApiToken, method, url, nil)
if err != nil {
return *project, err
}
defer reader.Close()
err = json.NewDecoder(reader).Decode(&struct {
*Project `json:"project"`
}{project})
if err != nil {
return *project, err
}
return *project, nil
}