-
Notifications
You must be signed in to change notification settings - Fork 1
/
fermentable.go
99 lines (90 loc) · 2.49 KB
/
fermentable.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
98
99
package brewerydb
import (
"fmt"
"net/http"
)
// FermentableService provides access to the BreweryDB Fermentable API.
// Use Client.Fermentable.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/fermentable_index
type FermentableService struct {
c *Client
}
// Characteristic represents a descriptive characteristic of a Fermentable.
type Characteristic struct {
ID int
Name string
Description string
CreateDate string
UpdateDate string
}
// Fermentable represents a Fermentable Beer ingredient.
type Fermentable struct {
ID int
Name string
Description string
CountryOfOrigin string
SrmID int
SrmPrecise float64
MoistureContent float64
CoarseFineDifference float64
DiastaticPower float64
DryYield float64
Potential float64
Protein float64
SolubleNitrogenRatio float64
MaxInBatch float64
RequiresMashing YesNo
Category string // This will always be set to "malt"
CategoryDisplay string // This will always be set to "Malts, Grains, & Fermentables"
CreateDate string
UpdateDate string
SRM SRM
Country struct {
IsoCode string
Name string
DisplayName string
IsoThree string
NumberCode int
CreateDate string
}
Characteristics []Characteristic
}
// FermentableList represents a "page" containing a slice of Fermentables.
type FermentableList struct {
CurrentPage int
NumberOfPages int
TotalResults int
Fermentables []Fermentable `json:"data"`
}
// List returns a list of Fermentable Beer ingredients.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/fermentable_index#1
func (fs *FermentableService) List(page int) (fl FermentableList, err error) {
// GET: /fermentables
var req *http.Request
req, err = fs.c.NewRequest("GET", "/fermentables", &Page{page})
if err != nil {
return
}
err = fs.c.Do(req, &fl)
return
}
// Get returns the Fermentable with the given Fermentable ID.
//
// See: http://www.brewerydb.com/developers/docs-endpoint/fermentable_index#2
func (fs *FermentableService) Get(id int) (f Fermentable, err error) {
// GET: /fermentable/:fermentableID
var req *http.Request
req, err = fs.c.NewRequest("GET", fmt.Sprintf("/fermentable/%d", id), nil)
if err != nil {
return
}
resp := struct {
Status string
Data Fermentable
Message string
}{}
err = fs.c.Do(req, &resp)
return resp.Data, err
}