forked from Philipp15b/go-steamapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices.go
52 lines (45 loc) · 1003 Bytes
/
prices.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
package steamapi
import (
"errors"
"net/url"
"strconv"
)
type storeJson struct {
Result struct {
Success bool
Assets []Asset
}
}
// An item in the store.
type Asset struct {
Prices map[string]int
Defindex int `json:"name,string"`
Date string
Tags []string
TagIds []int64
}
func (i *Asset) HasTag(tag string) bool {
for _, t := range i.Tags {
if t == tag {
return true
}
}
return false
}
var getAssetPrices = NewSteamMethod("ISteamEconomy", "GetAssetPrices", 1)
func (api *Api) GetAssetPrices(appid uint64, language, currency string) ([]Asset, error) {
vals := url.Values{}
vals.Add("key", api.GetApiKey())
vals.Add("appid", strconv.FormatUint(appid, 10))
vals.Add("language", language)
vals.Add("currency", currency)
var resp storeJson
err := getAssetPrices.Request(vals, &resp)
if err != nil {
return nil, err
}
if !resp.Result.Success {
return nil, errors.New("API call 'GetAssetPrices' did not succeed!")
}
return resp.Result.Assets, nil
}