-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontenttypes.go
94 lines (81 loc) · 2.91 KB
/
contenttypes.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
93
94
package gontentful
import (
"bytes"
"encoding/json"
"fmt"
"net/url"
)
const (
CONTENT_TYPE = "ContentType"
DELETED_CONTENT_TYPE = "DeletedContentType"
SCHEMA_TABLE_NAME = "_schema"
)
type ContentTypesService service
func (s *ContentTypesService) Get(query url.Values) ([]byte, error) {
path := fmt.Sprintf(pathContentTypes, s.client.Options.SpaceID, s.client.Options.EnvironmentID)
return s.client.get(path, query)
}
func (s *ContentTypesService) GetTypes() (*ContentTypes, error) {
data, err := s.Get(nil)
if err != nil {
return nil, err
}
res := &ContentTypes{}
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *ContentTypesService) GetSingle(contentTypeId string) ([]byte, error) {
path := fmt.Sprintf(pathContentType, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentTypeId)
return s.client.get(path, nil)
}
func (s *ContentTypesService) Update(contentType string, body []byte, version string) ([]byte, error) {
path := fmt.Sprintf(pathContentType, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentType)
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, bytes.NewBuffer(body))
}
func (s *ContentTypesService) Create(contentType string, body []byte) ([]byte, error) {
path := fmt.Sprintf(pathContentType, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentType)
return s.client.put(path, bytes.NewBuffer(body))
}
func (s *ContentTypesService) Publish(contentType string, version string) ([]byte, error) {
path := fmt.Sprintf(pathContentTypesPublish, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentType)
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, nil)
}
func (s *ContentTypesService) UnPublish(contentType string) ([]byte, error) {
path := fmt.Sprintf(pathContentTypesPublish, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentType)
return s.client.delete(path)
}
func (s *ContentTypesService) Delete(contentType string) ([]byte, error) {
path := fmt.Sprintf(pathContentType, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentType)
return s.client.delete(path)
}
func (s *ContentTypesService) GetSingleCMA(contentTypeId string) (*ContentType, error) {
path := fmt.Sprintf(pathContentType, s.client.Options.SpaceID, s.client.Options.EnvironmentID, contentTypeId)
data, err := s.client.getCMA(path, nil)
if err != nil {
return nil, err
}
res := &ContentType{}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *ContentTypesService) GetCMATypes() (*ContentTypes, error) {
path := fmt.Sprintf(pathContentTypes, s.client.Options.SpaceID, s.client.Options.EnvironmentID)
data, err := s.client.getCMA(path, nil)
if err != nil {
return nil, err
}
res := &ContentTypes{}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}