-
Notifications
You must be signed in to change notification settings - Fork 1
/
assets.go
74 lines (63 loc) · 1.9 KB
/
assets.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
package gontentful
import (
"bytes"
"fmt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
const (
ASSET = "Asset"
DELETED_ASSET = "DeletedAsset"
ASSET_TABLE_NAME = "_asset"
ASSET_DISPLAYFIELD = "title"
IMAGE_FOLDER_NAME = "_images"
)
var (
assetColumns = []string{"title", "description", "file_name", "content_type", "url"}
localizedAssetColumns = map[string]bool{
"title": true,
"description": true,
"file": true,
}
)
type PGSQLAssetTable struct {
Name string
Columns []string
FieldName string
DisplayField string
}
func NewPGSQLAssetTable() *PGSQLAssetTable {
return &PGSQLAssetTable{
Name: ASSET_TABLE_NAME,
Columns: assetColumns,
FieldName: ASSET,
DisplayField: ASSET_DISPLAYFIELD,
}
}
func (a *PGSQLAssetTable) Fields() []map[string]string {
fields := make([]map[string]string, 0)
for _, c := range assetColumns {
fields = append(fields, map[string]string{
"id": c,
"type": "text",
"label": cases.Title(language.Und).String(c),
})
}
return fields
}
type AssetsService service
func (s *AssetsService) Create(body []byte) ([]byte, error) {
path := fmt.Sprintf(pathAssets, s.client.Options.SpaceID, s.client.Options.EnvironmentID)
// Set header for content type
s.client.headers[headerContentType] = "application/vnd.contentful.management.v1+json"
return s.client.post(path, bytes.NewBuffer(body))
}
func (s *AssetsService) Process(id string, locale string) ([]byte, error) {
path := fmt.Sprintf(pathAssetsProcess, s.client.Options.SpaceID, s.client.Options.EnvironmentID, id, locale)
return s.client.put(path, nil)
}
func (s *AssetsService) Publish(id string, version string) ([]byte, error) {
path := fmt.Sprintf(pathAssetsPublished, s.client.Options.SpaceID, s.client.Options.EnvironmentID, id)
s.client.headers[headerContentfulVersion] = version
return s.client.put(path, nil)
}