-
Notifications
You must be signed in to change notification settings - Fork 2
/
store.go
276 lines (237 loc) · 9.56 KB
/
store.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package kettle
import (
"errors"
"net/http"
"strconv"
"encoding/json"
"github.com/dghubble/sling"
)
// StoreService provides a method for accessing Steam store endpoints
type StoreService struct {
sling *sling.Sling
}
func newStoreService(sling *sling.Sling) *StoreService {
return &StoreService{
sling: sling,
}
}
type appDetails struct {
Success bool `json:"success"`
AppData AppData `json:"data"`
}
// AppData holds the data for StoreService.AppDetails
// https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appdetails
type AppData struct {
Type string `json:"type"`
Name string `json:"name"`
SteamAppID int64 `json:"steam_appid"`
RequiredAge interface{} `json:"required_age"` // Can be string or int
IsFree bool `json:"is_free"`
ControllerSupport string `json:"controller_support"`
Dlc []int64 `json:"dlc,omitempty"`
DetailedDescription string `json:"detailed_description"`
AboutTheGame string `json:"about_the_game"`
ShortDescription string `json:"short_description"`
SupportedLanguages string `json:"supported_languages"`
Reviews string `json:"reviews"`
HeaderImage string `json:"header_image"`
Website string `json:"website"`
PCRequirements json.RawMessage `json:"pc_requirements,omitempty"`
MacRequirements json.RawMessage `json:"mac_requirements,omitempty"`
LinuxRequirements json.RawMessage `json:"linux_requirements,omitempty"`
LegalNotice string `json:"legal_notice"`
Developers []string `json:"developers"`
Publishers []string `json:"publishers"`
PriceOverview Price `json:"price_overview"`
Packages json.RawMessage `json:"packages"` // Can be an array of strings or ints
PackageGroups []PackageGroup `json:"package_groups"`
Platforms Platform `json:"platforms"`
MetaCritic MetaCritic `json:"metacritic,omitempty"`
Categories []Category `json:"categories"`
Genres []Genre `json:"genres"`
Screenshots []Screenshot `json:"screenshots"`
Movies []Movie `json:"movies"`
Recomendations Recomendations `json:"recommendations"`
Achievements Achievements `json:"achievements"`
ReleaseDate ReleaseDate `json:"release_date"`
SupportInfo SupportInfo `json:"support_info"`
Background string `json:"background"`
}
// Requirements is possibly used for pc/mac/linux requirements. If it's empty
// it will be an empty array so you will need to cast this yourself.
type Requirements struct {
Minimum string `json:"minimum"`
Recommended string `json:"recommended"`
}
// Price holds the current and sale price for an app
type Price struct {
Currency string `json:"currency"`
Initial int `json:"initial"`
Final int `json:"final"`
DiscountPercent int `json:"discount_percent"`
}
// PackageGroup are the packages the app is part of
type PackageGroup struct {
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
SelectionText string `json:"selection_text"`
SaveText string `json:"save_text"`
DisplayType interface{} `json:"display_type"` //This can be a string or number
IsRecurringSubscription string `json:"is_recurring_subscription"`
Subs []Sub `json:"subs"`
}
// Sub is part of the PackageGroup, details about a package
type Sub struct {
PackageID json.RawMessage `json:"packageid"` // This could be a string or int64
PercentSavingsText string `json:"percent_savings_text"`
PercentSavings int `json:"percent_savings"`
OptionText string `json:"option_text"`
OptionDescription string `json:"option_description"`
CanGetFreeLicense string `json:"can_get_free_license"`
IsFreeLicense bool `json:"is_free_license"`
PriceInCentsWithDiscount int `json:"price_in_cents_with_discount"`
}
// Platform lists what platforms this app works on
type Platform struct {
Windows bool `json:"windows"`
Mac bool `json:"mac"`
Linux bool `json:"linux"`
}
// MetaCritic information about the app
type MetaCritic struct {
Score int `json:"score"`
URL string `json:"url"`
}
// Category associated to an AppData
type Category struct {
ID int `json:"id"`
Description string `json:"description"`
}
// Genre associated with an AppData
type Genre struct {
ID string `json:"id"`
Description string `json:"description"`
}
// Screenshot is a screenshot of an app
type Screenshot struct {
ID int `json:"id"`
PathThumbnail string `json:"path_thumbnail"`
PathFull string `json:"path_full"`
}
// Movie are trailers and videos associated with AppData
type Movie struct {
ID int `json:"id"`
Name string `json:"name"`
Thumbnail string `json:"thumbnail"`
Webm Webm `json:"webm"`
Highlight bool `json:"highlight"`
}
// Webm are links to the different quality level of a Movie
type Webm struct {
Low string `json:"480"`
Max string `json:"max"`
}
// Recomendations are how many people recommended the app
type Recomendations struct {
Total int64 `json:"total"`
}
// Achievements are the achievements associated with AppData
type Achievements struct {
Total int `json:"total"`
Highlighted []HighlightedAchivement `json:"highlighted"`
}
// HighlightedAchivement are name/photo of achievements on an App
type HighlightedAchivement struct {
Name string `json:"name"`
Path string `json:"path"`
}
// ReleaseDate is the release date for an app
type ReleaseDate struct {
ComingSoon bool `json:"coming_soon"`
Date string `json:"date"`
}
// SupportInfo holds contact info for support for an app
type SupportInfo struct {
URL string `json:"url"`
Email string `json:"email"`
}
// AppDetails gets detailed information about a game
// Not supported: multiple appids with &filters=price_overview
// https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appdetails
func (s *StoreService) AppDetails(id int64) (*AppData, *http.Response, error) {
response := make(map[string]appDetails)
resp, err := s.sling.New().Path("api/appdetails").QueryStruct(struct {
AppIDs int64 `url:"appids"`
}{
AppIDs: id,
}).Receive(&response, &response)
i := strconv.FormatInt(id, 10)
a := response[i].AppData
if !response[i].Success && err == nil {
err = errors.New("API request failed with Success = false")
}
return &a, resp, err
}
type AppReview struct {
Success int `json:"success"`
QuerySummary QuerySummary `json:"query_summary"`
Reviews []Review `json:"reviews"`
}
type QuerySummary struct {
NumberReviews int `json:"num_reviews"`
ReviewScore int `json:"review_score"`
ReviewScoreDescription string `json:"review_score_desc"`
TotalPositive int `json:"total_positive"`
TotalNegative int `json:"total_negative"`
TotalReviews int `json:"total_reviews"`
}
type Review struct {
ID string `json:"recommendationid"`
Author Author `json:"author"`
Language string `json:"language"`
Review string `json:"review"`
TimeCreated int64 `json:"timestamp_created"`
TimeUpdated int64 `json:"timestamp_updated"`
VotedUp bool `json:"voted_up"`
VotesUp int `json:"votes_up"`
VotesDown int `json:"votes_down"`
VotesFunny int `json:"votes_funny"`
WeightedVoteScore string `json:"weighted_vote_score"`
CommentCount json.RawMessage `json:"comment_count"` // if < 1 string if == 0 int
SteamPurchase bool `json:"steam_purchase"`
ReceivedForFree bool `json:"received_for_free"`
EarlyAccess bool `json:"written_during_early_access"`
}
type Author struct {
UserID string `json:"steamid"`
NumberGamesOwned int `json:"num_games_owned"`
NumberReviews int `json:"num_reviews"`
PlayTimeForever int `json:"playtime_forever"`
PlaytimeLastTwoWeeks int `json:"playtime_last_two_weeks"`
LastPlayed int64 `json:"last_played"`
}
// AppReviewsParams are the parameters for Store.AppReviews
// https://partner.steamgames.com/doc/store/getreviews
type AppReviewsParams struct {
JSON int `url:"json"`
AppID int64
Filter string `url:"filter,omitempty"`
Language string `url:"language,omitempty"`
DayRange string `url:"day_range,omitempty"`
StartOffset string `url:"start_offset,omitempty"`
ReviewType string `url:"review_type,omitempty"`
PurchaseType string `url:"purchase_type,omitempty"`
}
// AppReviews gets review data for a game
// https://partner.steamgames.com/doc/store/reviews
func (s *StoreService) AppReviews(params *AppReviewsParams) (*AppReview, *http.Response, error) {
response := new(AppReview)
stringID := strconv.FormatInt(params.AppID, 10)
params.JSON = 1
resp, err := s.sling.New().Path("appreviews/" + stringID).QueryStruct(params).ReceiveSuccess(response)
if response.Success == 0 {
err = errors.New("API request for reviews failed with Success = 0")
}
return response, resp, err
}