forked from ohookins/contentful-go
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from foomo/feature/tags
tags support
- Loading branch information
Showing
6 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package contentful | ||
|
||
type Metadata struct { | ||
Tags []Tag `json:"tags"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |