-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
61 lines (51 loc) · 1.81 KB
/
search.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
package howlongtobeat
import "fmt"
type searchOptions struct {
Games searchOptionsGames `json:"games,required"`
Users searchOptionsUsers `json:"users,required"`
Filter string `json:"filter,required"`
Sort int `json:"sort,required"`
Randomizer int `json:"randomizer,required"`
}
type searchOptionsGames struct {
UserId int `json:"userId,required"`
Platform Platform `json:"platform,required"`
SortCategory SortBy `json:"sortCategory,required"`
RangeCategory string `json:"rangeCategory,required"`
RangeTime searchOptionsGamesRangeTime `json:"rangeTime,required"`
Gameplay searchOptionsGamesGameplay `json:"gameplay,required"`
Modifier Modifier `json:"modifier,required"`
}
type searchOptionsUsers struct {
SortCategory string `json:"sortCategory"`
}
type searchOptionsGamesRangeTime struct {
Min int `json:"min"`
Max int `json:"max"`
}
type searchOptionsGamesGameplay struct {
Perspective Perspective `json:"perspective"`
Flow Flow `json:"flow"`
Genre Genre `json:"genre"`
Difficulty Difficulty `json:"difficulty"`
}
type SearchResult struct {
Color string `json:"color"`
Title string `json:"title"`
Category string `json:"category"`
Count int `json:"count"`
PageCurrent int `json:"pageCurrent"`
PageTotal int `json:"pageTotal"`
PageSize int `json:"pageSize"`
Data []Game `json:"data"`
}
func (c *Client) Search(request SearchRequest) (SearchResult, error) {
if c.searchApiInfosTimedOut() {
c.findApiInfos()
}
result, err := request.send(c.api)
if err != nil {
return SearchResult{}, fmt.Errorf("request failed: %v", err)
}
return result, nil
}