Skip to content

Commit

Permalink
reorganized code
Browse files Browse the repository at this point in the history
  • Loading branch information
c-seeger committed Aug 16, 2021
1 parent 8f31d89 commit 71615fc
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 244 deletions.
13 changes: 13 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package goconfluence

import (
"net/http"
"net/url"
)

// API is the main api data structure
type API struct {
endPoint *url.URL
client *http.Client
username, token string
}
154 changes: 154 additions & 0 deletions content.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,78 @@ import (
"strings"
)

// Results array
type Results struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Status string `json:"status,omitempty"`
Content Content `json:"content"`
Excerpt string `json:"excerpt,omitempty"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
}

// Content specifies content properties
type Content struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Status string `json:"status,omitempty"`
Title string `json:"title"`
Ancestors []Ancestor `json:"ancestors,omitempty"`
Body Body `json:"body"`
Version *Version `json:"version,omitempty"`
Space Space `json:"space"`
History *History `json:"history,omitempty"`
Links *Links `json:"_links,omitempty"`
}

// Links contains link information
type Links struct {
Base string `json:"base"`
TinyUI string `json:"tinyui"`
}

// Ancestor defines ancestors to create sub pages
type Ancestor struct {
ID string `json:"id"`
}

// Body holds the storage information
type Body struct {
Storage Storage `json:"storage"`
View *Storage `json:"view,omitempty"`
}

// BodyExportView holds the export_view information
type BodyExportView struct {
ExportView *Storage `json:"export_view"`
View *Storage `json:"view,omitempty"`
}

// Storage defines the storage information
type Storage struct {
Value string `json:"value"`
Representation string `json:"representation"`
}

// Version defines the content version number
// the version number is used for updating content
type Version struct {
Number int `json:"number"`
MinorEdit bool `json:"minorEdit"`
Message string `json:"message,omitempty"`
By *User `json:"by,omitempty"`
}

// Space holds the Space information of a Content Page
type Space struct {
ID int `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Status string `json:"status,omitempty"`
}

// getContentIDEndpoint creates the correct api endpoint by given id
func (a *API) getContentIDEndpoint(id string) (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/content/" + id)
Expand All @@ -29,6 +101,24 @@ func (a *API) getContentGenericEndpoint(id string, t string) (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/content/" + id + "/" + t)
}

// ContentQuery defines the query parameters
// used for content related searching
// Query parameter values https://developer.atlassian.com/cloud/confluence/rest/#api-content-get
type ContentQuery struct {
Expand []string
Limit int // page limit
OrderBy string // fieldpath asc/desc e.g: "history.createdDate desc"
PostingDay string // required for blogpost type Format: yyyy-mm-dd
SpaceKey string
Start int // page start
Status string // current, trashed, draft, any
Title string // required for page
Trigger string // viewed
Type string // page, blogpost
Version int //version number when not lastest

}

// GetContentByID querys content by id
func (a *API) GetContentByID(id string, query ContentQuery) (*Content, error) {
ep, err := a.getContentIDEndpoint(id)
Expand All @@ -39,6 +129,14 @@ func (a *API) GetContentByID(id string, query ContentQuery) (*Content, error) {
return a.SendContentRequest(ep, "GET", nil)
}

// ContentSearch results
type ContentSearch struct {
Results []Content `json:"results"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
Size int `json:"size,omitempty"`
}

// GetContent querys content using a query parameters
func (a *API) GetContent(query ContentQuery) (*ContentSearch, error) {
ep, err := a.getContentEndpoint()
Expand Down Expand Up @@ -123,6 +221,26 @@ func (a *API) GetAttachments(id string) (*Search, error) {
return a.SendSearchRequest(ep, "GET")
}

// History contains object history information
type History struct {
LastUpdated LastUpdated `json:"lastUpdated"`
Latest bool `json:"latest"`
CreatedBy User `json:"createdBy"`
CreatedDate string `json:"createdDate"`
}

// LastUpdated contains information about the last update
type LastUpdated struct {
By User `json:"by"`
When string `json:"when"`
FriendlyWhen string `json:"friendlyWhen"`
Message string `json:"message"`
Number int `json:"number"`
MinorEdit bool `json:"minorEdit"`
SyncRev string `json:"syncRev"`
ConfRev string `json:"confRev"`
}

// GetHistory returns history information
func (a *API) GetHistory(id string) (*History, error) {
ep, err := a.getContentGenericEndpoint(id, "history")
Expand All @@ -132,6 +250,22 @@ func (a *API) GetHistory(id string) (*History, error) {
return a.SendHistoryRequest(ep, "GET")
}

// Labels is the label containter type
type Labels struct {
Labels []Label `json:"results"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
Size int `json:"size,omitempty"`
}

// Label contains label information
type Label struct {
Prefix string `json:"prefix"`
Name string `json:"name"`
ID string `json:"id,omitempty"`
Label string `json:"label,omitempty"`
}

// GetLabels returns a list of labels attachted to a content object
func (a *API) GetLabels(id string) (*Labels, error) {
ep, err := a.getContentGenericEndpoint(id, "label")
Expand Down Expand Up @@ -159,6 +293,21 @@ func (a *API) DeleteLabel(id string, name string) (*Labels, error) {
return a.SendLabelRequest(ep, "DELETE", nil)
}

// Watchers is a list of Watcher
type Watchers struct {
Watchers []Watcher `json:"results"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
Size int `json:"size,omitempty"`
}

// Watcher contains information about watching users of a page
type Watcher struct {
Type string `json:"type"`
Watcher User `json:"watcher"`
ContentID int `json:"contentId"`
}

// GetWatchers returns a list of watchers
func (a *API) GetWatchers(id string) (*Watchers, error) {
ep, err := a.getContentGenericEndpoint(id, "notification/child-created")
Expand Down Expand Up @@ -215,6 +364,11 @@ func (a *API) DelContent(id string) (*Content, error) {
return a.SendContentRequest(ep, "DELETE", nil)
}

// ContentVersionResult contains the version results
type ContentVersionResult struct {
Result []Version `json:"results"`
}

// GetContentVersion gets all versions of this content
func (a *API) GetContentVersion(id string) (*ContentVersionResult, error) {
ep, err := a.getContentGenericEndpoint(id, "version")
Expand Down
21 changes: 21 additions & 0 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ import (
"strings"
)

// Search results
type Search struct {
Results []Results `json:"results"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
Size int `json:"size,omitempty"`
ID string `json:"id,omitempty"`
TotalSize int `json:"totalSize, omitempty"`
}

// SearchQuery defines query parameters used for searchng
// Query parameter values https://developer.atlassian.com/cloud/confluence/rest/#api-search-get
type SearchQuery struct {
CQL string
CQLContext string
IncludeArchivedSpaces bool
Limit int
Start int
Expand []string
}

// getContentEndpoint creates the correct api endpoint by given id
func (a *API) getSearchEndpoint() (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/search")
Expand Down
21 changes: 21 additions & 0 deletions space.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ import (
"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")
Expand Down
Loading

0 comments on commit 71615fc

Please sign in to comment.