-
Notifications
You must be signed in to change notification settings - Fork 1
/
entries.go
87 lines (74 loc) · 2.92 KB
/
entries.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
package gontentful
import (
"bytes"
"encoding/json"
"fmt"
"net/url"
)
const (
ENTRY = "Entry"
DELETED_ENTRY = "DeletedEntry"
)
type EntriesService service
func (s *EntriesService) Get(query url.Values) ([]byte, error) {
path := fmt.Sprintf(pathEntries, s.client.Options.SpaceID, s.client.Options.EnvironmentID)
return s.client.get(path, query)
}
func (s *EntriesService) GetEntries(query url.Values) (*Entries, error) {
data, err := s.Get(query)
if err != nil {
return nil, err
}
res := &Entries{}
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
func (s *EntriesService) GetSingle(entryId string) ([]byte, error) {
path := fmt.Sprintf(pathEntry, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
return s.client.get(path, nil)
}
func (s *EntriesService) Create(contentType string, body []byte) ([]byte, error) {
path := fmt.Sprintf(pathEntries, s.client.Options.SpaceID, s.client.Options.EnvironmentID)
// Set header for content type
s.client.headers[headerContentfulContentType] = contentType
return s.client.post(path, bytes.NewBuffer(body))
}
func (s *EntriesService) Update(version string, entryId string, body []byte) ([]byte, error) {
path := fmt.Sprintf(pathEntry, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for content type
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, bytes.NewBuffer(body))
}
func (s *EntriesService) Publish(entryId string, version string) ([]byte, error) {
path := fmt.Sprintf(pathEntriesPublish, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for version
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, nil)
}
func (s *EntriesService) UnPublish(entryId string, version string) ([]byte, error) {
path := fmt.Sprintf(pathEntriesPublish, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for version
s.client.headers[headerContentfulVersion] = version
return s.client.delete(path)
}
func (s *EntriesService) Delete(entryId string, version string) ([]byte, error) {
path := fmt.Sprintf(pathEntry, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for version
s.client.headers[headerContentfulVersion] = version
return s.client.delete(path)
}
func (s *EntriesService) Archive(entryId string, version string) ([]byte, error) {
path := fmt.Sprintf(pathEntriesArchive, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for version
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, nil)
}
func (s *EntriesService) UnArchive(entryId string, version string) ([]byte, error) {
path := fmt.Sprintf(pathEntriesArchive, s.client.Options.SpaceID, s.client.Options.EnvironmentID, entryId)
// Set header for version
s.client.headers[headerContentfulVersion] = version
return s.client.delete(path)
}