-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeature.go
97 lines (86 loc) · 2.3 KB
/
feature.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package brewerydb
import (
"fmt"
"net/http"
)
// FeatureService provides access to the BreweryDB Feature API. Use Client.Feature.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/feature_index
type FeatureService struct {
c *Client
}
// Feature represents a combined Featured Beer and Brewery.
// TODO: the Brewery in a Feature should ALSO contain its locations:
type Feature struct {
ID int
Year int
Week int
BeerID string
Beer Beer
BreweryID string
Brewery Brewery
}
// Get returns this week's Featured Beer and Brewery.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/feature_index#1
func (fs *FeatureService) Get() (f Feature, err error) {
// GET: /featured
var req *http.Request
req, err = fs.c.NewRequest("GET", "/featured", nil)
if err != nil {
return
}
resp := struct {
Status string
Data Feature
Message string
}{}
err = fs.c.Do(req, &resp)
return resp.Data, err
}
// FeatureListRequest contains options for querying for a list of features.
type FeatureListRequest struct {
Page int `url:"p"`
Year int `url:"year,omitempty"`
Week int `url:"week,omitempty"`
IgnoreFuture string `url:"ignoreFuture,omitempty"` // Y or N
}
// FeatureList represents a single "page" containing a slice of Features.
type FeatureList struct {
CurrentPage int
NumberOfPages int
TotalResults int
Features []Feature `json:"data"`
}
// List returns all Featured Beers and Breweries.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/feature_index#2
func (fs *FeatureService) List(q *FeatureListRequest) (fl FeatureList, err error) {
// GET: /features
var req *http.Request
req, err = fs.c.NewRequest("GET", "/features", q)
if err != nil {
return
}
err = fs.c.Do(req, &fl)
return
}
// ByWeek returns the Featured Beer and Brewery for the given
// year and week number.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/feature_index#3
func (fs *FeatureService) ByWeek(year, week int) (f Feature, err error) {
// GET: /feature/:year-week
var req *http.Request
req, err = fs.c.NewRequest("GET", fmt.Sprintf("/feature/%4d-%02d", year, week), nil)
if err != nil {
return
}
resp := struct {
Status string
Data Feature
Message string
}{}
err = fs.c.Do(req, &resp)
return resp.Data, err
}