mirror of
https://github.com/foomo/contentful.git
synced 2026-06-28 21:40:01 +00:00
feat: tags support
This commit is contained in:
5
asset.go
5
asset.go
@@ -50,8 +50,9 @@ type FileFieldsNoLocale struct {
|
||||
|
||||
// Asset model
|
||||
type Asset struct {
|
||||
Sys *Sys `json:"sys"`
|
||||
Fields *FileFields `json:"fields"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
Sys *Sys `json:"sys"`
|
||||
Fields *FileFields `json:"fields"`
|
||||
}
|
||||
|
||||
// AssetNoLocale model
|
||||
|
||||
@@ -32,6 +32,7 @@ type Contentful struct {
|
||||
ContentTypes *ContentTypesService
|
||||
Entries *EntriesService
|
||||
Locales *LocalesService
|
||||
Tags *TagsService
|
||||
Webhooks *WebhooksService
|
||||
}
|
||||
|
||||
@@ -66,6 +67,7 @@ func NewCMA(token string) *Contentful {
|
||||
c.Assets = &AssetsService{c: c}
|
||||
c.ContentTypes = &ContentTypesService{c: c}
|
||||
c.Entries = &EntriesService{c: c}
|
||||
c.Tags = &TagsService{c: c}
|
||||
c.Locales = &LocalesService{c: c}
|
||||
c.Webhooks = &WebhooksService{c: c}
|
||||
|
||||
@@ -92,6 +94,7 @@ func NewCDA(token string) *Contentful {
|
||||
c.Assets = &AssetsService{c: c}
|
||||
c.ContentTypes = &ContentTypesService{c: c}
|
||||
c.Entries = &EntriesService{c: c}
|
||||
c.Tags = &TagsService{c: c}
|
||||
c.Locales = &LocalesService{c: c}
|
||||
c.Webhooks = &WebhooksService{c: c}
|
||||
|
||||
@@ -116,6 +119,7 @@ func NewCPA(token string) *Contentful {
|
||||
c.Assets = &AssetsService{c: c}
|
||||
c.ContentTypes = &ContentTypesService{c: c}
|
||||
c.Entries = &EntriesService{c: c}
|
||||
c.Tags = &TagsService{c: c}
|
||||
c.Locales = &LocalesService{c: c}
|
||||
c.Webhooks = &WebhooksService{c: c}
|
||||
|
||||
|
||||
5
entry.go
5
entry.go
@@ -15,8 +15,9 @@ type EntriesService service
|
||||
|
||||
// Entry model
|
||||
type Entry struct {
|
||||
Sys *Sys `json:"sys"`
|
||||
Fields map[string]interface{} `json:"fields,omitempty"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
Sys *Sys `json:"sys"`
|
||||
Fields map[string]interface{} `json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
// GetVersion returns entity version
|
||||
|
||||
5
metadata.go
Normal file
5
metadata.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package contentful
|
||||
|
||||
type Metadata struct {
|
||||
Tags []Tag `json:"tags"`
|
||||
}
|
||||
3
query.go
3
query.go
@@ -255,9 +255,6 @@ func (q *Query) Values() url.Values {
|
||||
}
|
||||
params.Set("include", strconv.Itoa(int(q.include)))
|
||||
}
|
||||
if q.include == 0 {
|
||||
params.Set("include", "0")
|
||||
}
|
||||
if q.contentType != "" {
|
||||
params.Set("content_type", q.contentType)
|
||||
}
|
||||
|
||||
56
tag.go
Normal file
56
tag.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package contentful
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// TagsService servıce
|
||||
type TagsService service
|
||||
|
||||
// Tag model
|
||||
type Tag struct {
|
||||
Sys *Sys `json:"sys"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// List returns tags collection
|
||||
func (service *TagsService) List(ctx context.Context, spaceID string) *Collection {
|
||||
path := fmt.Sprintf("/spaces/%s%s/tags", spaceID, getEnvPath(service.c))
|
||||
method := http.MethodGet
|
||||
|
||||
req, err := service.c.newRequest(ctx, method, path, nil, nil)
|
||||
if err != nil {
|
||||
return &Collection{}
|
||||
}
|
||||
|
||||
col := NewCollection(&CollectionOptions{})
|
||||
col.c = service.c
|
||||
col.req = req
|
||||
|
||||
return col
|
||||
}
|
||||
|
||||
// Get returns a single entry
|
||||
func (service *TagsService) Get(ctx context.Context, spaceID, tagID string, locale ...string) (*Tag, error) {
|
||||
path := fmt.Sprintf("/spaces/%s%s/entries/%s", spaceID, getEnvPath(service.c), tagID)
|
||||
query := url.Values{}
|
||||
if len(locale) > 0 {
|
||||
query["locale"] = locale
|
||||
}
|
||||
method := http.MethodGet
|
||||
|
||||
req, err := service.c.newRequest(ctx, method, path, query, nil)
|
||||
if err != nil {
|
||||
return &Tag{}, err
|
||||
}
|
||||
|
||||
var tag Tag
|
||||
if ok := service.c.do(req, &tag); ok != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &tag, err
|
||||
}
|
||||
Reference in New Issue
Block a user