/
ISteamNews.go
53 lines (44 loc) · 1.25 KB
/
ISteamNews.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
package steamapi
import (
"encoding/json"
"net/url"
"strconv"
"github.com/Jleagle/unmarshal-go"
)
func (c Client) GetNews(appID int, limit int) (articles News, err error) {
options := url.Values{}
options.Set("appid", strconv.Itoa(appID))
options.Set("count", strconv.Itoa(limit))
options.Set("maxlength", "0")
b, err := c.getFromAPI("ISteamNews/GetNewsForApp/v2", options, false)
if err != nil {
return articles, err
}
// Unmarshal
var resp NewsResponse
err = json.Unmarshal(b, &resp)
if err != nil {
return articles, err
}
return resp.App, nil
}
type NewsResponse struct {
App News `json:"appnews"`
}
type News struct {
AppID int `json:"appid"`
Items []struct {
GID unmarshal.Int64 `json:"gid"`
Title string `json:"title"`
URL string `json:"url"`
IsExternalURL bool `json:"is_external_url"`
Author string `json:"author"`
Contents string `json:"contents"`
Feedlabel string `json:"feedlabel"`
Date int64 `json:"date"`
FeedName string `json:"feedname"`
FeedType int `json:"feed_type"`
AppID int `json:"appid"`
} `json:"newsitems"`
Count int `json:"count"`
}