zube

package module
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

README

About

This is a small library that implements a Zube API client in Go.

Usage

You can take a look at the examples folder to see how to use the library.

go run examples/epics/fetch_epics.go

Remember to set your own credential values first.

Authentication

You can read the details of the auth mechanism in the official docs.

In short, you will need:

  • Your Zube clientId
  • Your private key as a .pem file
  • Your access token

By default, the library will look for the private key in ~/.ssh/zube_api_key.pem, but this will be configurable in the future.

This is a barebones implementation of creating a client. If the access token passed is empty, it will be automatically fetched from Zube.

 clientId := "fd59a5e4-2505-4be0-8818-4f25466fded3"
 client, _ := zube.NewClient(clientId, "")

 client.FetchSources()

If you don't want to go through the access token regeneration after every call to the constructor, you can cache the access token and re-use it (note: as of the time of writing it is valid for only up to 24 hours).

Documentation

Index

Constants

View Source
const (
	ZubeHost  string = "zube.io"
	ApiUrl    string = "https://zube.io/api/"
	UserAgent string = "Zube-Go"
)
View Source
const PrivateKeyFileName = "zube_api_key.pem"

Variables

This section is empty.

Functions

func CardUrl

func CardUrl(account *models.Account, project *models.Project, card *models.Card) string

Returns a direct URL to a Zube card

func Check

func Check(err error, msg string)

func Contains

func Contains[T comparable](coll []T, e T) bool

Check if `coll` contains an element `e` of type `T`

func EpicTitles

func EpicTitles(epics *[]models.Epic) []string

func GenerateRefreshJWT

func GenerateRefreshJWT(clientId string, key *rsa.PrivateKey) (string, error)

Create a refresh JWT valid for one minute, used to fetch an access token JWT

func GetEpicByTitle

func GetEpicByTitle(title string, epics *[]models.Epic) models.Epic

func GetLabelsByIndexes

func GetLabelsByIndexes(indexes []int, labels []models.Label) []models.Label

func GetMembersByNames

func GetMembersByNames(names []string, members []models.Member) []models.Member

func GetPrivateKey

func GetPrivateKey() (*rsa.PrivateKey, error)

func GetPrivateKeyWithPath

func GetPrivateKeyWithPath(privateKeyPath string) (*rsa.PrivateKey, error)

Returns the parsed RSA private key from the given path to a .pem file

func GetProjectByName

func GetProjectByName(name string, projects *[]models.Project) (models.Project, error)

func GetSourceByName

func GetSourceByName(name string, sources *[]models.Source) models.Source

func GetWorkspaceByName

func GetWorkspaceByName(name string, workspaces *[]models.Workspace) models.Workspace

func IsTokenValid

func IsTokenValid(token models.ZubeAccessToken) bool

Returns true if the token is present and not expired

func LabelIds

func LabelIds(labels *[]models.Label) []int

func LabelNames

func LabelNames(labels *[]models.Label) []string

Convert labels to a slice of label names

func MemberIds

func MemberIds(members *[]models.Member) []int

func MemberNames

func MemberNames(members *[]models.Member) []string

func ParsePriority

func ParsePriority(priority string) optional.Int

func PrivateKeyFilePath

func PrivateKeyFilePath() string

Returns the correct path to the user's private key file

func ProjectNames

func ProjectNames(projects *[]models.Project) []string

Convert projects to a slice of project names

func SourceNames

func SourceNames(sources *[]models.Source) []string

func WorkspaceNames

func WorkspaceNames(workspaces *[]models.Workspace) []string

Convert workspaces to a slice of workspace names

Types

type Client

type Client struct {
	models.ZubeAccessToken // An encoded access JWT valid for 24h to the Zube API
	Host                   string
	ClientId               string // Your unique client ID
	HTTPc                  http.Client
}

func NewClient

func NewClient(clientId, accessToken string) (*Client, error)

Creates and returns a Zube Client with an access token If the current access token is invalid, it is refreshes and saved to config

func NewClientWithId

func NewClientWithId(clientId string) *Client

Constructs a new client with only host and Client ID configured, enough to make an access token request.

func (*Client) CreateCard

func (client *Client) CreateCard(card *models.Card) models.Card

func (*Client) DoApiRequestUrl added in v2.0.2

func (client *Client) DoApiRequestUrl(method string, url *url.URL, body io.Reader) ([]byte, error)

Performs a generic request with URL and body

func (*Client) FetchAccounts

func (client *Client) FetchAccounts(query *Query) []models.Account

Fetch and return an array of `Account`s

func (*Client) FetchCardComments

func (client *Client) FetchCardComments(cardId int) []models.Comment

func (*Client) FetchCards

func (client *Client) FetchCards(query *Query) []models.Card

Fetch and return an array of `Card`s

func (*Client) FetchCurrentPerson

func (client *Client) FetchCurrentPerson() models.CurrentPerson

func (*Client) FetchEpics

func (client *Client) FetchEpics(projectId int) []models.Epic

Fetch all epics for a given project

func (*Client) FetchLabels

func (client *Client) FetchLabels(projectId int) []models.Label

Fetch all labels for a given project

func (*Client) FetchProjectCards

func (client *Client) FetchProjectCards(projectId int, query *Query) []models.Card

Fetch cards for a specific project. The `project_id` key in the `Where` part of the `Query`'s `Filter` will have no effect.

func (*Client) FetchProjectMembers

func (client *Client) FetchProjectMembers(projectId int) []models.Member

func (*Client) FetchProjects

func (client *Client) FetchProjects(query *Query) []models.Project

func (*Client) FetchSources

func (client *Client) FetchSources() []models.Source

Fetch and return an array of Github `Source`s

func (*Client) FetchSprints

func (client *Client) FetchSprints(workspaceId int) []models.Sprint

Fetch all sprints for a given workspace

func (*Client) FetchWorkspaces

func (client *Client) FetchWorkspaces(query *Query) []models.Workspace

func (*Client) MoveCard added in v2.0.2

func (client *Client) MoveCard(cardId int, destination *models.Destination)

Move a card to a new destination

func (*Client) RefreshAccessToken

func (client *Client) RefreshAccessToken(key *rsa.PrivateKey) (*Client, error)

Fetch the access token JWT from Zube API and set it for the client. If it already exists, refresh it.

func (*Client) SearchCards

func (client *Client) SearchCards(query *Query) []models.Card

Search Zube cards using a simple Query struct with `search` field in it.

type Filter

type Filter struct {
	Where  map[string]any // Map of keys corresponding to fields to filter by
	Select []string       // Array of attributes to select
}

type Order

type Order struct {
	By        string // Column / field to order by
	Direction string // Either of `asc` or `desc`
}

type Pagination

type Pagination struct {
	Page    string // Results page to paginate to
	PerPage string // How many results to fetch per page, defaults to 30
}

type Query

type Query struct {
	Pagination
	Order
	Filter
	Search string `json:"search"` // Undocumented search API query parameter, pass search query string here
}

Represents possible Zube query parameters

func (*Query) Encode

func (query *Query) Encode() string

Encodes everything in `Query` into a flat Zube query string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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