confluence

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 20 Imported by: 3

README

go-confluence

A Go client library for accessing Confluence Cloud REST API

Documentation

Index

Constants

View Source
const (
	AttachmentNotFoundError = "attachment not found"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	StatusCode int `json:"statusCode,omitempty"`
	Data       struct {
		Authorized bool `json:"authorized,omitempty"`
		Valid      bool `json:"valid,omitempty"`
		Errors     []struct {
			Message struct {
				Key  string        `json:"key,omitempty"`
				Args []interface{} `json:"args,omitempty"`
			} `json:"message,omitempty"`
		} `json:"errors,omitempty"`
		Successful bool `json:"successful,omitempty"`
	} `json:"data,omitempty"`
	Message string `json:"message,omitempty"`
}

APIResponse provides default response from API

type Attachment

type Attachment struct {
	ID       string `json:"id"`
	Type     string `json:"type"`
	Status   string `json:"status"`
	Title    string `json:"title"`
	Metadata struct {
		Comment   string `json:"comment"`
		MediaType string `json:"mediaType"`
	} `json:"metadata"`
	Version struct {
		Number int `json:"number"`
	} `json:"version"`
}

Attachment ...

type AttachmentExpandable

type AttachmentExpandable struct {
	Container    string `json:"container"`
	Operations   string `json:"operations"`
	Children     string `json:"children"`
	Restrictions string `json:"restrictions"`
	History      string `json:"history"`
	// Ancestors string `json:"ancestors"`
	// Body string `json:"body"`
	// Version string `json:"version"`
	Descendants string `json:"descendants"`
	Space       string `json:"space"`
}

AttachmentExpandable expandable

type AttachmentExtensions

type AttachmentExtensions struct {
	MediaType string  `json:"mediaType"`
	FileSize  float64 `json:"fileSize"`
	Comment   string  `json:"comment"`
}

AttachmentExtensions Extensions

type AttachmentFetchResult

type AttachmentFetchResult struct {
	ID         string               `json:"id"`
	Type       string               `json:"type"`
	Status     string               `json:"status"`
	Title      string               `json:"title"`
	MetaData   AttachmentMetaData   `json:"metadata"`
	Extensions AttachmentExtensions `json:"extensions"`
	Expandable AttachmentExpandable `json:"_expandable"`
	Links      AttachmentLinks      `json:"_links"`
}

AttachmentFetchResult ...

type AttachmentLabels

type AttachmentLabels struct {
	Results []interface{}     `json:"results"`
	Start   float64           `json:"start"`
	Limit   float64           `json:"limit"`
	Size    float64           `json:"size"`
	Links   map[string]string `json:"_links"`
}

AttachmentLabels ...

type AttachmentLinks struct {
	Self      string `json:"self"`
	Webui     string `json:"webui"`
	Download  string `json:"download"`
	Thumbnail string `json:"thumbnail"`
}

AttachmentLinks links

func (*AttachmentLinks) UnmarshalJSON

func (a *AttachmentLinks) UnmarshalJSON(data []byte) error

UnmarshalJSON Custom Unmarshaller

type AttachmentMetaData

type AttachmentMetaData struct {
	MediaType  string                 `json:"mediaType"`
	Labels     AttachmentLabels       `json:"labels"`
	Expandable map[string]interface{} `json:"_expandable"`
}

AttachmentMetaData ...

type AttachmentResults

type AttachmentResults struct {
	Results []AttachmentFetchResult `json:"results"`
	Start   float64                 `json:"start"`
	Limit   float64                 `json:"limit"`
	Size    float64                 `json:"size"`
	Links   map[string]string       `json:"_links"`
}

AttachmentResults Results

type Attachments

type Attachments struct {
	Results []Attachment `json:"results"`
	Size    int          `json:"size"`
}

Attachments ..

type Client

type Client struct {
	Cookie      string
	Username    string
	Password    string
	AccessToken string
	Endpoint    string
	Debug       bool
}

Client for the Confluence API

func (*Client) AddAttachment

func (client *Client) AddAttachment(contentID, path string) (*Attachment, error)

AddAttachment ...

func (*Client) AddLabels

func (client *Client) AddLabels(contentID string, labels []string, prefix LabelPrefix) error

AddLabels ...

func (*Client) AddUpdateAttachments

