Skip to content

Commit

Permalink
adds support for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
chasecoleman committed Nov 8, 2016
1 parent 9847121 commit dcecb4e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ type CategoryAPIResponse struct {
Category Category `json:"data"`
}

// Tags
type TagsAPIResponse struct {
TagList []Tag `json:"data"`
}

type TagAPIResponse struct {
Tag Tag `json:"data"`
}

// Authors
type AuthorsAPIResponse struct {
AuthorList []Author `json:"data"`
Expand Down
28 changes: 28 additions & 0 deletions buttercms.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,34 @@ func GetCategory(slug string, params map[string]string) (*CategoryAPIResponse, e
return resp, err
}

func GetTags(params map[string]string) (*TagsAPIResponse, error) {
body, err := getRequest("tags", params)
if err != nil {
return nil, err
}

var resp = new(TagsAPIResponse)
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
return resp, err
}

func GetTag(slug string, params map[string]string) (*TagAPIResponse, error) {
body, err := getRequest("tags/"+slug, params)
if err != nil {
return nil, err
}

var resp = new(TagAPIResponse)
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
return resp, err
}

func GetContentFields(keys []string) (*ContentFieldsAPIResponse, error) {
params := map[string]string{"keys": strings.Join(keys, ",")}
body, err := getRequest("content", params)
Expand Down
7 changes: 7 additions & 0 deletions tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ButterCMS

type Tag struct {
Name string `json:"name"`
Slug string `json:"slug"`
RecentPosts []Post `json:"recent_posts"`
}

0 comments on commit dcecb4e

Please sign in to comment.