diff --git a/asset.go b/asset.go index f37c37e..c988aa4 100644 --- a/asset.go +++ b/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 diff --git a/contentful.go b/contentful.go index 0113c39..96c7e41 100644 --- a/contentful.go +++ b/contentful.go @@ -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} diff --git a/entry.go b/entry.go index 8731645..5b8feef 100644 --- a/entry.go +++ b/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 diff --git a/metadata.go b/metadata.go new file mode 100644 index 0000000..3c0ee40 --- /dev/null +++ b/metadata.go @@ -0,0 +1,5 @@ +package contentful + +type Metadata struct { + Tags []Tag `json:"tags"` +} diff --git a/query.go b/query.go index 37c839e..9f056ed 100644 --- a/query.go +++ b/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) } diff --git a/tag.go b/tag.go new file mode 100644 index 0000000..8537cd5 --- /dev/null +++ b/tag.go @@ -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 +}