func (client *Client) AddUpdateAttachments(contentID string, files []string) ([]*Attachment, []error)

AddUpdateAttachments ...

func (*Client) CreateContent

func (client *Client) CreateContent(bp *CreateContentBodyParameters, qp *QueryParameters) (Content, error)

CreateContent creates a new piece of content or publishes an existing draft. https://developer.atlassian.com/cloud/confluence/rest/#api-content-post

func (*Client) Delete

func (client *Client) Delete(class interface{}) error

Delete deletes various API types

func (*Client) DeleteAttachment

func (client *Client) DeleteAttachment(contentID string, attachmentID string) error

DeleteAttachment ..

func (*Client) DeleteContent

func (client *Client) DeleteContent(content Content) error

DeleteContent oves a piece of content to the space’s trash or purges it from the trash, depending on the content’s type and status:

  • If the content’s type is `page` or `blogpost` and its status is `current`, it will be trashed.
  • If the content’s type is `page` or `blogpost` and its status is `trashed`, the content will be purged from the trash and deleted permanently. Note, you must also set the `status` query parameter to `trashed` in your request.
  • If the content’s type is `comment` or `attachment`, it will be deleted permanently without being trashed.

https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-delete

func (*Client) DownloadAttachmentsFromPage

func (client *Client) DownloadAttachmentsFromPage(pageID, directory string) error

DownloadAttachmentsFromPage ...

func (*Client) DownloadFromURL

func (client *Client) DownloadFromURL(url, outputFilepath string) error

DownloadFromURL ...

func (*Client) FetchAttachmentMetaData

func (client *Client) FetchAttachmentMetaData(contentID string) (*AttachmentResults, error)

FetchAttachmentMetaData ...

func (*Client) GetAttachment

func (client *Client) GetAttachment(contentID, attachmentID string) (*Attachment, error)

GetAttachment ...

func (*Client) GetAttachmentByFilename

func (client *Client) GetAttachmentByFilename(contentID, filename string) (*Attachment, error)

GetAttachmentByFilename ...

func (*Client) GetContent

func (client *Client) GetContent(qp *GetContentQueryParameters) ([]Content, error)

GetContent Returns all content in a Confluence instance. https://developer.atlassian.com/cloud/confluence/rest/#api-content-get

func (*Client) Search

func (client *Client) Search(qp *SearchQueryParameters) ([]SearchResult, error)

Search searches for content using the Confluence Query Language (CQL) https://developer.atlassian.com/cloud/confluence/rest/#api-search-get

Example:

searchResults, err := client.Search(&confluence.SearchQueryParameters{
  CQL:   "space = PE",
  Limit: 1,
})

if err != nil {
  errorAndExit(err)
}

for _, searchResult := range searchResults {
  fmt.Println(searchResult.Title)
}

func (*Client) UpdateAttachment

func (client *Client) UpdateAttachment(contentID, attachmentID, path string, minorEdit bool) (*Attachment, error)

UpdateAttachment ...

func (*Client) UpdateContent

func (client *Client) UpdateContent(content *Content, qp *QueryParameters) (Content, error)

UpdateContent updates a piece of content. Use this method to update the title or body of a piece of content, change the status, change the parent page, and more. https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-put

type Content

type Content struct {
	ID        string `json:"id,omitempty"`
	Type      string `json:"type,omitempty"`
	Status    string `json:"status,omitempty"`
	Title     string `json:"title,omitempty"`
	URL       string `json:"url,omitempty"`
	Ancestors []struct {
		ID string `json:"id,omitempty"`
	} `json:"ancestors,omitempty"`
	Space struct {
		Key string `json:"key,omitempty"`
	} `json:"space,omitempty"`
	Version struct {
		Number  int    `json:"number,omitempty"`
		Message string `json:"message,omitempty"`
	} `json:"version,omitempty"`
	Body struct {
		Storage struct {
			Value           string        `json:"value,omitempty"`
			Representation  string        `json:"representation,omitempty"`
			EmbeddedContent []interface{} `json:"embeddedContent,omitempty"`
			Expandable      struct {
				Content string `json:"content,omitempty"`
			} `json:"_expandable,omitempty"`
		} `json:"storage,omitempty"`
	} `json:"body,omitempty"`
	Links struct {
		Self   string `json:"self,omitempty"`
		Tinyui string `json:"tinyui,omitempty"`
		Editui string `json:"editui,omitempty"`
		Webui  string `json:"webui,omitempty"`
	} `json:"_links,omitempty"`
}

