-
Notifications
You must be signed in to change notification settings - Fork 57
/
space.go
74 lines (67 loc) · 2.14 KB
/
space.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
package goconfluence
import (
"net/url"
"strconv"
"strings"
)
// AllSpaces results
type AllSpaces struct {
Results []Space `json:"results"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
Size int `json:"size,omitempty"`
}
// AllSpacesQuery defines the query parameters
// Query parameter values https://developer.atlassian.com/cloud/confluence/rest/#api-space-get
type AllSpacesQuery struct {
Expand []string
Favourite bool // Filter the results to the favourite spaces of the user specified by favouriteUserKey
FavouriteUserKey string // The userKey of the user, whose favourite spaces are used to filter the results when using the favourite parameter. Leave blank for the current user
Limit int // page limit
SpaceKey string
Start int // page start
Status string // current, archived
Type string // global, personal
}
// getSpaceEndpoint creates the correct api endpoint
func (a *API) getSpaceEndpoint() (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/space")
}
// GetAllSpaces queries content using a query parameters
func (a *API) GetAllSpaces(query AllSpacesQuery) (*AllSpaces, error) {
ep, err := a.getSpaceEndpoint()
if err != nil {
return nil, err
}
ep.RawQuery = addAllSpacesQueryParams(query).Encode()
return a.SendAllSpacesRequest(ep, "GET")
}
// addAllSpacesQueryParams adds the defined query parameters
func addAllSpacesQueryParams(query AllSpacesQuery) *url.Values {
data := url.Values{}
if len(query.Expand) != 0 {
data.Set("expand", strings.Join(query.Expand, ","))
}
if query.Favourite {
data.Set("favourite", strconv.FormatBool(query.Favourite))
}
if query.FavouriteUserKey != "" {
data.Set("favouriteUserKey", query.FavouriteUserKey)
}
if query.Limit != 0 {
data.Set("limit", strconv.Itoa(query.Limit))
}
if query.SpaceKey != "" {
data.Set("spaceKey", query.SpaceKey)
}
if query.Start != 0 {
data.Set("start", strconv.Itoa(query.Start))
}
if query.Status != "" {
data.Set("status", query.Status)
}
if query.Type != "" {
data.Set("type", query.Type)
}
return &data
}