Update to OW2
This commit is contained in:
5
go.mod
5
go.mod
@ -2,8 +2,6 @@ module git.meow.tf/ow-api/ow-api
|
||||
|
||||
go 1.19
|
||||
|
||||
replace github.com/s32x/ovrstat => github.com/1RV34/ovrstat v0.0.0-20220807115213-81427894fccd
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.8.0
|
||||
github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833
|
||||
@ -11,8 +9,8 @@ require (
|
||||
github.com/go-redis/redis v6.15.6+incompatible
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/miekg/dns v1.1.26
|
||||
github.com/ow-api/ovrstat v0.0.0-20221214025448-fafff9caacf4
|
||||
github.com/rs/cors v1.7.0
|
||||
github.com/s32x/ovrstat v0.0.0-20211111235940-13d1a9594882
|
||||
github.com/stoewer/go-strcase v1.2.0
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
|
||||
)
|
||||
@ -23,6 +21,7 @@ require (
|
||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||
github.com/onsi/gomega v1.20.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
|
||||
|
||||
9
go.sum
9
go.sum
@ -1,5 +1,3 @@
|
||||
github.com/1RV34/ovrstat v0.0.0-20220807115213-81427894fccd h1:Y1wOdUR7RyMPzfVKzkAxziOCQuBlXPnjUCpM83me31c=
|
||||
github.com/1RV34/ovrstat v0.0.0-20220807115213-81427894fccd/go.mod h1:uVFCv2DWlcRsF0hXdM4hS/Wpu7qwo+d0GVMWDsmblJs=
|
||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
@ -46,6 +44,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q=
|
||||
github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
|
||||
github.com/ow-api/ovrstat v0.0.0-20221214025448-fafff9caacf4 h1:f+vlTFtbl5+Ft4UycjLSYwwVrf9HY0NrOGPbu8xSqu4=
|
||||
github.com/ow-api/ovrstat v0.0.0-20221214025448-fafff9caacf4/go.mod h1:tQqYdSdfFHIW4JYBZV78Bj/lQyWfq28WlZ9KLMr1cyk=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@ -55,8 +55,9 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
@ -119,6 +120,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
54
main.go
54
main.go
@ -2,15 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.meow.tf/ow-api/ow-api/cache"
|
||||
"git.meow.tf/ow-api/ow-api/json-patch"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/ow-api/ovrstat/ovrstat"
|
||||
"github.com/rs/cors"
|
||||
"github.com/s32x/ovrstat/ovrstat"
|
||||
"github.com/stoewer/go-strcase"
|
||||
"golang.org/x/net/context"
|
||||
"log"
|
||||
@ -61,7 +60,7 @@ var (
|
||||
|
||||
heroNames []string
|
||||
|
||||
platforms = []string{ovrstat.PlatformPC, ovrstat.PlatformXBL, ovrstat.PlatformPSN, ovrstat.PlatformNS}
|
||||
platforms = []string{ovrstat.PlatformPC, ovrstat.PlatformConsole}
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -175,6 +174,10 @@ var (
|
||||
|
||||
func injectPlatform(platform string, handler httprouter.Handle) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if platform == "psn" || platform == "xbl" || platform == "nintendo-switch" {
|
||||
platform = ovrstat.PlatformConsole
|
||||
}
|
||||
|
||||
ps = append(ps, httprouter.Param{Key: "platform", Value: platform})
|
||||
|
||||
ctx := context.Background()
|
||||
@ -220,18 +223,7 @@ func statsResponse(w http.ResponseWriter, r *http.Request, ps httprouter.Params,
|
||||
|
||||
platform := ps.ByName("platform")
|
||||
|
||||
switch platform {
|
||||
case ovrstat.PlatformPC:
|
||||
if !tagRegexp.MatchString(tag) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return nil, errors.New("bad tag")
|
||||
}
|
||||
stats, err = ovrstat.PCStats(tag)
|
||||
case ovrstat.PlatformPSN, ovrstat.PlatformXBL, ovrstat.PlatformNS:
|
||||
stats, err = ovrstat.ConsoleStats(platform, tag)
|
||||
default:
|
||||
return nil, errors.New("unknown platform")
|
||||
}
|
||||
stats, err = ovrstat.Stats(platform, tag)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -305,20 +297,6 @@ func statsResponse(w http.ResponseWriter, r *http.Request, ps httprouter.Params,
|
||||
var ratingIcon string
|
||||
|
||||
if len(stats.Ratings) > 0 {
|
||||
totalRating := 0
|
||||
iconUrl := ""
|
||||
|
||||
for _, rating := range stats.Ratings {
|
||||
totalRating += rating.Level
|
||||
iconUrl = rating.RankIcon
|
||||
}
|
||||
|
||||
rating = totalRating / len(stats.Ratings)
|
||||
|
||||
urlBase := iconUrl[0 : strings.Index(iconUrl, "rank-icons/")+11]
|
||||
|
||||
ratingIcon = urlBase + iconFor(rating)
|
||||
|
||||
if version == VersionThree {
|
||||
m := make(map[string]ovrstat.Rating)
|
||||
|
||||
@ -388,24 +366,6 @@ func statsResponse(w http.ResponseWriter, r *http.Request, ps httprouter.Params,
|
||||
return b, err
|
||||
}
|
||||
|
||||
func iconFor(rating int) string {
|
||||
if rating >= 4000 {
|
||||
return "rank-GrandmasterTier.png"
|
||||
} else if rating >= 3500 {
|
||||
return "rank-MasterTier.png"
|
||||
} else if rating >= 3000 {
|
||||
return "rank-DiamondTier.png"
|
||||
} else if rating >= 2500 {
|
||||
return "rank-PlatinumTier.png"
|
||||
} else if rating >= 2000 {
|
||||
return "rank-GoldTier.png"
|
||||
} else if rating >= 1500 {
|
||||
return "rank-SilverTier.png"
|
||||
}
|
||||
|
||||
return "rank-BronzeTier.png"
|
||||
}
|
||||
|
||||
func generateCacheKey(r *http.Request, ps httprouter.Params) string {
|
||||
version := VersionOne
|
||||
|
||||
|
||||
@ -2,12 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/s32x/ovrstat/ovrstat"
|
||||
"github.com/ow-api/ovrstat/ovrstat"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Stats(t *testing.T) {
|
||||
stats, err := ovrstat.PCStats("cats-11481")
|
||||
stats, err := ovrstat.Stats(ovrstat.PlatformPC, "cats-11481")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/s32x/ovrstat/ovrstat"
|
||||
"github.com/ow-api/ovrstat/ovrstat"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
@ -99,13 +99,13 @@ func main() {
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
stats, err := ovrstat.PCStats("cats-11481")
|
||||
stats, err := ovrstat.Stats(ovrstat.PlatformPC, "cats-11481")
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Error retrieving:", err)
|
||||
}
|
||||
|
||||
log.Println(stats.Name+" is level", stats.Level)
|
||||
log.Println(stats.Name+" is level", stats.Endorsement)
|
||||
}
|
||||
|
||||
func lookupCloudfrontURL() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user