outline

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 8 Imported by: 0

README

Checks MIT

go-outline

Go client and cli for outline.

Installation

Installing the client:

go get github.com/ioki-mobility/go-outline

Installing the CLI:

  • Download pre-built binaries from releases page for your platform
  • Install via go toolchain:
go install github.com/ioki-mobility/go-outline/cli@latest

Usage

Client

Create a client
cl := outline.New("https://server.url", &http.Client{}, "api key")

Note: You can create a new API key in your outline account settings.

Get a collection
col, err := cl.Collections().Get("collection id").Do(context.Background())
if err != nil {
	panic(err)
}
fmt.Println(col)
Get all collections
err := cl.Collections().List().Do(context.Background(), func(col *outline.Collection, err error) (bool, error) {
	fmt.Println(col)
	return true, nil
})
if err != nil {
	panic(err)
}
Create a collection
col, err := cl.Collections().Create("collection name").Do(context.Background()) 
if err != nil {
	panic(err)
}
fmt.Println(col)

There are also optional functions for the CollectionsCreateClient available:

colCreateClient := cl.Collections().Create("collection name")
colCreateClient.
	Description("desc"). 
	PermissionRead(). // or PermissionReadWrite()
	Color("#c0c0c0").
	Private(true).
	Do(context.Background())
Document Create
doc := cl.Documents().Create("Document name", "collection id").Do(context.Background())

There re also optional functions for the DocumentsCreateClient available:

docCreateClient := cl.Documents().Create("Document name")
docCreateClient.
	Publish(true). 
	Text("text").
	ParentDocumentID(DocumentId("parent document id")).
	TemplateID(TemplateId("templateId")).
	Template(false).
	Do(context.Background())

CLI

Build the CLI
go build -o outline ./cli
Required flags

Any command requires the flags server and key. You can simply add them with --server https://server.url and --key sup3rS3cre7Ap1K3Y.

Collections

The basic command to work with collections is:

outline collections
Collections fetch

To fetch a collection and display it in a json string use:

outline collections fetch [COLLECTION_ID] [flags]
Collections create

To create a collection and display the created collection as a json string use:

outline collections create [COLLECTION_NAME] [flags]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTemporary

func IsTemporary(err error) bool

IsTemporary returns true if err is temporary in nature i.e. you can retry the same operation in some time. This would usually return true for server side errors.

Types

type Attachment added in v0.4.0

type Attachment struct {
	MaxUploadSize  int                    `json:"maxUploadSize"`
	UploadURL      string                 `json:"uploadUrl"`
	Form           map[string]interface{} `json:"form"`
	AttachmentData AttachmentData         `json:"attachment"`
}

type AttachmentCreateClient added in v0.4.0

type AttachmentCreateClient struct {
	// contains filtered or unexported fields
}

AttachmentCreateClient is a client for creating a single attachment.

func (*AttachmentCreateClient) Do added in v0.4.0

Do makes the actual request to create a attachment.

func (*AttachmentCreateClient) DocumentID added in v0.4.0

type AttachmentData added in v0.4.0

type AttachmentData struct {
	ContentType string `json:"contentType"`
	Size        int    `json:"size"`
	Name        string `json:"name"`
	URL         string `json:"url"`
	DocumentID  string `json:"documentId"`
}

type AttachmentsClient added in v0.4.0

type AttachmentsClient struct {
	// contains filtered or unexported fields
}

AttachmentsClient exposes CRUD operations around the attachments resource.

func (*AttachmentsClient) Create added in v0.4.0

func (cl *AttachmentsClient) Create(name string, contentType string, size int) *AttachmentCreateClient

Create returns a client for creating a single attachment in the specified collection. API reference: https://www.getoutline.com/developers#tag/Attachments/paths/~1attachments.create/post

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is per server top level client which acts as entry point and stores common configuration (like base url) for resource level clients. It is preferred to reuse same client while communicating to the same server as this makes better utilization of resources.

func New

func New(serverURL string, hc *http.Client, apiKey string) *Client

New creates and returns a new (per server) client.

func (*Client) Attachments added in v0.4.0

func (cl *Client) Attachments() *AttachmentsClient

Attachments creates a client for operating on attachments.

func (*Client) Collections

func (cl *Client) Collections() *CollectionsClient

Collections creates a client for operating on collections.

func (*Client) Documents

func (cl *Client) Documents() *DocumentsClient

Documents creates a client for operating on documents.

type Collection

type Collection struct {
	ID          CollectionID   `json:"id"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Sort        map[string]any `json:"sort"`
	Index       string         `json:"index"`
	Color       string         `json:"color"`
	Icon        string         `json:"icon"`
	Permission  string         `json:"permission"`
	CreatedAt   time.Time      `json:"createdAt"`
	UpdatedAt   time.Time      `json:"updatedAt"`
	DeletedAt   time.Time      `json:"deletedAt"`
}

Collection represents an outline collection.

type CollectionID

type CollectionID string

type CollectionsClient

type CollectionsClient struct {
	// contains filtered or unexported fields
}

CollectionsClient exposes CRUD operations around the collections resource.

func (*CollectionsClient) Create

Create returns a client for creating a collection. API reference: https://www.getoutline.com/developers#tag/Collections/paths/~1collections.create/post

func (*CollectionsClient) DocumentStructure

DocumentStructure gives access to id's document structure. API Reference: https://www.getoutline.com/developers#tag/Collections/paths/~1collections.documents/post

func (*CollectionsClient) Get

func (*CollectionsClient) List

type CollectionsCreateClient

type CollectionsCreateClient struct {
	// contains filtered or unexported fields
}

func (*CollectionsCreateClient) Color

func (*CollectionsCreateClient) Description

func (*CollectionsCreateClient) Do

Do make the actual request to create a collection.

func (*CollectionsCreateClient) PermissionRead

func (cl *CollectionsCreateClient) PermissionRead() *CollectionsCreateClient

func (*CollectionsCreateClient) PermissionReadWrite

func (cl *CollectionsCreateClient) PermissionReadWrite() *CollectionsCreateClient

func (*CollectionsCreateClient) Private

type CollectionsDocumentStructureClient

type CollectionsDocumentStructureClient struct {
	// contains filtered or unexported fields
}

func (*CollectionsDocumentStructureClient) Do

Do makes the actual request for getting the collection's document structure.

type CollectionsGetClient

type CollectionsGetClient struct {
	// contains filtered or unexported fields
}

func (*CollectionsGetClient) Do

Do makes the actual request for fetching said collection info.

type CollectionsListClient

type CollectionsListClient struct {
	// contains filtered or unexported fields
}

func (*CollectionsListClient) Do

Do makes the actual request for listing all collections. If the request is successful then fn is called sequentially with every collection received. But if there is some error/bad response then fn is called with the error. If fn returns false then the whole process is aborted otherwise the request is retried. NOTE: Policies if any returned are ignored as of now. Later if we find them important then we can include them too.

type CollectionsListFn

type CollectionsListFn func(*Collection, error) (bool, error)

CollectionsListFn is the type of function called by CollectionsListClient.Do for every new collection it finds.

type Document

type Document struct {
	ID               DocumentID    `json:"id"`
	CollectionID     CollectionID  `json:"collectionId"`
	ParentDocumentID DocumentID    `json:"parentDocumentId"`
	Title            string        `json:"title"`
	FullWidth        bool          `json:"fullWidth"`
	Emoji            string        `json:"emoji"`
	Text             string        `json:"text"`
	URLID            string        `json:"urlId"`
	Collaborators    []interface{} `json:"collaborators"`
	Pinned           bool          `json:"pinned"`
	Template         bool          `json:"template"`
	TemplateID       TemplateID    `json:"templateId"`
	Revision         int           `json:"revision"`
	CreatedAt        time.Time     `json:"createdAt"`
	CreatedBy        interface{}   `json:"createdBy"`
	UpdatedAt        time.Time     `json:"updatedAt"`
	UpdatedBy        interface{}   `json:"updatedBy"`
	PublishedAt      time.Time     `json:"publishedAt"`
	ArchivedAt       time.Time     `json:"archivedAt"`
	DeletedAt        time.Time     `json:"deletedAt"`
}

Document represents an outline document.

type DocumentID

type DocumentID string

type DocumentShareID

type DocumentShareID string

type DocumentStructure

type DocumentStructure []DocumentSummary

type DocumentSummary

type DocumentSummary struct {
	ID       DocumentID        `json:"id"`
	Title    string            `json:"title"`
	URL      string            `json:"url"`
	Children []DocumentSummary `json:"children"`
}

DocumentSummary represents summary of a document (and its children) that is part of a collection.

type DocumentUrlID

type DocumentUrlID string

type DocumentsClient

type DocumentsClient struct {
	// contains filtered or unexported fields
}

DocumentsClient exposes CRUD operations around the documents resource.

func (*DocumentsClient) Create

Create returns a client for creating a single document in the specified collection. API reference: https://www.getoutline.com/developers#tag/Documents/paths/~1documents.create/post

func (*DocumentsClient) Get

Get returns a client for retrieving a single document.

func (*DocumentsClient) GetAll

func (cl *DocumentsClient) GetAll() *DocumentsClientGetAll

GetAll returns a client for retrieving multiple documents at once.

func (*DocumentsClient) Update added in v0.2.0

Update returns a client for updating a single document in the specified collection. API reference: https://www.getoutline.com/developers#tag/Documents/paths/~1documents.update/post

type DocumentsClientGet

type DocumentsClientGet struct {
	// contains filtered or unexported fields
}

DocumentsClientGet gets a single document.

func (*DocumentsClientGet) ByID

ByID configures that document be retrieved by its id.

func (*DocumentsClientGet) ByShareID

ByShareID configures that document be retrieved by its share id.

func (*DocumentsClientGet) Do

Do makes the actual request and returns the document.

type DocumentsClientGetAll

type DocumentsClientGetAll struct{}

DocumentsClientGetAll can be used to retrieve more than one document. Use available configuration options to select the documents you want to retrieve then finally call DocumentsClientGetAll.Do.

func (*DocumentsClientGetAll) Collection

Collection selects documents belonging to the collection identified by id.

func (*DocumentsClientGetAll) Do

func (cl *DocumentsClientGetAll) Do(ctx context.Context, fn func(*Document, error) bool) error

Do makes the actual request and retrieves selected documents. The user provided callback fn is called for every such document. If there is any error during the process then fn is given the error so that it can decide whether to continue or not. The callback can return false in case it wants to abort getting documents.

func (*DocumentsClientGetAll) Parent

Parent selects documents having the parent document identified by id.

type DocumentsCreateClient

type DocumentsCreateClient struct {
	// contains filtered or unexported fields
}

DocumentsCreateClient is a client for creating a single document.

func (*DocumentsCreateClient) Do

Do makes the actual request to create a document.

func (*DocumentsCreateClient) ParentDocumentID

func (cl *DocumentsCreateClient) ParentDocumentID(id DocumentID) *DocumentsCreateClient

func (*DocumentsCreateClient) Publish

func (cl *DocumentsCreateClient) Publish(publish bool) *DocumentsCreateClient

func (*DocumentsCreateClient) Template

func (cl *DocumentsCreateClient) Template(template bool) *DocumentsCreateClient

func (*DocumentsCreateClient) TemplateID

func (*DocumentsCreateClient) Text

type DocumentsUpdateClient added in v0.2.0

type DocumentsUpdateClient struct {
	// contains filtered or unexported fields
}

DocumentsUpdateClient is a client for updating a single document.

func (*DocumentsUpdateClient) Append added in v0.2.0

func (cl *DocumentsUpdateClient) Append(append bool) *DocumentsUpdateClient

func (*DocumentsUpdateClient) Do added in v0.2.0

Do makes the actual request to update a document.

func (*DocumentsUpdateClient) Done added in v0.2.0

func (*DocumentsUpdateClient) Publish added in v0.2.0

func (cl *DocumentsUpdateClient) Publish(publish bool) *DocumentsUpdateClient

func (*DocumentsUpdateClient) Text added in v0.2.0

func (*DocumentsUpdateClient) Title added in v0.2.0

type TemplateID

type TemplateID string

Directories

Path Synopsis
internal
cli

Jump to

Keyboard shortcuts

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