-
Notifications
You must be signed in to change notification settings - Fork 1
/
category.go
62 lines (55 loc) · 1.36 KB
/
category.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
package brewerydb
import (
"fmt"
"net/http"
)
// CategoryService provides access to the BreweryDB Category API. Use Client.Category.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/category_index
type CategoryService struct {
c *Client
}
// Category represents a type of Beer as specified by the Brewers Association
// Style Guidelines.
type Category struct {
ID int
Name string
Description string
CreateDate string
UpdateDate string
}
// List returns all possible Beer Categories.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/category_index#1
func (cs *CategoryService) List() ([]Category, error) {
// GET: /categories
req, err := cs.c.NewRequest("GET", "/categories", nil)
if err != nil {
return nil, err
}
resp := struct {
Status string
Data []Category
Message string
}{}
err = cs.c.Do(req, &resp)
return resp.Data, err
}
// Get obtains the Category with the given Category ID.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/category_index#2
func (cs *CategoryService) Get(id int) (cat Category, err error) {
// GET: /category/:categoryId
var req *http.Request
req, err = cs.c.NewRequest("GET", fmt.Sprintf("/category/%d", id), nil)
if err != nil {
return
}
resp := struct {
Status string
Data Category
Message string
}{}
err = cs.c.Do(req, &resp)
return resp.Data, err
}