-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
69 lines (60 loc) · 1.69 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package anki
type (
// ModelInput represents a model input.
ModelInput struct {
Model string `json:"modelName"` // Name of the model.
InOrderFields []string `json:"inOrderFields"` // Ordered fields.
CSS string `json:"css"` // Optional CSS, defaults to built in CSS.
CardTemplates []CardTemplateInput `json:"cardTemplates"` // List of card templates.
}
// CardTemplateInput represents a card template input.
CardTemplateInput struct {
Name string `json:"Name"` // Card template name.
Front string `json:"Front"` // Card front template.
Back string `json:"Back"` // Card back template.
}
)
// Models returns the list of model names for the current user.
func (c *Client) Models() ([]string, error) {
var res []string
if err := c.sendRequest(
ankiRequest{
Action: "modelNames",
Version: c.minVersion,
}, &res); err != nil {
return nil, err
}
return res, nil
}
// Gets the complete list of field names for the provided model name.
func (c *Client) ModelFieldNames(modelName string) ([]string, error) {
var res []string
if err := c.sendRequest(
ankiRequest{
Action: "modelFieldNames",
Version: c.minVersion,
Params: map[string]interface{}{
"modelName": modelName,
},
}, &res); err != nil {
return nil, err
}
return res, nil
}
// CreateModel creates a new model.
func (c *Client) CreateModel(model ModelInput) error {
var res interface{}
if err := c.sendRequest(
ankiRequest{
Action: "createModel",
Version: c.minVersion,
Params: model,
}, &res); err != nil {
return err
}
return nil
}
type createModelRequest struct {
ankiRequest
Params ModelInput `json:"params"`
}