-
Notifications
You must be signed in to change notification settings - Fork 11
/
recipes.go
63 lines (54 loc) · 1.78 KB
/
recipes.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
package gw2api
import (
"net/url"
"strconv"
)
// Recipe meta object for the recipes
type Recipe struct {
ID int `json:"id"`
Type string `json:"type"`
OutputItemID int `json:"output_item_id"`
OutputItemCount int `json:"output_item_count"`
TimeToCraftMS int `json:"time_to_craft_ms"`
Disciplines []string `json:"disciplines"`
MinRating int `json:"min_rating"`
Flags []string `json:"flags"`
Ingredients []RecipeIngredient `json:"ingredients"`
}
//RecipeIngredient for the ingredient list
type RecipeIngredient struct {
ItemID int `json:"item_id"`
Count int `json:"count"`
}
//Recipes returns list of recipe ids.
func (gw2 *GW2Api) Recipes() (res []int, err error) {
ver := "v2"
tag := "recipes"
err = gw2.fetchEndpoint(ver, tag, nil, &res)
return
}
// RecipeIds returns the details on the requested recipes
func (gw2 *GW2Api) RecipeIds(ids ...int) (recipes []Recipe, err error) {
ver := "v2"
tag := "recipes"
params := url.Values{}
params.Add("ids", commaList(stringSlice(ids)))
err = gw2.fetchEndpoint(ver, tag, params, &recipes)
return
}
func (gw2 *GW2Api) recipesSearch(mode string, n int) (res []int, err error) {
ver := "v2"
tag := "recipes/search"
params := url.Values{}
params.Add(mode, strconv.Itoa(n))
err = gw2.fetchEndpoint(ver, tag, params, &res)
return
}
// RecipeSearchInput searches for recipes which use the input item id
func (gw2 *GW2Api) RecipeSearchInput(input int) ([]int, error) {
return gw2.recipesSearch("input", input)
}
// RecipeSearchOutput searches for recipes which output the item id
func (gw2 *GW2Api) RecipeSearchOutput(output int) ([]int, error) {
return gw2.recipesSearch("output", output)
}