monday

package
v0.0.0-...-a4f4c6b Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package monday is taken mostly from here: https://golang.ir/play/p/aZ7tgaqFxWP.

Index

Constants

View Source
const (
	DateFormat     = "2006-01-02"
	TimeFormat     = "15:04:05"
	DateTimeFormat = DateFormat + " " + TimeFormat
)

Variables

View Source
var AddItem = api.NewBinding[ItemId, string](
	func(b api.Binding[ItemId, string], args ...any) api.Request {
		req := NewRequest(`mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $colValues: JSON!) { create_item (board_id: $boardId, group_id: $groupId, item_name: $itemName, column_values: $colValues ) { id } }`)
		boardId := args[0].(int)
		groupId := args[1].(string)
		itemName := args[2].(string)
		columnValues := args[3].(map[string]interface{})
		jsonValues, _ := json.Marshal(&columnValues)
		req.Var("boardId", boardId)
		req.Var("groupId", groupId)
		req.Var("itemName", itemName)
		req.Var("colValues", string(jsonValues))
		return req
	},
	ResponseWrapper[ItemId, string],
	ResponseUnwrapped[ItemId, string],
	func(b api.Binding[ItemId, string], response ItemId, args ...any) string {
		return response.Id
	},
	func(binding api.Binding[ItemId, string]) []api.BindingParam {
		return api.Params("boardId", 0, true, "groupId", 0, true, "itemName", "", true, "columnValues", map[string]any{})
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "create_item" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("AddItem")

AddItem is a Binding that adds an Item of the given name and column values to the given Board and Group combination. Arguments provided to Binding.Execute:

• boardId (int): The ID of the Board to which to add the Item to.

• groupId (string): The ID of the Group to which to add the Item to.

• itemName (string): The name of the new Item.

• columnValues (map[string]interface{}): The values of the columns of the new Item.

Binding.Execute returns the ID of the newly added Item.

View Source
var AddItemUpdate = api.NewBinding[ItemId, string](
	func(b api.Binding[ItemId, string], args ...any) api.Request {
		itemId := args[0].(int)
		msg := args[1].(string)
		req := NewRequest(`mutation ($itemId: Int!, $body: String!) { create_update (item_id: $itemId, body: $body ) { id } }`)
		req.Var("itemId", itemId)
		req.Var("body", msg)
		return req
	},
	ResponseWrapper[ItemId, string],
	ResponseUnwrapped[ItemId, string],
	func(b api.Binding[ItemId, string], response ItemId, args ...any) string {
		return response.Id
	},
	func(binding api.Binding[ItemId, string]) []api.BindingParam {
		return api.Params("itemId", 0, true, "msg", "", true)
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "create_update" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("AddItemUpdate")

AddItemUpdate is a Binding that adds an update with the given message to the Item of the given ID. Arguments provided to Binding.Execute:

• itemId (int): The ID of the Item to add an update to.

• msg (string): The body of the update that will be added to the Item.

Binding.Execute returns the ID of the Item to which the update was added.

View Source
var ChangeMultipleColumnValues = api.NewBinding[ItemId, string](
	func(b api.Binding[ItemId, string], args ...any) api.Request {
		req := NewRequest(`mutation ($itemId: Int, $boardId: Int!, $colValues: JSON!) { change_multiple_column_values (item_id: $itemId, board_id: $boardId, column_values: $colValues) { id } }`)
		itemId := args[0].(int)
		boardId := args[1].(int)
		columnValues := args[2].(map[string]interface{})
		jsonValues, _ := json.Marshal(&columnValues)
		req.Var("itemId", itemId)
		req.Var("boardId", boardId)
		req.Var("colValues", string(jsonValues))
		return req
	},
	ResponseWrapper[ItemId, string],
	ResponseUnwrapped[ItemId, string],
	func(b api.Binding[ItemId, string], response ItemId, args ...any) string {
		return response.Id
	},
	func(binding api.Binding[ItemId, string]) []api.BindingParam {
		return api.Params("itemId", 0, true, "boardId", 0, true, "columnValues", map[string]any{})
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "change_multiple_column_values" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("ChangeMultipleColumnValues")

ChangeMultipleColumnValues is a Binding that changes multiple ColumnValue for the given Item and Board combination. Arguments provided to Binding.Execute:

• itemId (int): The ID of the Item for which we want to change the column values for.

• boardId (int): The ID of the Board that the Item resides within.

• columnValues (map[string]interface{}): The values to set the columns of the Item of the given ID that is within the Board of the given ID.

Binding.Execute returns the ID of the Item that has been mutated.

View Source
var DefaultClient api.Client
View Source
var DeleteItem = api.NewBinding[ItemId, string](
	func(binding api.Binding[ItemId, string], args ...any) (request api.Request) {
		req := NewRequest(`mutation ($itemId: Int) { delete_item (item_id: $itemId) { id } }`)
		itemId := args[0].(int)
		req.Var("itemId", itemId)
		return req
	},
	ResponseWrapper[ItemId, string],
	ResponseUnwrapped[ItemId, string],
	func(binding api.Binding[ItemId, string], response ItemId, args ...any) string { return response.Id },
	func(binding api.Binding[ItemId, string]) []api.BindingParam { return api.Params("itemId", 0, true) },
	false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "delete_item" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
)

DeleteItem is an api.Binding that deletes the Item of the given item ID. Arguments provided to Binding.Execute:

itemId (int): The ID of the Item that we want to delete.

Binding.Execute returns the ID for the Item that was deleted.

View Source
var GetBoards = api.NewBinding[[]Board, []Board](
	func(b api.Binding[[]Board, []Board], args ...any) api.Request {
		var (
			page         int
			workspaceIds []int
		)
		req := NewRequest(`query ($page: Int!, $workspaceIds: [Int]) { boards (page: $page, workspace_ids: $workspaceIds) { id name } }`)
		page = args[0].(int)
		workspaceIds = slices.Comprehension[any, int](args[1:], func(idx int, value any, arr []any) int {
			return value.(int)
		})
		req.Var("page", page)
		req.Var("workspaceIds", workspaceIds)
		return req
	},
	ResponseWrapper[[]Board, []Board],
	ResponseUnwrapped[[]Board, []Board],
	nil, func(binding api.Binding[[]Board, []Board]) []api.BindingParam {
		return api.Params("page", 1, "workspaceIds", []int{}, false, true)
	}, true,
	func(client api.Client) (string, any) { return "jsonResponseKey", "boards" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetBoards")

GetBoards is a Binding to retrieve multiple Board from the given workspaces. Arguments provided to Binding.Execute:

• page (int): The page of results to retrieve. This means that GetBoards can be passed to an api.Paginator.

• workspaceIds ([]int...): The IDs of the workspaces to retrieve all Board from.

Binding.Execute returns a list of Board instances from the given workspaces for the given page of results.

View Source
var GetColumnMap = api.NewBinding[columnResponse, map[string]ColumnMap](
	getColumnsRequest[columnResponse, map[string]ColumnMap],
	ResponseWrapper[columnResponse, map[string]ColumnMap],
	ResponseUnwrapped[columnResponse, map[string]ColumnMap],
	func(b api.Binding[columnResponse, map[string]ColumnMap], response columnResponse, args ...any) map[string]ColumnMap {
		m := make(map[string]ColumnMap)
		for _, board := range response {
			m[board.Id] = make(ColumnMap)
			for _, column := range board.Columns {
				m[board.Id][column.Id] = column
			}
		}
		return m
	},
	func(binding api.Binding[columnResponse, map[string]ColumnMap]) []api.BindingParam {
		return boardIdsParam()
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "boards" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetColumnMap")

GetColumnMap is a Binding to retrieve the multiple ColumnMap from the given boards. Arguments provided to Binding.Execute:

• boardIds ([]int...): The IDs of the boards to retrieve all ColumnMap for.

Binding.Execute returns a map of Board IDs to ColumnMap instances for the given boards.

View Source
var GetColumns = api.NewBinding[columnResponse, []Column](
	getColumnsRequest[columnResponse, []Column],
	ResponseWrapper[columnResponse, []Column],
	ResponseUnwrapped[columnResponse, []Column],
	func(b api.Binding[columnResponse, []Column], response columnResponse, args ...any) []Column {
		columns := make([]Column, 0)
		for _, board := range response {
			columns = append(columns, board.Columns...)
		}
		return columns
	},
	func(binding api.Binding[columnResponse, []Column]) []api.BindingParam {
		return boardIdsParam()
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "boards" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetColumns")

GetColumns is a Binding to retrieve multiple Column from the given boards. Arguments provided to Binding.Execute:

• boardIds ([]int...): The IDs of the boards to retrieve all Column from.

Binding.Execute returns a list of Column instances from the given boards.

View Source
var GetGroups = api.NewBinding[groupResponse, []Group](
	func(b api.Binding[groupResponse, []Group], args ...any) api.Request {
		req := NewRequest(`query ($boardIds: [Int]) { boards (ids: $boardIds) { groups { id title } } }`)
		req.Var("boardIds", slices.Comprehension(args, func(idx int, value any, arr []any) int {
			return value.(int)
		}))
		return req
	},
	ResponseWrapper[groupResponse, []Group],
	ResponseUnwrapped[groupResponse, []Group],
	func(b api.Binding[groupResponse, []Group], response groupResponse, args ...any) []Group {
		groups := make([]Group, 0)
		for _, board := range response {
			groups = append(groups, board.Groups...)
		}
		return groups
	},
	func(binding api.Binding[groupResponse, []Group]) []api.BindingParam {
		return boardIdsParam()
	}, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "boards" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetGroups")

GetGroups is a Binding to retrieve multiple Group from the given boards. Arguments provided to Binding.Execute:

• boardIds ([]int...): The IDs of the boards to retrieve all Group from.

Binding.Execute returns a list of Group instances from the given boards.

View Source
var GetItems = api.NewBinding[ItemResponse, []Item](
	func(b api.Binding[ItemResponse, []Item], args ...any) api.Request {
		var (
			page     int
			boardIds []int
			groupIds []string
		)
		req := NewRequest(`
			query ($page: Int!, $boardIds: [Int], $groupIds: [String]) {
				boards (ids: $boardIds) {
					id
					groups (ids: $groupIds) {
						id
						items (limit: 10, page: $page) {
							id name
							column_values { id title value }
						}
					}
				}
			}
		`)
		if len(args) > 0 {
			page = args[0].(int)
		}
		if len(args) > 1 {
			boardIds = args[1].([]int)
		}
		if len(args) > 2 {
			groupIds = args[2].([]string)
		}
		req.Var("page", page)
		req.Var("boardIds", boardIds)
		req.Var("groupIds", groupIds)
		return req
	},
	ResponseWrapper[ItemResponse, []Item],
	ResponseUnwrapped[ItemResponse, []Item],
	func(b api.Binding[ItemResponse, []Item], response ItemResponse, args ...any) []Item {
		items := make([]Item, 0)
		for _, board := range response {
			for _, group := range board.Groups {
				for _, item := range group.Items {
					items = append(items, Item{
						Id:           item.Id,
						GroupId:      group.Id,
						BoardId:      board.Id,
						Name:         item.Name,
						ColumnValues: item.ColumnValues,
					})
				}
			}
		}
		return items
	},
	func(binding api.Binding[ItemResponse, []Item]) []api.BindingParam {
		return api.Params("page", 1, "boardIds", []int{}, "groupIds", []string{})
	}, true,
	func(client api.Client) (string, any) { return "jsonResponseKey", "boards" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetItems")

GetItems is a Binding that retrieves multiple Item from the given Board(s) and Group(s). Arguments provided to Binding.Execute:

• page (int): The page of results to retrieve. This means that GetItems can be passed to an api.Paginator.

• boardIds ([]int): The IDs of the Board from which to retrieve all Item from.

• groupIds ([]string): The IDs of the Group from which to retrieve all Item from.

Binding.Execute returns a list of Item instances from the given Board(s) and Group(s).

View Source
var GetUsers = api.NewBinding[[]User, []User](
	func(binding api.Binding[[]User, []User], args ...any) api.Request {
		return NewRequest(`{ users { id name email } }`)
	},
	ResponseWrapper[[]User, []User],
	ResponseUnwrapped[[]User, []User],
	nil, nil, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "users" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("GetUsers")

GetUsers is a Binding to retrieve all User from the linked Monday.com organisation for the API token.

View Source
var Me = api.NewBinding[User, User](
	func(binding api.Binding[User, User], args ...any) (request api.Request) {
		return NewRequest(`{ me { id name email } }`)
	},
	ResponseWrapper[User, User],
	ResponseUnwrapped[User, User],
	nil, nil, false,
	func(client api.Client) (string, any) { return "jsonResponseKey", "me" },
	func(client api.Client) (string, any) { return "config", client.(*Client).Config },
).SetName("Me")

Me is an api.Binding that will retrieve the User bound to the Monday API token used to fetch it.

Functions

func CreateClient

func CreateClient(config Config, opts ...ClientOption)

CreateClient creates and sets the DefaultClient.

func ResponseUnwrapped

func ResponseUnwrapped[ResT any, RetT any](binding api.Binding[ResT, RetT], responseWrapper reflect.Value, args ...any) (response ResT, err error)

func ResponseWrapper

func ResponseWrapper[ResT any, RetT any](binding api.Binding[ResT, RetT], args ...any) (responseWrapper reflect.Value, err error)

Types

type Board

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

func (*Board) ID

func (b *Board) ID() int

type Checkbox

type Checkbox struct {
	C string `json:"checked"`
}

func BuildCheckbox

func BuildCheckbox(checked string) Checkbox

func (Checkbox) Type

func (cb Checkbox) Type() ColumnType

func (Checkbox) Value

func (cb Checkbox) Value() (any, error)

type Client

type Client struct {
	Config Config

	Log func(s string)
	// contains filtered or unexported fields
}

func (*Client) Run

func (c *Client) Run(ctx context.Context, bindingName string, attrs map[string]any, req api.Request, res any) error

type ClientOption

type ClientOption func(*Client)

type Column

type Column struct {
	Id       string     `json:"id"`
	Title    string     `json:"title"`
	Type     ColumnType `json:"type"`         // text, boolean, color, ...
	Settings string     `json:"settings_str"` // used to get label index values for color(status) and dropdown column types
	// contains filtered or unexported fields
}

func (*Column) SettingsMap

func (c *Column) SettingsMap() map[string]any

type ColumnMap

type ColumnMap map[string]Column

ColumnMap is a map of column IDs to Column. To fetch the ColumnMap for a specific board/multiple boards you can use the GetColumnMap Binding.

func (ColumnMap) DecodeValue

func (cm ColumnMap) DecodeValue(columnValue ColumnValue) (Value, error)

type ColumnType

type ColumnType string
const (
	TextType           ColumnType = "text"
	StatusType         ColumnType = "color"
	BooleanType        ColumnType = "boolean"
	DateType           ColumnType = "date"
	TimelineType       ColumnType = "timerange"
	MultiplePersonType ColumnType = "multiple-person"
	DropdownType       ColumnType = "dropdown"
	VotesType          ColumnType = "votes"
)

func (ColumnType) String

func (ct ColumnType) String() string

type ColumnValue

type ColumnValue struct {
	Id    string `json:"id"` // column id
	Title string `json:"title"`
	Value string `json:"value"` // see func DecodeValue below
}

func (ColumnValue) Decode

func (cv ColumnValue) Decode(columnMap ColumnMap) (Value, error)

type Config

type Config interface {
	MondayToken() string
	MondayMappingForModel(model any) MappingConfig
}

type DateTime

type DateTime struct {
	D string `json:"date"`
	T string `json:"time"`
}

func BuildDate

func BuildDate(date string) DateTime

func BuildDateTime

func BuildDateTime(date, time string) DateTime

func (DateTime) Type

func (dt DateTime) Type() ColumnType

func (DateTime) Value

func (dt DateTime) Value() (any, error)
type Dropdown struct {
	Ids []int `json:"ids"`
}
type DropdownMap map[string]DropdownValue
func (dm DropdownMap) Selected() []DropdownValue
type DropdownValue struct {
	Name     string
	Selected bool
}

type Error

type Error struct {
	Code       string         `json:"error_code"`
	StatusCode int            `json:"status_code"`
	Message    string         `json:"error_message"`
	Data       map[string]any `json:"error_data"`
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

type Group

type Group struct {
	Id    string `json:"id"`
	Title string `json:"title"`
}

type Item

type Item struct {
	Id           string
	GroupId      string
	BoardId      string
	Name         string
	ColumnValues []ColumnValue
}

type ItemId

type ItemId struct {
	Id string `json:"id"`
}

type ItemResponse

type ItemResponse []struct {
	Id     string `json:"id"`
	Groups []struct {
		Id    string `json:"id"`
		Items []struct {
			Id           string        `json:"id"`
			Name         string        `json:"name"`
			ColumnValues []ColumnValue `json:"column_values"`
		} `json:"items"`
	} `json:"groups"`
}
type Link struct {
	URL  string `json:"url"`
	Text string `json:"text"`
}
func BuildLink(url, text string) Link

type MappingConfig

type MappingConfig interface {
	MappingModelName() string
	MappingBoardIDs() []int
	MappingGroupIDs() []string
	MappingColumnsToUpdate() []string
	MappingModelInstanceIDColumnID() string
	MappingModelInstanceUpvotesColumnID() string
	MappingModelInstanceDownvotesColumnID() string
	MappingModelInstanceWatchedColumnID() string
	ColumnValues(game any, columnIDs ...string) (columnValues map[string]any, err error)
}

type People

type People struct {
	PersonsAndTeams []PersonTeam `json:"personsAndTeams"`
}

func BuildPeople

func BuildPeople(userIds ...int) People

func (People) Type

func (p People) Type() ColumnType

func (People) Value

func (p People) Value() (any, error)

type PersonTeam

type PersonTeam struct {
	Id   int    `json:"id"`
	Kind string `json:"kind"` // "person" or "team"
}

type Request

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

Request is a GraphQL request.

func NewRequest

func NewRequest(q string) *Request

NewRequest makes a new Request with the specified string.

func (*Request) Header

func (req *Request) Header() *http.Header

func (*Request) Var

func (req *Request) Var(key string, value interface{})

Var sets a variable.

type StatusIndex

type StatusIndex struct {
	Index int `json:"index"`
}

func BuildStatusIndex

func BuildStatusIndex(index int) StatusIndex

type StatusLabel

type StatusLabel struct {
	Label string `json:"label"`
}

func BuildStatusLabel

func BuildStatusLabel(label string) StatusLabel

type Text

type Text string

func (Text) Type

func (t Text) Type() ColumnType

func (Text) Value

func (t Text) Value() (any, error)

type Timeline

type Timeline struct {
	From string `json:"from"`
	To   string `json:"to"`
}

func (Timeline) Type

func (t Timeline) Type() ColumnType

func (Timeline) Value

func (t Timeline) Value() (any, error)

type User

type User struct {
	Id    int    `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

type Value

type Value interface {
	Type() ColumnType
	Value() (any, error)
}

func DecodeLabels

func DecodeLabels(column Column, columnValue ColumnValue) Value

DecodeLabels displays index value of all labels for a column. Uses column settings_str (see GetColumns and Column). Use for Status (color) and Dropdown fields.

func DecodeValue

func DecodeValue(columnMap ColumnMap, columnValue ColumnValue) (value Value, err error)

DecodeValue converts column value returned from Monday to a Value.

color(status) returns index of label chosen, ex. "3"
boolean(checkbox) returns "true" or "false"
date returns "2019-05-22"

Types "multi-person" and "dropdown" may have multiple values. For these, a slice of strings is returned

type Votes

type Votes struct {
	VoterIds  []int  `json:"votersIds"`
	ChangedAt string `json:"changed_at"`
}

func (Votes) Type

func (v Votes) Type() ColumnType

func (Votes) Value

func (v Votes) Value() (any, error)

Jump to

Keyboard shortcuts

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