-
Notifications
You must be signed in to change notification settings - Fork 1
/
change.go
82 lines (70 loc) · 2.14 KB
/
change.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
package brewerydb
import "net/http"
// ChangeService provides access to the BreweryDB Change API.
// Use Client.Change.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/change_index
type ChangeService struct {
c *Client
}
// ChangeType represents a type of attribute changed in BreweryDB.
type ChangeType string
// ChangeTypes available.
const (
ChangeBeer ChangeType = "beer"
ChangeBrewery = "brewery"
ChangeEvent = "event"
ChangeGuild = "guild"
ChangeLocation = "location"
)
// ChangeAction represents the type of change made to an attribute.
type ChangeAction string
// ChangeActions available.
const (
ChangeAdd ChangeAction = "add"
ChangeDelete = "delete"
ChangeEdit = "edit"
)
// ChangeListRequest contains parameters for obtaining a list of BreweryDB changes.
type ChangeListRequest struct {
Page int `url:"p,omitempty"`
AttributeName ChangeType `url:"attributeName,omitempty"`
AttributeID string `url:"attributeId,omitempty"`
Since string `url:"since,omitempty"`
}
// Attribute is a generic object that contains the ID and Name of either a
// Beer, Brewery, Event, Guild, or Location.
type Attribute struct {
ID string
Name string
}
// Change contains all the relevant information for an individual change in BreweryDB.
type Change struct {
AttributeName ChangeType
Action ChangeAction
Attribute Attribute
SubAttributeName ChangeType
SubAction ChangeAction
SubAttribute Attribute
}
// ChangeList represents one "page" containing a slice of Changes.
type ChangeList struct {
CurrentPage int
NumberOfPages int
TotalResults int
Changes []Change `json:"data"`
}
// List retrieves (by default) a paginated list of all Changes to BreweryDB
// in the last 30 days.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/change_index#1
func (cs *ChangeService) List(q *ChangeListRequest) (cl ChangeList, err error) {
// GET: /changes
var req *http.Request
req, err = cs.c.NewRequest("GET", "/changes", q)
if err != nil {
return
}
err = cs.c.Do(req, &cl)
return
}