-
Notifications
You must be signed in to change notification settings - Fork 6
/
project.go
68 lines (55 loc) · 1.26 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
package client
import (
"fmt"
"net/url"
"time"
)
type Project struct {
Id int64 `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Description string `json:"description"`
Status int `json:"status"`
CreatedOn time.Time `json:"created_on"`
Parent *Entity `json:"parent"`
}
type Parent struct{}
type ProjectsResponse struct {
Projects []Project `json:"projects"`
}
type ProjectResponse struct {
Project Project `json:"project"`
}
func (c *Client) GetProject(id int64) (*Project, error) {
req, err := c.getRequest(fmt.Sprintf("/projects/%v.json", id), "")
if err != nil {
return nil, err
}
var response ProjectResponse
_, err = c.Do(req, &response)
if err != nil {
return nil, err
}
return &response.Project, nil
}
func (c *Client) GetProjects() ([]Project, error) {
req, err := c.getRequest("/projects.json", "limit=200")
if err != nil {
return nil, err
}
var response ProjectsResponse
_, err = c.Do(req, &response)
if err != nil {
return nil, err
}
return response.Projects, nil
}
func (p *Project) URL() string {
hostname, _ := getCredentials()
u := url.URL{
Scheme: "https",
Host: hostname,
Path: fmt.Sprintf("/projects/%v", p.Id),
}
return u.String()
}