gomochi

package
v0.0.0-...-1db218e Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIBase = "https://app.mochi.cards/api/"

	PathCard = "/cards"
	PathDeck = "/decks"
)

Variables

This section is empty.

Functions

func LoadTemplateConfig

func LoadTemplateConfig(file string) error

Types

type Card

type Card struct {
	ID             string               `json:"id,omitempty"`
	Content        string               `json:"content"`
	DeckID         string               `json:"deck-id"`
	TemplateID     string               `json:"template-id,omitempty"`
	Fields         map[string]CardField `json:"fields,omitempty"`
	Archived       bool                 `json:"archived?"`
	ReviewReversed bool                 `json:"review-reverse?"`
	Position       string               `json:"pos,omitempty"`
}

func (*Card) AddField

func (c *Card) AddField(id, value string)

func (*Card) SetTemplate

func (c *Card) SetTemplate(id string)

type CardField

type CardField struct {
	ID    string `json:"id"`
	Value string `json:"value"`
}

type Client

type Client struct {
	HTTPClient *http.Client `json:"-"`
	APIBase    string       `json:"api_base"`

	APIKey    string             `json:"-"`
	Templates *TemplateConfigSet `json:"templates"`
	Debug     bool               `json:"debug"`
	Noop      bool               `json:"noop"`
}

func (*Client) GetCard

func (c *Client) GetCard(id string) (*Card, error)

func (*Client) Request

func (c *Client) Request(apiPath string, method string, body any, response any) error

Request makes the request against the mochi api.

WARNING: This method is Private API, it may change at any point, and is only exposed as an escape hatch.

- body: if included it will encode it as JSON and send it as the body of the request. - response: if set the response will be JSON decoded into the response

type FieldConfig

type FieldConfig struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type TemplateConfig

type TemplateConfig struct {
	ID     string         `json:"id"`
	Name   string         `json:"name"`
	Fields []*FieldConfig `json:"fields"`
}

func (*TemplateConfig) Get

func (t *TemplateConfig) Get(name string) *FieldConfig

Get will get the field with the requested name. Returns nil if not found.

This is safe to call if TemplateConfig is nil, which allows easily chain requests without constantly nil check.

type TemplateConfigSet

type TemplateConfigSet struct {
	Templates map[string]*TemplateConfig `json:"templates"`
}

func (*TemplateConfigSet) Get

func (set *TemplateConfigSet) Get(name string) *TemplateConfig

Get looks for the requested template. If it isn't found it will return nil.

Jump to

Keyboard shortcuts

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