Content represents the data returned from the Confluence API

type ContentResponse

type ContentResponse struct {
	Results []Content `json:"results"`
}

ContentResponse represents the data returned from the Confluence API

type CreateContentBodyParameters

type CreateContentBodyParameters struct {
	Content
}

CreateContentBodyParameters query parameters for CreateContent

type GetContentQueryParameters

type GetContentQueryParameters struct {
	QueryParameters
	Expand       []string `url:"-"`
	ExpandString string   `url:"expand,omitempty"`
	Limit        int      `url:"limit,omitempty"`
	Orderby      string   `url:"orderby,omitempty"`
	PostingDay   string   `url:"postingDay,omitempty"`
	Spacekey     string   `url:"spaceKey,omitempty"`
	Start        int      `url:"start,omitempty"`
	Title        string   `url:"title,omitempty"`
	Trigger      string   `url:"trigger,omitempty"`
	Type         string   `url:"type,omitempty"`
}

GetContentQueryParameters query parameters for GetContent

type LabelPrefix

type LabelPrefix string

LabelPrefix ...

const (
	// GlobalPrefix ...
	GlobalPrefix LabelPrefix = "global"
	// LocalPrefix ...
	LocalPrefix LabelPrefix = "local"
)

type PreRequestFn

type PreRequestFn func(request *http.Request)

PreRequestFn ...

type QueryParameters

type QueryParameters struct {
	Expand []string `url:"expand,omitempty"`
	Status string   `url:"status,omitempty"`
}

QueryParameters provides default query parameters for client

type SearchQueryParameters

type SearchQueryParameters struct {
	CQL                   string `url:"cql"`
	CQLContext            string `url:"cqlcontext,omitempty"`
	IncludeArchivedSpaces bool   `url:"includeArchivedSpaces,omitempty"`
	Limit                 int    `url:"limit,omitempty"`
	Start                 int    `url:"start,omitempty"`
}

SearchQueryParameters query parameters for Search

type SearchResponse

type SearchResponse struct {
	APIResponse
	Results        []SearchResult `json:"results,omitempty"`
	Start          int            `json:"start,omitempty"`
	Limit          int            `json:"limit,omitempty"`
	Size           int            `json:"size,omitempty"`
	TotalSize      int            `json:"totalSize,omitempty"`
	CqlQuery       string         `json:"cqlQuery,omitempty"`
	SearchDuration int            `json:"searchDuration,omitempty"`
	Links          struct {
		Base    string `json:"base,omitempty"`
		Context string `json:"context,omitempty"`
	} `json:"_links,omitempty"`
}

SearchResponse represents the data returned from the Confluence API

type SearchResult

type SearchResult struct {
	Space struct {
		Key      string `json:"key,omitempty"`
		Name     string `json:"name,omitempty"`
		Type     string `json:"type,omitempty"`
		Metadata struct {
		} `json:"metadata,omitempty"`
		Status     string `json:"status,omitempty"`
		Expandable struct {
			Operations  string `json:"operations,omitempty"`
			Permissions string `json:"permissions,omitempty"`
			Description string `json:"description,omitempty"`
		} `json:"_expandable,omitempty"`
		Links struct {
			Self string `json:"self,omitempty"`
		} `json:"_links,omitempty"`
	} `json:"space,omitempty"`
	Title                 string `json:"title,omitempty"`
	Excerpt               string `json:"excerpt,omitempty"`
	URL                   string `json:"url,omitempty"`
	ResultGlobalContainer struct {
		Title      string `json:"title"`
		DisplayURL string `json:"displayUrl"`
	} `json:"resultGlobalContainer"`
	Breadcrumbs          []interface{} `json:"breadcrumbs,omitempty"`
	EntityType           string        `json:"entityType,omitempty"`
	IconCSSClass         string        `json:"iconCssClass,omitempty"`
	LastModified         time.Time     `json:"lastModified,omitempty"`
	FriendlyLastModified string        `json:"friendlyLastModified,omitempty"`
	Score                float64       `json:"score,omitempty"`
	Content              `json:"content,omitempty"`
}

SearchResult results from Search

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL