twist

package module
v0.0.0-...-5829ee7 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 11 Imported by: 0

README

twist

Package twist implements Go client for Twist API

See documentation at https://pkg.go.dev/github.com/artyom/twist

Documentation

Overview

Package twist provides functions to work with Twist API.

It relies on Twist API v3 documented at https://developer.twist.com/v3/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Id       uint64 `json:"id"`
	Name     string `json:"name"`
	Archived bool   `json:"archived"`
}

Channel is a Twist channel. Channels organize threads around broad topics like team, project, location, or area of interest. Channel contains threads.

See https://developer.twist.com/v3/#channels for details.

type Client

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

Client is a Twist API client.

func New

func New(token string) *Client

New returns Client that calls Twist API using provided token for authentication.

See https://developer.twist.com/v3/#authentication for details.

func (*Client) Channels

func (c *Client) Channels(ctx context.Context, workspaceID uint64) ([]Channel, error)

Channels returns all the channels in a given workspace.

func (*Client) CommentsPaginator

func (c *Client) CommentsPaginator(threadID uint64) *CommentsPaginator

CommentsPaginator returns CommentsPaginator that fetches all comments of a thread.

func (*Client) NewCommentsPaginator

func (c *Client) NewCommentsPaginator(threadID uint64, since time.Time) *CommentsPaginator

NewCommentsPaginator returns CommentsPaginator that fetches only thread comments that were posted since given time.

Only use it to update thread comments you already have on a best-effort basis. Twist API logic is racy and may miss some comments that were updated between per-page API calls. If you need to fetch all comments of a thread, use CommentsPaginator method instead.

func (*Client) NewThreadsPaginator

func (c *Client) NewThreadsPaginator(channelID uint64, since time.Time) *ThreadsPaginator

NewThreadsPaginator returns ThreadsPaginator that fetches only threads updated since given time.

Only use it to update channel thread list that you already have on a best-effort basis. Twist API logic is racy and may miss some threads that were updated between per-page API calls. If you need to fetch all threads of a channel, use ThreadsPaginator method instead.

func (*Client) Thread

func (c *Client) Thread(ctx context.Context, threadID uint64) (*Thread, error)

Thread returns a single thread. Use ThreadsPaginator to get all threads of a channel.

func (*Client) ThreadsPaginator

func (c *Client) ThreadsPaginator(channelID uint64) *ThreadsPaginator

ThreadsPaginator returns ThreadsPaginator that fetches all threads of a channel.

func (*Client) Users

func (c *Client) Users(ctx context.Context, workspaceID uint64) ([]User, error)

func (*Client) Workspaces

func (c *Client) Workspaces(ctx context.Context) ([]Workspace, error)

Workspaces returns all the workspaces user has access to.

type Comment

type Comment struct {
	Id         uint64 `json:"id"`
	Text       string `json:"content"`
	Creator    uint64 `json:"creator"`
	OrderIndex int    `json:"obj_index"`
	TsPosted   uint64 `json:"posted_ts"`
}

Comment is a message posted to a thread.

See https://developer.twist.com/v3/#comments for details.

func (*Comment) PostedAt

func (c *Comment) PostedAt() time.Time

PostedAt is a convenience method to convert TsPosted field to time.

type CommentsPaginator

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

CommentsPaginator fetches comments of a thread.

Typical usage:

p := client.CommentsPaginator(3456) // get comments for thread with id=3456
for p.Next() {
	comments, err := p.Page(ctx)
	if err != nil {
		return err
	}
	doSomethingWithComments(comments)
}

func (*CommentsPaginator) Next

func (tp *CommentsPaginator) Next() bool

Next reports whether there's another page to load. It only returns false once all channels are fetched with the Page method.

func (*CommentsPaginator) Page

func (tp *CommentsPaginator) Page(ctx context.Context) ([]Comment, error)

Page returns next portion of thread comments.

type Thread

type Thread struct {
	Id        uint64 `json:"id"`
	TsPosted  uint64 `json:"posted_ts"`
	TsUpdated uint64 `json:"last_updated_ts"`
	Title     string `json:"title"`
	Text      string `json:"content"`
	Creator   uint64 `json:"creator"`
	Archived  bool   `json:"is_archived"`
}

Thread is a Twist thread. Threads keep team's conversations organized by specific topics. Thread contains comments.

See https://developer.twist.com/v3/#threads for details.

func (*Thread) PostedAt

func (t *Thread) PostedAt() time.Time

PostedAt is a convenience method to convert TsPosted field to time.

func (*Thread) UpdatedAt

func (t *Thread) UpdatedAt() time.Time

UpdatedAt is a convenience method to convert TsUpdated field to time.

type ThreadsPaginator

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

ThreadsPaginator fetches threads of a channel.

Typical usage:

p := client.ThreadsPaginator(1234) // get threads for channel with id=1234
for p.Next() {
	threads, err := p.Page(ctx)
	if err != nil {
		return err
	}
	doSomethingWithThreads(threads)
}

func (*ThreadsPaginator) Next

func (cp *ThreadsPaginator) Next() bool

Next reports whether there's another page to load. It only returns false once all threads are fetched with the Page method.

func (*ThreadsPaginator) Page

func (cp *ThreadsPaginator) Page(ctx context.Context) ([]Thread, error)

Page returns next portion of channel threads.

type User

type User struct {
	Id        uint64 `json:"id"`
	Name      string `json:"name"`
	ShortName string `json:"short_name"`
}

type Workspace

type Workspace struct {
	Id   uint64 `json:"id"`
	Name string `json:"name"`
}

Workspace is a Twist workspace. A workspace is a shared place between different users. Workspace contains channels.

See https://developer.twist.com/v3/#workspaces for details.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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