-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathattachment.go
64 lines (57 loc) · 1.65 KB
/
attachment.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
package goconfluence
import (
"encoding/json"
"net/http"
"net/url"
"time"
)
type Attachment struct {
MediaTypeDescription string `json:"mediaTypeDescription"`
WebuiLink string `json:"webuiLink"`
DownloadLink string `json:"downloadLink"`
CreatedAt interface{} `json:"createdAt"`
ID string `json:"id"`
Comment string `json:"comment"`
Version struct {
Number int `json:"number"`
Message string `json:"message"`
MinorEdit bool `json:"minorEdit"`
AuthorID string `json:"authorId"`
CreatedAt time.Time `json:"createdAt"`
} `json:"version"`
Title string `json:"title"`
FileSize int `json:"fileSize"`
Status string `json:"status"`
PageID string `json:"pageId"`
FileID string `json:"fileId"`
MediaType string `json:"mediaType"`
Links struct {
Download string `json:"download"`
Webui string `json:"webui"`
} `json:"_links"`
}
// getAttachmentEndpoint creates the correct api endpoint by given id
func (a *API) getAttachmentEndpoint(id string) (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/attachments/" + id)
}
// Get info on specific attachment by id
func (a *API) GetAttachmentById(id string) (*Attachment, error) {
ep, err := a.getAttachmentEndpoint(id)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", ep.String(), nil)
if err != nil {
return nil, err
}
res, err := a.Request(req)
if err != nil {
return nil, err
}
var attachment Attachment
err = json.Unmarshal(res, &attachment)
if err != nil {
return nil, err
}
return &attachment, nil
}