-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
82 lines (73 loc) · 2.17 KB
/
client.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type apiResponse struct {
NextChangeId string `json:"next_change_id"`
Stashes []stash `json:"stashes"`
}
type stash struct {
AccountName string `json:"accountName"`
LastCharacterName string `json:"lastCharacterName"`
Id string `json:"id"`
StashName string `json:"stash"`
StashType string `json:"stashType"`
Items []stashItem `json:"items"`
PublicStash bool `json:"public"`
}
type stashItem struct {
Id string `json:"id"`
League string `json:"league"`
FrameType int `json:"frameType"` // 3=unique, 5=currency, 6=divcard
Note string `json:"note,omitempty"` // Price
Name string `json:"name"`
TypeLine string `json:"typeLine"`
EnchantMods []string `json:"enchantMods,omitempty"`
ImplicitMods []string `json:"implicitMods,omitempty"`
ExplicitMods []string `json:"explicitMods,omitempty"`
CraftedMods []string `json:"craftedMods,omitempty"`
Elder bool `json:"elder,omitempty"`
Shaper bool `json:"shaper,omitempty"`
Veiled bool `json:"veiled,omitempty"`
Corrupted bool `json:"corrupted,omitempty"`
Ilvl int `json:"ilvl"`
StackSize int `json:"stackSize"`
MaxStackSize int `json:"maxStackSize"`
}
func apiGet(lastChangeId string) *apiResponse {
resp, err := http.Get("http://api.pathofexile.com/public-stash-tabs?id=" + lastChangeId)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
var apiRes apiResponse
err = json.Unmarshal(body, &apiRes)
if err != nil {
log.Fatal(err)
}
return &apiRes
}
func findItemsByCategoryAndLeague(tab stash, categories []int, league string) []stashItem {
var stashItems []stashItem
for _, item := range tab.Items {
if item.League != league {
continue
}
for _, category := range categories {
if category == item.FrameType {
if item.Note == "" {
item.Note = tab.StashName
}
stashItems = append(stashItems, item)
}
}
}
return stashItems
}