This repository has been archived by the owner on Apr 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcard.go
115 lines (101 loc) · 3.42 KB
/
card.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
/*
Copyright 2014 go-trello authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package trello
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Card struct {
client *Client
Id string `json:"id"`
CheckItemStates string `json:"checkItemStates"`
Closed bool `json:"closed"`
DateLastActivity string `json:"dateLastActivity"`
Desc string `json:"desc"`
DescData []string `json:"descData"`
Email string `json:"email"`
IdBoard string `json:"idBoard"`
IdList string `json:"idList"`
IdMembersVoted []string `json:"idMembersVoted"`
IdShort int `json:"idShort"`
IdAttachmentCover string `json:"idAttachmentCover"`
ManualCoverAttachment bool `json:"manualCoverAttachment"`
Name string `json:"name"`
Pos int `json:"pos"`
ShortLink string `json:"shortLink"`
Badges struct {
Votes int `json:"votes"`
ViewingMemberVoted bool `json:"viewingMemberVoted"`
Subscribed bool `json:"subscribed"`
Fogbugz string `json:"fogbugz"`
CheckItems int `json:"checkItems"`
CheckItemsChecked int `json:"checkItemsChecked"`
Comments int `json:"comments"`
Attachments int `json:"attachments"`
Description string `json:"description"`
Due string `json:"due"`
} `json:"badges"`
Due string `json:"due"`
IdCheckLists []string `json:"idCheckLists"`
IdMembers []string `json:"idMembers"`
Labels []string `json:"labels"`
ShortUrl string `json:"shortUrl"`
Subscribed bool `json:"subscribed"`
Url string `json:"url"`
}
func (c *Client) Card(CardId string) (card *Card, err error) {
req, err := http.NewRequest("GET", c.endpoint+"/card/"+CardId, nil)
if err != nil {
return
}
resp, err := c.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
} else if resp.StatusCode != 200 {
err = fmt.Errorf("Received unexpected status %d while trying to retrieve the server data", resp.StatusCode)
return
}
err = json.Unmarshal(body, &card)
card.client = c
return
}
func (c *Card) Checklists() (checklists []Checklist, err error) {
req, err := http.NewRequest("GET", c.client.endpoint+"/card/"+c.Id+"/checklists", nil)
if err != nil {
return
}
resp, err := c.client.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
} else if resp.StatusCode != 200 {
err = fmt.Errorf("Received unexpected status %d while trying to retrieve the server data", resp.StatusCode)
return
}
err = json.Unmarshal(body, &checklists)
for i, _ := range checklists {
checklists[i].client = c.client
}
return
}