forked from contentful-labs/contentful-go
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheditor_interface.go
92 lines (74 loc) · 2.38 KB
/
editor_interface.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package contentful
import (
"bytes"
"encoding/json"
"fmt"
"net/url"
)
// EditorInterfacesService service
type EditorInterfacesService service
// EditorInterface model
type EditorInterface struct {
Sys *Sys `json:"sys"`
Controls []Controls `json:"controls"`
SideBar []Sidebar `json:"sidebar"`
}
// Controls model
type Controls struct {
FieldID string `json:"fieldId"`
WidgetNameSpace string `json:"widgetNamespace"`
WidgetID string `json:"widgetId"`
Settings map[string]string `json:"settings,omitempty"`
}
// Sidebar model
type Sidebar struct {
WidgetNameSpace string `json:"widgetNamespace"`
WidgetID string `json:"widgetId"`
Settings map[string]string `json:"settings,omitempty"`
Disabled bool `json:"disabled"`
}
// List returns an EditorInterface collection
func (service *EditorInterfacesService) List(spaceID string) *Collection {
path := fmt.Sprintf("/spaces/%s/environments/%s/editor_interface", spaceID, service.c.Environment)
req, err := service.c.newRequest("GET", path, nil, nil)
if err != nil {
return &Collection{}
}
col := NewCollection(&CollectionOptions{})
col.c = service.c
col.req = req
return col
}
// Get returns a single EditorInterface
func (service *EditorInterfacesService) Get(spaceID, contentTypeID string) (*EditorInterface, error) {
path := fmt.Sprintf("/spaces/%s/environments/%s/content_types/%s/editor_interface", spaceID, service.c.Environment, contentTypeID)
query := url.Values{}
method := "GET"
req, err := service.c.newRequest(method, path, query, nil)
if err != nil {
return &EditorInterface{}, err
}
var editorInterface EditorInterface
if ok := service.c.do(req, &editorInterface); ok != nil {
return nil, err
}
return &editorInterface, err
}
// Update updates an editor interface
func (service *EditorInterfacesService) Update(spaceID, contentTypeID string, e *EditorInterface) error {
bytesArray, err := json.Marshal(e)
if err != nil {
return err
}
var path string
var method string
if contentTypeID != "" {
path = fmt.Sprintf("/spaces/%s/environments/%s/content_types/%s/editor_interface", spaceID, service.c.Environment, contentTypeID)
method = "PUT"
}
req, err := service.c.newRequest(method, path, nil, bytes.NewReader(bytesArray))
if err != nil {
return err
}
return service.c.do(req, e)
}