diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63abe34..32e2efd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,4 +27,4 @@ jobs: - uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.txt + file: ./coverage.txt \ No newline at end of file diff --git a/README.md b/README.md index da0368f..28cc6c8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![codecov](https://codecov.io/gh/KnutZuidema/golio/branch/master/graph/badge.svg)](https://codecov.io/gh/KnutZuidema/golio) # Golio - + Golio is a wrapper for the Riot API and the Data Dragon service. It is written purely in Go and provides idiomatic access to all API endpoints. @@ -19,7 +19,7 @@ import ( "net/http" "github.com/KnutZuidema/golio" - "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/api" log "github.com/sirupsen/logrus" ) diff --git a/datadragon/data_dragon_test.go b/datadragon/data_dragon_test.go index 11e2e23..a9fe3ee 100644 --- a/datadragon/data_dragon_test.go +++ b/datadragon/data_dragon_test.go @@ -30,9 +30,11 @@ func TestClient_GetChampions(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]ChampionData{ - "champion": {}, - }), + doer: dataDragonResponseDoer( + map[string]ChampionData{ + "champion": {}, + }, + ), want: []ChampionData{{}}, }, { @@ -50,17 +52,19 @@ func TestClient_GetChampions(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetChampions() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetChampions() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetChampions() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -74,9 +78,11 @@ func TestClient_GetChampion(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]ChampionDataExtended{ - "champion": {}, - }), + doer: dataDragonResponseDoer( + map[string]ChampionDataExtended{ + "champion": {}, + }, + ), want: ChampionDataExtended{}, }, { @@ -99,17 +105,19 @@ func TestClient_GetChampion(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetChampion("champion") - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetChampion("champion") - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetChampion("champion") + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -123,9 +131,11 @@ func TestClient_GetProfileIcons(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]ProfileIcon{ - "icon": {}, - }), + doer: dataDragonResponseDoer( + map[string]ProfileIcon{ + "icon": {}, + }, + ), want: []ProfileIcon{{}}, }, { @@ -143,17 +153,19 @@ func TestClient_GetProfileIcons(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetProfileIcons() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetProfileIcons() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetProfileIcons() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -167,9 +179,11 @@ func TestClient_GetItems(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Item{ - "item": {}, - }), + doer: dataDragonResponseDoer( + map[string]Item{ + "item": {}, + }, + ), want: []Item{{ID: "item"}}, }, { @@ -187,17 +201,19 @@ func TestClient_GetItems(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetItems() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetItems() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetItems() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -211,9 +227,11 @@ func TestClient_GetRunes(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Item{ - "rune": {}, - }), + doer: dataDragonResponseDoer( + map[string]Item{ + "rune": {}, + }, + ), want: []Item{{ID: "rune"}}, }, { @@ -231,17 +249,19 @@ func TestClient_GetRunes(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetRunes() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetRunes() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetRunes() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -255,9 +275,11 @@ func TestClient_GetMasteries(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Mastery{ - "mastery": {}, - }), + doer: dataDragonResponseDoer( + map[string]Mastery{ + "mastery": {}, + }, + ), want: []Mastery{{}}, }, { @@ -275,17 +297,19 @@ func TestClient_GetMasteries(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetMasteries() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetMasteries() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetMasteries() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -299,9 +323,11 @@ func TestClient_GetSummonerSpells(t *testing.T) { }{ { name: "get response", - doer: dataDragonResponseDoer(map[string]SummonerSpell{ - "summoner": {}, - }), + doer: dataDragonResponseDoer( + map[string]SummonerSpell{ + "summoner": {}, + }, + ), want: []SummonerSpell{{}}, }, { @@ -319,17 +345,19 @@ func TestClient_GetSummonerSpells(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := c.GetSummonerSpells() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) got, err := c.GetSummonerSpells() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetSummonerSpells() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -350,9 +378,11 @@ func TestClient_GetChampionByID(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]ChampionData{ - "champion": {Name: "champion", Key: "id"}, - }), + doer: dataDragonResponseDoer( + map[string]ChampionData{ + "champion": {Name: "champion", Key: "id"}, + }, + ), id: "id", want: ChampionDataExtended{ChampionData: ChampionData{Name: "champion", Key: "id"}}, }, @@ -371,12 +401,14 @@ func TestClient_GetChampionByID(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetChampionByID(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetChampionByID(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -391,9 +423,11 @@ func TestClient_GetProfileIcon(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]ProfileIcon{ - "icon": {ID: 1}, - }), + doer: dataDragonResponseDoer( + map[string]ProfileIcon{ + "icon": {ID: 1}, + }, + ), id: 1, want: ProfileIcon{ID: 1}, }, @@ -412,12 +446,14 @@ func TestClient_GetProfileIcon(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetProfileIcon(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetProfileIcon(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -432,9 +468,11 @@ func TestClient_GetItem(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Item{ - "id": {}, - }), + doer: dataDragonResponseDoer( + map[string]Item{ + "id": {}, + }, + ), id: "id", want: Item{ID: "id"}, }, @@ -453,12 +491,14 @@ func TestClient_GetItem(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetItem(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetItem(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -473,9 +513,11 @@ func TestClient_GetMastery(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Mastery{ - "icon": {ID: 1}, - }), + doer: dataDragonResponseDoer( + map[string]Mastery{ + "icon": {ID: 1}, + }, + ), id: 1, want: Mastery{ID: 1}, }, @@ -494,12 +536,14 @@ func TestClient_GetMastery(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetMastery(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetMastery(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -514,9 +558,11 @@ func TestClient_GetRune(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]Item{ - "id": {}, - }), + doer: dataDragonResponseDoer( + map[string]Item{ + "id": {}, + }, + ), id: "id", want: Item{ID: "id"}, }, @@ -535,12 +581,14 @@ func TestClient_GetRune(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetRune(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetRune(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -555,9 +603,11 @@ func TestClient_GetSummonerSpell(t *testing.T) { tests := []test{ { name: "get response", - doer: dataDragonResponseDoer(map[string]SummonerSpell{ - "id": {Key: "id"}, - }), + doer: dataDragonResponseDoer( + map[string]SummonerSpell{ + "id": {Key: "id"}, + }, + ), id: "id", want: SummonerSpell{Key: "id"}, }, @@ -576,12 +626,14 @@ func TestClient_GetSummonerSpell(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := client.GetSummonerSpell(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := client.GetSummonerSpell(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -613,11 +665,13 @@ func TestClient_doRequest(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) - _, err := c.doRequest(tt.format, tt.endpoint) - assert.Equal(t, err != nil, tt.wantErr) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionEuropeWest, log.StandardLogger()) + _, err := c.doRequest(tt.format, tt.endpoint) + assert.Equal(t, err != nil, tt.wantErr) + }, + ) } } @@ -641,12 +695,14 @@ func TestClient_init(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, api.RegionOceania, log.StandardLogger()) - if err := c.init(string(api.RegionOceania)); (err != nil) != tt.wantErr { - t.Errorf("Client.init() error = %v, wantErr %v", err, tt.wantErr) - } - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, api.RegionOceania, log.StandardLogger()) + if err := c.init(string(api.RegionOceania)); (err != nil) != tt.wantErr { + t.Errorf("Client.init() error = %v, wantErr %v", err, tt.wantErr) + } + }, + ) } } @@ -664,11 +720,13 @@ func TestClient_getInto(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(mock.NewJSONMockDoer(0, 200), api.RegionOceania, log.StandardLogger()) - err := c.getInto("endpoint", tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(mock.NewJSONMockDoer(0, 200), api.RegionOceania, log.StandardLogger()) + err := c.getInto("endpoint", tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } } @@ -701,18 +759,22 @@ func Test_versionGreaterThan(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := versionGreaterThan(tt.args.v1, tt.args.v2); got != tt.want { - t.Errorf("versionGreaterThan() = %v, want %v", got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + if got := versionGreaterThan(tt.args.v1, tt.args.v2); got != tt.want { + t.Errorf("versionGreaterThan() = %v, want %v", got, tt.want) + } + }, + ) } } func dataDragonResponseDoer(object interface{}) internal.Doer { - return mock.NewJSONMockDoer(dataDragonResponse{ - Data: object, - }, 200) + return mock.NewJSONMockDoer( + dataDragonResponse{ + Data: object, + }, 200, + ) } type errorReadCloser struct{} diff --git a/datadragon/model_test.go b/datadragon/model_test.go index 3e684d7..d0cb7d9 100644 --- a/datadragon/model_test.go +++ b/datadragon/model_test.go @@ -21,20 +21,24 @@ func TestChampionData_GetExtended(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]*ChampionDataExtended{ - "champion": {ChampionData: ChampionData{Name: "champion"}}, - }), + doer: dataDragonResponseDoer( + map[string]*ChampionDataExtended{ + "champion": {ChampionData: ChampionData{Name: "champion"}}, + }, + ), data: &ChampionData{Name: "champion"}, want: ChampionDataExtended{ChampionData: ChampionData{Name: "champion"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) - got, err := test.data.GetExtended(client) - assert.Equal(t, test.wantErr, err != nil) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionEuropeWest, log.StandardLogger()) + got, err := test.data.GetExtended(client) + assert.Equal(t, test.wantErr, err != nil) + assert.Equal(t, test.want, got) + }, + ) } } @@ -49,19 +53,23 @@ func TestRecommendedItem_GetItem(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]Item{ - "id": {}, - }), + doer: dataDragonResponseDoer( + map[string]Item{ + "id": {}, + }, + ), data: &RecommendedItem{ID: "id"}, want: Item{ID: "id"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.data.GetItem(client) - assert.Equal(t, test.wantErr, err != nil) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.data.GetItem(client) + assert.Equal(t, test.wantErr, err != nil) + assert.Equal(t, test.want, got) + }, + ) } } diff --git a/go.mod b/go.mod index 645f0ca..45ddae3 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,15 @@ module github.com/KnutZuidema/golio -go 1.12 +go 1.20 require ( - github.com/sirupsen/logrus v1.4.2 - github.com/stretchr/testify v1.3.0 + github.com/sirupsen/logrus v1.9.0 + github.com/stretchr/testify v1.8.1 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 86c9bda..9adccfe 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,22 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +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= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/golio.go b/golio.go index 640e74c..caf666b 100644 --- a/golio.go +++ b/golio.go @@ -2,22 +2,23 @@ // idiomatic access to all API endpoints. // // Example: -// client := golio.NewClient("API KEY", -// golio.WithRegion(api.RegionNorthAmerica), -// golio.WithLogger(logrus.New().WithField("foo", "bar"))) -// summoner, _ := client.Riot.Summoner.GetByName("SK Jenax") -// fmt.Printf("%s is a level %d summoner\n", summoner.Name, summoner.SummonerLevel) -// champion, _ := client.DataDragon.GetChampion("Ashe") -// mastery, err := client.Riot.ChampionMastery.Get(summoner.ID, champion.Key) -// if err != nil { -// fmt.Printf("%s has not played any games on %s\n", summoner.Name, champion.Name) -// } else { -// fmt.Printf("%s has mastery level %d with %d points on %s\n", summoner.Name, mastery.ChampionLevel, -// mastery.ChampionPoints, champion.Name) -// } -// challengers, _ := client.Riot.League.GetChallenger(api.QueueRankedSolo) -// rank1 := challengers.GetRank(0) -// fmt.Printf("%s is the highest ranked player with %d league points\n", rank1.SummonerName, rank1.LeaguePoints) +// +// client := golio.NewClient("API KEY", +// golio.WithRegion(api.RegionNorthAmerica), +// golio.WithLogger(logrus.New().WithField("foo", "bar"))) +// summoner, _ := client.Riot.Summoner.GetByName("SK Jenax") +// fmt.Printf("%s is a level %d summoner\n", summoner.Name, summoner.SummonerLevel) +// champion, _ := client.DataDragon.GetChampion("Ashe") +// mastery, err := client.Riot.ChampionMastery.Get(summoner.ID, champion.Key) +// if err != nil { +// fmt.Printf("%s has not played any games on %s\n", summoner.Name, champion.Name) +// } else { +// fmt.Printf("%s has mastery level %d with %d points on %s\n", summoner.Name, mastery.ChampionLevel, +// mastery.ChampionPoints, champion.Name) +// } +// challengers, _ := client.Riot.League.GetChallenger(api.QueueRankedSolo) +// rank1 := challengers.GetRank(0) +// fmt.Printf("%s is the highest ranked player with %d league points\n", rank1.SummonerName, rank1.LeaguePoints) package golio import ( diff --git a/golio_test.go b/golio_test.go index e2f52fe..439a990 100644 --- a/golio_test.go +++ b/golio_test.go @@ -11,9 +11,11 @@ import ( ) func TestNewClient(t *testing.T) { - client := NewClient("api_key", + client := NewClient( + "api_key", WithLogger(log.StandardLogger()), WithRegion(api.RegionEuropeWest), - WithClient(http.DefaultClient)) + WithClient(http.DefaultClient), + ) require.NotNil(t, client) } diff --git a/internal/client.go b/internal/client.go index 303ecb0..cec7f6a 100644 --- a/internal/client.go +++ b/internal/client.go @@ -41,10 +41,12 @@ func NewClient(region api.Region, key string, client Doer, logger log.FieldLogge // GetInto processes a GET request and saves the response body into the given target. func (c *Client) GetInto(endpoint string, target interface{}) error { - logger := c.Logger().WithFields(log.Fields{ - "method": "GetInto", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "GetInto", + "endpoint": endpoint, + }, + ) response, err := c.Get(endpoint) if err != nil { logger.Debug(err) @@ -59,10 +61,12 @@ func (c *Client) GetInto(endpoint string, target interface{}) error { // PostInto processes a POST request and saves the response body into the given target. func (c *Client) PostInto(endpoint string, body, target interface{}) error { - logger := c.Logger().WithFields(log.Fields{ - "method": "PostInto", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "PostInto", + "endpoint": endpoint, + }, + ) response, err := c.Post(endpoint, body) if err != nil { logger.Debug(err) @@ -77,10 +81,12 @@ func (c *Client) PostInto(endpoint string, body, target interface{}) error { // Put processes a PUT request. func (c *Client) Put(endpoint string, body interface{}) error { - logger := c.Logger().WithFields(log.Fields{ - "method": "Put", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "Put", + "endpoint": endpoint, + }, + ) buf := &bytes.Buffer{} if err := json.NewEncoder(buf).Encode(body); err != nil { logger.Debug(err) @@ -97,10 +103,12 @@ func (c *Client) Get(endpoint string) (*http.Response, error) { // Post processes a POST request. func (c *Client) Post(endpoint string, body interface{}) (*http.Response, error) { - logger := c.Logger().WithFields(log.Fields{ - "method": "Post", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "Post", + "endpoint": endpoint, + }, + ) buf := &bytes.Buffer{} if err := json.NewEncoder(buf).Encode(body); err != nil { logger.Debug(err) @@ -112,10 +120,12 @@ func (c *Client) Post(endpoint string, body interface{}) (*http.Response, error) // DoRequest processes a http.Request and returns the response. // Rate-Limiting and retrying is handled via the corresponding response headers. func (c *Client) DoRequest(method, endpoint string, body io.Reader) (*http.Response, error) { - logger := c.Logger().WithFields(log.Fields{ - "method": "DoRequest", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "DoRequest", + "endpoint": endpoint, + }, + ) request, err := c.NewRequest(method, endpoint, body) if err != nil { logger.Debug(err) @@ -162,10 +172,12 @@ func (c *Client) DoRequest(method, endpoint string, body io.Reader) (*http.Respo // NewRequest returns a new http.Request with necessary headers et. func (c *Client) NewRequest(method, endpoint string, body io.Reader) (*http.Request, error) { - logger := c.Logger().WithFields(log.Fields{ - "method": "NewRequest", - "endpoint": endpoint, - }) + logger := c.Logger().WithFields( + log.Fields{ + "method": "NewRequest", + "endpoint": endpoint, + }, + ) request, err := http.NewRequest(method, fmt.Sprintf(apiURLFormat, scheme, c.Region, baseURL, endpoint), body) if err != nil { logger.Debug(err) diff --git a/internal/client_test.go b/internal/client_test.go index eb15785..5dd2ef5 100644 --- a/internal/client_test.go +++ b/internal/client_test.go @@ -59,9 +59,11 @@ func TestClient_DoRequest(t *testing.T) { args: args{ method: "GET", }, - doer: mock.NewHeaderMockDoer(http.StatusTooManyRequests, http.Header{ - "Retry-After": []string{"abc"}, - }), + doer: mock.NewHeaderMockDoer( + http.StatusTooManyRequests, http.Header{ + "Retry-After": []string{"abc"}, + }, + ), wantErr: true, }, { @@ -88,11 +90,13 @@ func TestClient_DoRequest(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(api.RegionEuropeNorthEast, "", tt.doer, logrus.StandardLogger()) - _, err := c.DoRequest(tt.args.method, tt.args.endpoint, tt.args.body) - assert.Equal(t, err != nil, tt.wantErr) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(api.RegionEuropeNorthEast, "", tt.doer, logrus.StandardLogger()) + _, err := c.DoRequest(tt.args.method, tt.args.endpoint, tt.args.body) + assert.Equal(t, err != nil, tt.wantErr) + }, + ) } } @@ -125,11 +129,13 @@ func TestClient_GetInto(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) - err := c.GetInto("endpoint", tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) + err := c.GetInto("endpoint", tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } } @@ -162,11 +168,13 @@ func TestClient_PostInto(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) - err := c.PostInto("endpoint", struct{}{}, tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) + err := c.PostInto("endpoint", struct{}{}, tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } } @@ -194,11 +202,13 @@ func TestClient_Post(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) - _, err := c.Post("endpoint", tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) + _, err := c.Post("endpoint", tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } } @@ -226,11 +236,13 @@ func TestClient_Put(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) - err := c.Put("endpoint", tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(api.RegionOceania, "API_KEY", tt.doer, logrus.StandardLogger()) + err := c.Put("endpoint", tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } } diff --git a/riot/client.go b/riot/client.go index 8836152..9d6145f 100644 --- a/riot/client.go +++ b/riot/client.go @@ -9,6 +9,7 @@ import ( "github.com/KnutZuidema/golio/internal" "github.com/KnutZuidema/golio/riot/lol" "github.com/KnutZuidema/golio/riot/lor" + "github.com/KnutZuidema/golio/riot/val" ) // Client provides access to all Riot API endpoints @@ -34,6 +35,7 @@ type Client struct { LoL *lol.Client LoR *lor.Client + Val *val.Client } // NewClient returns a new api client for the Riot API @@ -42,6 +44,7 @@ func NewClient(region api.Region, apiKey string, client internal.Doer, logger lo c := &Client{ LoL: lol.NewClient(baseClient), LoR: lor.NewClient(baseClient), + Val: val.NewClient(baseClient), } // TODO: deprecated, remove in a future release diff --git a/riot/lol/challenges.go b/riot/lol/challenges.go new file mode 100644 index 0000000..78efcd8 --- /dev/null +++ b/riot/lol/challenges.go @@ -0,0 +1,104 @@ +package lol + +import ( + "fmt" + + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/internal" +) + +// ChallengesClient provides methods for the challenges endpoints of the League of Legends API. +type ChallengesClient struct { + c *internal.Client +} + +// GetConfig returns all basic challenge configuration information +func (cc *ChallengesClient) GetConfig() ([]*ChallengeConfigInfo, error) { + logger := cc.logger().WithField("method", "GetConfig") + var challengeConfigs []*ChallengeConfigInfo + if err := cc.c.GetInto(endpointChallengesConfig, &challengeConfigs); err != nil { + logger.Debug(err) + return nil, err + } + return challengeConfigs, nil +} + +// Percentiles a map of level to percentile used by PercentilesByChallenges as value +type Percentiles map[string]float64 + +// PercentilesByChallenges a map of level to percentile of players who have achieved it +type PercentilesByChallenges map[string]Percentiles + +// GetPercentiles returns a map of level to percentile of players who have achieved it +func (cc *ChallengesClient) GetPercentiles() (PercentilesByChallenges, error) { + logger := cc.logger().WithField("method", "GetPercentiles") + var percentiles PercentilesByChallenges + if err := cc.c.GetInto(endpointChallengesPercentiles, &percentiles); err != nil { + logger.Debug(err) + return nil, err + } + return percentiles, nil +} + +// GetConfigByChallengeID returns challenge configuration by ID +func (cc *ChallengesClient) GetConfigByChallengeID(challengeID int64) (*ChallengeConfigInfo, error) { + logger := cc.logger().WithField("method", "GetConfigByChallengeID") + var challengeConfig *ChallengeConfigInfo + if err := cc.c.GetInto( + fmt.Sprintf(endpointChallengesConfigByChallengeID, challengeID), &challengeConfig, + ); err != nil { + logger.Debug(err) + return nil, err + } + return challengeConfig, nil +} + +// GetLeaderBoardByChallengeIDAndLevel returns top players for each level +func (cc *ChallengesClient) GetLeaderBoardByChallengeIDAndLevel( + challengeID int64, tier tier, limit int32, +) ([]*ApexPlayerInfo, error) { + logger := cc.logger().WithField("method", "GetLeaderBoardByChallengeIDAndLevel") + var apexPlayerInfo []*ApexPlayerInfo + if tier == "" { + tier = TierChallenger + } + if limit <= 0 { + limit = 50 + } + if err := cc.c.GetInto( + fmt.Sprintf(endpointChallengesLeaderboards, challengeID, tier, limit), &apexPlayerInfo, + ); err != nil { + logger.Debug(err) + return nil, err + } + return apexPlayerInfo, nil +} + +// GetPercentilesByChallengeID returns map of level to percentiles of players who have achieved it for a challenge +func (cc *ChallengesClient) GetPercentilesByChallengeID(challengeID int64) (Percentiles, error) { + logger := cc.logger().WithField("method", "GetPercentilesByChallengeID") + var percentiles Percentiles + if err := cc.c.GetInto( + fmt.Sprintf(endpointChallengesPercentilesByChallengeID, challengeID), &percentiles, + ); err != nil { + logger.Debug(err) + return nil, err + } + return percentiles, nil +} + +// GetPlayerDataByPUUID returns player information with list of all progressed challenges +func (cc *ChallengesClient) GetPlayerDataByPUUID(uuid string) (*PlayerInfo, error) { + logger := cc.logger().WithField("method", "GetPlayerDataByPUUID") + var playerData *PlayerInfo + if err := cc.c.GetInto(fmt.Sprintf(endpointChallengesPlayerDataByPUUID, uuid), &playerData); err != nil { + logger.Debug(err) + return nil, err + } + return playerData, nil +} + +func (cc *ChallengesClient) logger() log.FieldLogger { + return cc.c.Logger().WithField("category", "challenges") +} diff --git a/riot/lol/challenges_test.go b/riot/lol/challenges_test.go new file mode 100644 index 0000000..cb6518b --- /dev/null +++ b/riot/lol/challenges_test.go @@ -0,0 +1,213 @@ +package lol + +import ( + "fmt" + "net/http" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestChallengesClient_GetConfig(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want []*ChallengeConfigInfo + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: []*ChallengeConfigInfo{{}}, + doer: mock.NewJSONMockDoer([]ChallengeConfigInfo{{}}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetConfig() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetPercentiles(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want PercentilesByChallenges + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: PercentilesByChallenges{}, + doer: mock.NewJSONMockDoer(PercentilesByChallenges{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetPercentiles() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetConfigWithChallengeId(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *ChallengeConfigInfo + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &ChallengeConfigInfo{}, + doer: mock.NewJSONMockDoer(ChallengeConfigInfo{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetConfigByChallengeID(1) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetLeaderBoardByChallengeIdAndLevel(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want []*ApexPlayerInfo + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: []*ApexPlayerInfo{{}}, + doer: mock.NewJSONMockDoer([]ApexPlayerInfo{{}}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetLeaderBoardByChallengeIDAndLevel(203102, "", 0) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetPercentilesWithChallengeId(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want Percentiles + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: Percentiles{}, + doer: mock.NewJSONMockDoer(Percentiles{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetPercentilesByChallengeID(1) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetPlayerDataWithPUUID(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *PlayerInfo + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &PlayerInfo{}, + doer: mock.NewJSONMockDoer(PlayerInfo{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChallengesClient{c: client}).GetPlayerDataByPUUID("1") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} diff --git a/riot/lol/champion_mastery_test.go b/riot/lol/champion_mastery_test.go index 333ce80..092756f 100644 --- a/riot/lol/champion_mastery_test.go +++ b/riot/lol/champion_mastery_test.go @@ -34,14 +34,16 @@ func TestChampionMasteryClient_List(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&ChampionMasteryClient{c: client}).List("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChampionMasteryClient{c: client}).List("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -65,14 +67,16 @@ func TestChampionMasteryClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&ChampionMasteryClient{c: client}).Get("id", "id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChampionMasteryClient{c: client}).Get("id", "id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -96,13 +100,15 @@ func TestChampionMasteryClient_GetTotal(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&ChampionMasteryClient{c: client}).GetTotal("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChampionMasteryClient{c: client}).GetTotal("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/champion_test.go b/riot/lol/champion_test.go index edd567d..7e4bb74 100644 --- a/riot/lol/champion_test.go +++ b/riot/lol/champion_test.go @@ -34,13 +34,15 @@ func TestChampionClient_GetFreeRotation(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&ChampionClient{c: client}).GetFreeRotation() - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ChampionClient{c: client}).GetFreeRotation() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/client.go b/riot/lol/client.go index 48e906b..c40713c 100644 --- a/riot/lol/client.go +++ b/riot/lol/client.go @@ -4,6 +4,7 @@ import "github.com/KnutZuidema/golio/internal" // Client pools all methods for endpoints of the League of Legends API. type Client struct { + Challenge *ChallengesClient ChampionMastery *ChampionMasteryClient Champion *ChampionClient League *LeagueClient @@ -18,6 +19,7 @@ type Client struct { // NewClient returns a new instance of a League of Legends client. func NewClient(base *internal.Client) *Client { return &Client{ + Challenge: &ChallengesClient{c: base}, ChampionMastery: &ChampionMasteryClient{c: base}, Summoner: &SummonerClient{c: base}, Champion: &ChampionClient{c: base}, diff --git a/riot/lol/constants.go b/riot/lol/constants.go index c357515..8ade9ae 100644 --- a/riot/lol/constants.go +++ b/riot/lol/constants.go @@ -1,45 +1,56 @@ package lol const ( - endpointBase = "/lol" - endpointMasteryBase = endpointBase + "/champion-mastery/v4" - endpointGetChampionMasteries = endpointMasteryBase + "/champion-masteries/by-summoner/%s" - endpointGetChampionMastery = endpointMasteryBase + "/champion-masteries/by-summoner/%s/by-champion/%s" - endpointGetChampionMasteryTotalScore = endpointMasteryBase + "/scores/by-summoner/%s" - endpointPlatformBase = endpointBase + "/platform/v3" - endpointGetFreeChampionRotation = endpointPlatformBase + "/champion-rotations" - endpointLeagueBase = endpointBase + "/league/v4" - endpointGetChallengerLeague = endpointLeagueBase + "/challengerleagues/by-queue/%s" - endpointGetGrandmasterLeague = endpointLeagueBase + "/grandmasterleagues/by-queue/%s" - endpointGetMasterLeague = endpointLeagueBase + "/masterleagues/by-queue/%s" - endpointGetLeaguesBySummoner = endpointLeagueBase + "/entries/by-summoner/%s" - endpointGetLeagues = endpointLeagueBase + "/entries/%s/%s/%s" - endpointGetLeague = endpointLeagueBase + "/leagues/%s" - endpointStatusBase = endpointBase + "/status/v3" - endpointGetStatus = endpointStatusBase + "/shard-data" - endpointMatchBase = endpointBase + "/match/v5" - endpointGetMatchIDs = endpointMatchBase + "/matches/by-puuid/%s/ids?start=%d&count=%d" - endpointGetMatch = endpointMatchBase + "/matches/%s" - endpointGetMatchTimeline = endpointMatchBase + "/matches/%s/timeline" - endpointSummonerBase = endpointBase + "/summoner/v4" - endpointGetSummonerBySummonerID = endpointSummonerBase + "/summoners/%s" - endpointGetSummonerBy = endpointSummonerBase + "/summoners/by-%s/%s" - endpointSpectatorBase = endpointBase + "/spectator/v4" - endpointGetCurrentGame = endpointSpectatorBase + "/active-games/by-summoner/%s" - endpointGetFeaturedGames = endpointSpectatorBase + "/featured-games" - endpointTournamentStubBase = endpointBase + "/tournament-stub/v4" - endpointCreateStubTournamentCodes = endpointTournamentStubBase + "/codes?count=%d&tournamentId=%d" - endpointGetStubLobbyEvents = endpointTournamentStubBase + "/lobby-events/by-code/%s" - endpointCreateStubTournamentProvider = endpointTournamentStubBase + "/providers" - endpointCreateStubTournament = endpointTournamentStubBase + "/tournaments" - endpointTournamentBase = endpointBase + "/tournament/v4" - endpointCreateTournamentCodes = endpointTournamentBase + "/codes?count=%d&tournamentId=%d" - endpointGetLobbyEvents = endpointTournamentBase + "/lobby-events/by-code/%s" - endpointCreateTournamentProvider = endpointTournamentBase + "/providers" - endpointCreateTournament = endpointTournamentBase + "/tournaments" - endpointGetTournament = endpointTournamentBase + "/codes/%s" - endpointUpdateTournament = endpointTournamentBase + "/codes/%s" - endpointGetThirdPartyCode = endpointPlatformBase + "/third-party-code/by-summoner/%s" + endpointBase = "/lol" + endpointMasteryBase = endpointBase + "/champion-mastery/v4" + endpointMasteriesBase = endpointMasteryBase + "/champion-masteries" + endpointGetChampionMasteries = endpointMasteriesBase + "/by-summoner/%s" + endpointGetChampionMastery = endpointMasteriesBase + "/by-summoner/%s/by-champion/%s" + endpointGetChampionMasteryTotalScore = endpointMasteryBase + "/scores/by-summoner/%s" + endpointChallengesBase = endpointBase + "/challenges/v1" + endpointChallengesBaseChallenges = endpointChallengesBase + "/challenges" + endpointChallengesConfig = endpointChallengesBaseChallenges + "/config" + endpointChallengesPercentiles = endpointChallengesBaseChallenges + "/percentiles" + endpointChallengesConfigByChallengeID = endpointChallengesBaseChallenges + "/%d/config" + endpointChallengesLeaderboardsBase = endpointChallengesBaseChallenges + "/%d/leaderboards" + endpointChallengesLeaderboards = endpointChallengesLeaderboardsBase + "/by-level/%s?limit=%d" + endpointChallengesPercentilesByChallengeID = endpointChallengesBaseChallenges + "/%d/percentiles" + endpointChallengesPlayerDataByPUUID = endpointChallengesBase + "/player-data/%s" + endpointPlatformBase = endpointBase + "/platform/v3" + endpointGetFreeChampionRotation = endpointPlatformBase + "/champion-rotations" + endpointLeagueBase = endpointBase + "/league/v4" + endpointGetChallengerLeague = endpointLeagueBase + "/challengerleagues/by-queue/%s" + endpointGetGrandmasterLeague = endpointLeagueBase + "/grandmasterleagues/by-queue/%s" + endpointGetMasterLeague = endpointLeagueBase + "/masterleagues/by-queue/%s" + endpointGetLeaguesBySummoner = endpointLeagueBase + "/entries/by-summoner/%s" + endpointGetLeagues = endpointLeagueBase + "/entries/%s/%s/%s" + endpointGetLeague = endpointLeagueBase + "/leagues/%s" + endpointStatusBase = endpointBase + "/status/v3" + endpointGetStatus = endpointStatusBase + "/shard-data" + endpointMatchBase = endpointBase + "/match/v5" + endpointGetMatchIDsBase = endpointMatchBase + "/matches/by-puuid" + endpointGetMatchIDs = endpointGetMatchIDsBase + "/%s/ids?start=%d&count=%d" + endpointGetMatch = endpointMatchBase + "/matches/%s" + endpointGetMatchTimeline = endpointMatchBase + "/matches/%s/timeline" + endpointSummonerBase = endpointBase + "/summoner/v4" + endpointGetSummonerBySummonerID = endpointSummonerBase + "/summoners/%s" + endpointGetSummonerBy = endpointSummonerBase + "/summoners/by-%s/%s" + endpointSpectatorBase = endpointBase + "/spectator/v4" + endpointGetCurrentGame = endpointSpectatorBase + "/active-games/by-summoner/%s" + endpointGetFeaturedGames = endpointSpectatorBase + "/featured-games" + endpointTournamentStubBase = endpointBase + "/tournament-stub/v4" + endpointCreateStubTournamentCodes = endpointTournamentStubBase + "/codes?count=%d&tournamentId=%d" + endpointGetStubLobbyEvents = endpointTournamentStubBase + "/lobby-events/by-code/%s" + endpointCreateStubTournamentProvider = endpointTournamentStubBase + "/providers" + endpointCreateStubTournament = endpointTournamentStubBase + "/tournaments" + endpointTournamentBase = endpointBase + "/tournament/v4" + endpointCreateTournamentCodes = endpointTournamentBase + "/codes?count=%d&tournamentId=%d" + endpointGetLobbyEvents = endpointTournamentBase + "/lobby-events/by-code/%s" + endpointCreateTournamentProvider = endpointTournamentBase + "/providers" + endpointCreateTournament = endpointTournamentBase + "/tournaments" + endpointGetTournament = endpointTournamentBase + "/codes/%s" + endpointUpdateTournament = endpointTournamentBase + "/codes/%s" + endpointGetThirdPartyCode = endpointPlatformBase + "/third-party-code/by-summoner/%s" ) type identification string @@ -64,13 +75,16 @@ type tier string // All possible Tiers const ( - TierIron tier = "IRON" - TierBronze = "BRONZE" - TierSilver = "SILVER" - TierGold = "GOLD" - TierPlatinum = "PLATINUM" - TierEmerald = "EMERALD" - TierDiamond = "DIAMOND" + TierIron tier = "IRON" + TierBronze = "BRONZE" + TierSilver = "SILVER" + TierGold = "GOLD" + TierPlatinum = "PLATINUM" + TierEmerald = "EMERALD" + TierDiamond = "DIAMOND" + TierMaster = "MASTER" + TierGrandMaster = "GRANDMASTER" + TierChallenger = "CHALLENGER" ) type division string diff --git a/riot/lol/league_test.go b/riot/lol/league_test.go index ccdb542..0c0186a 100644 --- a/riot/lol/league_test.go +++ b/riot/lol/league_test.go @@ -34,14 +34,16 @@ func TestLeagueClient_GetChallenger(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).GetChallenger(QueueRankedSolo) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).GetChallenger(QueueRankedSolo) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -65,14 +67,16 @@ func TestLeagueClient_GetGrandmaster(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).GetGrandmaster(QueueRankedSolo) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).GetGrandmaster(QueueRankedSolo) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -96,14 +100,16 @@ func TestLeagueClient_GetMaster(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).GetMaster(QueueRankedSolo) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).GetMaster(QueueRankedSolo) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -127,14 +133,16 @@ func TestLeagueClient_ListPlayers(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).ListPlayers(QueueRankedSolo, TierGold, DivisionOne) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).ListPlayers(QueueRankedSolo, TierGold, DivisionOne) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -158,14 +166,16 @@ func TestLeagueClient_ListBySummoner(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).ListBySummoner("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).ListBySummoner("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -189,13 +199,15 @@ func TestLeagueClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&LeagueClient{c: client}).Get("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&LeagueClient{c: client}).Get("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/match.go b/riot/lol/match.go index 85fbd0d..067da33 100644 --- a/riot/lol/match.go +++ b/riot/lol/match.go @@ -63,7 +63,8 @@ func (m *MatchClient) Get(id string) (*Match, error) { // List returns a list of match ids by puuid func (m *MatchClient) List(puuid string, start, count int, options ...*MatchListOptions) ( - []string, error) { + []string, error, +) { logger := m.logger().WithField("method", "List") c := *m.c // copy client c.Region = api.Region(api.RegionToRoute[c.Region]) // Match v5 uses a route instead of a region diff --git a/riot/lol/match_test.go b/riot/lol/match_test.go index 85801de..4645431 100644 --- a/riot/lol/match_test.go +++ b/riot/lol/match_test.go @@ -36,20 +36,24 @@ func TestMatchClient_List(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - queue := 200 - got, err := (&MatchClient{c: client}).List("id", 0, 1, &MatchListOptions{ - Queue: &queue, - Type: "SomeType", - StartTime: time.Now(), - EndTime: time.Now().Add(time.Hour), - }) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + queue := 200 + got, err := (&MatchClient{c: client}).List( + "id", 0, 1, &MatchListOptions{ + Queue: &queue, + Type: "SomeType", + StartTime: time.Now(), + EndTime: time.Now().Add(time.Hour), + }, + ) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -80,25 +84,29 @@ func TestMatchClient_ListStream(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - queue := 200 - got := (&MatchClient{c: client}).ListStream("id", &MatchListOptions{ - Queue: &queue, - Type: "SomeType", - StartTime: time.Now(), - EndTime: time.Now().Add(time.Hour), - }) - for res := range got { - if res.Error != nil && tt.wantErr != nil { - require.Equal(t, res.Error, tt.wantErr) - break - } else if res.Error != nil { - require.Equal(t, res.Error, io.EOF) - return + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + queue := 200 + got := (&MatchClient{c: client}).ListStream( + "id", &MatchListOptions{ + Queue: &queue, + Type: "SomeType", + StartTime: time.Now(), + EndTime: time.Now().Add(time.Hour), + }, + ) + for res := range got { + if res.Error != nil && tt.wantErr != nil { + require.Equal(t, res.Error, tt.wantErr) + break + } else if res.Error != nil { + require.Equal(t, res.Error, io.EOF) + return + } } - } - }) + }, + ) } } @@ -122,14 +130,16 @@ func TestMatchClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&MatchClient{c: client}).Get("NA_1") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&MatchClient{c: client}).Get("NA_1") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -153,13 +163,15 @@ func TestMatchClient_GetTimeline(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&MatchClient{c: client}).GetTimeline("0") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&MatchClient{c: client}).GetTimeline("0") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/model.go b/riot/lol/model.go index 604d24a..3db44bf 100644 --- a/riot/lol/model.go +++ b/riot/lol/model.go @@ -81,9 +81,11 @@ func (l *LeagueList) GetRank(i int) *LeagueItem { if l.sortedEntries == nil || len(l.sortedEntries) != len(l.Entries) { l.sortedEntries = make([]*LeagueItem, len(l.Entries)) copy(l.sortedEntries, l.Entries) - sort.Slice(l.sortedEntries, func(i, j int) bool { - return l.sortedEntries[i].LeaguePoints > l.sortedEntries[j].LeaguePoints - }) + sort.Slice( + l.sortedEntries, func(i, j int) bool { + return l.sortedEntries[i].LeaguePoints > l.sortedEntries[j].LeaguePoints + }, + ) } return l.sortedEntries[i] } @@ -771,3 +773,54 @@ type ProviderRegistrationParameters struct { // (Legal values: BR, EUNE, EUW, JP, LAN, LAS, NA, OCE, PBE, RU, TR) Region string `json:"region"` } + +// ChallengeConfigInfo represents basic challenge configuration information +type ChallengeConfigInfo struct { + ID int64 `json:"id"` + LocalizedNames map[string]map[string]string `json:"localizedNames"` + State string `json:"state"` + Tracking string `json:"tracking"` + StartTimeStamp int64 `json:"startTimeStamp"` + EndTimeStamp int64 `json:"endTimeStamp"` + Leaderboard bool `json:"leaderboard"` + Thresholds map[string]float64 `json:"thresholds"` +} + +// ChallengePoints contains the settings of a previously created tournament +type ChallengePoints struct { + Level string `json:"level"` + Current float32 `json:"current"` + Max int32 `json:"max"` + Percentile float32 `json:"percentile"` +} + +// ChallengeInfo represents each challenge info for a player +type ChallengeInfo struct { + ChallengeID int32 `json:"challengeid"` + Percentile float32 `json:"percentile"` + Level string `json:"level"` + Value float32 `json:"value"` + AchievedTime int64 `json:"achievedtime"` +} + +// PlayerClientPreferences holds player preferences +type PlayerClientPreferences struct { + BannerAccent string `json:"banneraccent"` + Title string `json:"title"` + ChallengeID []int32 `json:"challengeids"` +} + +// PlayerInfo contains player information with list of all progressed challenges +type PlayerInfo struct { + TotalPoints *ChallengePoints `json:"totalpoints"` + CategoryPoints map[string]ChallengePoints `json:"categorypoints"` + Challenges []*ChallengeInfo `json:"challenges"` + Preferences *PlayerClientPreferences `json:"preferences"` +} + +// ApexPlayerInfo holds information of top players for each level +type ApexPlayerInfo struct { + PuuID string `json:"puuid"` + Value float64 `json:"value"` + Position int32 `json:"position"` +} diff --git a/riot/lol/model_test.go b/riot/lol/model_test.go index b7f74d0..00ef941 100644 --- a/riot/lol/model_test.go +++ b/riot/lol/model_test.go @@ -38,12 +38,14 @@ func TestLeagueList_GetRank(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - l := &LeagueList{ - Entries: tt.entries, - } - require.Equal(t, tt.want, l.GetRank(tt.i)) - }) + t.Run( + tt.name, func(t *testing.T) { + l := &LeagueList{ + Entries: tt.entries, + } + require.Equal(t, tt.want, l.GetRank(tt.i)) + }, + ) } } @@ -58,10 +60,12 @@ func TestChampionInfo_GetChampionsForNewPlayers(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion1": {Key: "1", Name: "champion1"}, - "champion2": {Key: "2", Name: "champion2"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion1": {Key: "1", Name: "champion1"}, + "champion2": {Key: "2", Name: "champion2"}, + }, + ), model: ChampionInfo{ FreeChampionIDsForNewPlayers: []int{1, 2}, }, @@ -83,12 +87,14 @@ func TestChampionInfo_GetChampionsForNewPlayers(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampionsForNewPlayers(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampionsForNewPlayers(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -103,10 +109,12 @@ func TestChampionInfo_GetChampions(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion1": {Key: "1", Name: "champion1"}, - "champion2": {Key: "2", Name: "champion2"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion1": {Key: "1", Name: "champion1"}, + "champion2": {Key: "2", Name: "champion2"}, + }, + ), model: ChampionInfo{ FreeChampionIDs: []int{1, 2}, }, @@ -128,12 +136,14 @@ func TestChampionInfo_GetChampions(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampions(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampions(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -154,12 +164,14 @@ func TestChampionMastery_GetSummoner(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) - got, err := test.model.GetSummoner(NewClient(client)) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) + got, err := test.model.GetSummoner(NewClient(client)) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -174,20 +186,24 @@ func TestChampionMastery_GetChampion(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion": {Name: "champion", Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion": {Name: "champion", Key: "1"}, + }, + ), model: ChampionMastery{ChampionID: 1}, want: datadragon.ChampionDataExtended{ChampionData: datadragon.ChampionData{Name: "champion", Key: "1"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampion(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampion(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -208,12 +224,14 @@ func TestLeagueItem_GetSummoner(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) - got, err := test.model.GetSummoner(NewClient(client)) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) + got, err := test.model.GetSummoner(NewClient(client)) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -234,12 +252,14 @@ func TestMatchInfo_GetQueue(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := static.NewClient(test.doer, log.StandardLogger()) - got, err := test.model.GetQueue(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := static.NewClient(test.doer, log.StandardLogger()) + got, err := test.model.GetQueue(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -260,12 +280,14 @@ func TestMatchInfo_GetMap(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := static.NewClient(test.doer, log.StandardLogger()) - got, err := test.model.GetMap(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := static.NewClient(test.doer, log.StandardLogger()) + got, err := test.model.GetMap(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -286,12 +308,14 @@ func TestMatchInfo_GetGameType(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := static.NewClient(test.doer, log.StandardLogger()) - got, err := test.model.GetGameType(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := static.NewClient(test.doer, log.StandardLogger()) + got, err := test.model.GetGameType(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -312,12 +336,14 @@ func TestMatchInfo_GetGameMode(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := static.NewClient(test.doer, log.StandardLogger()) - got, err := test.model.GetGameMode(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := static.NewClient(test.doer, log.StandardLogger()) + got, err := test.model.GetGameMode(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -338,12 +364,14 @@ func TestParticipant_GetSummoner(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) - got, err := test.model.GetSummoner(NewClient(client)) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) + got, err := test.model.GetSummoner(NewClient(client)) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -358,20 +386,24 @@ func TestParticipant_GetProfileIcon(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ProfileIcon{ - "champion": {ID: 1}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ProfileIcon{ + "champion": {ID: 1}, + }, + ), model: Participant{ProfileIcon: 1}, want: datadragon.ProfileIcon{ID: 1}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetProfileIcon(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetProfileIcon(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -386,20 +418,24 @@ func TestTeamBan_GetChampion(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion": {Name: "champion", Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion": {Name: "champion", Key: "1"}, + }, + ), model: TeamBan{ChampionID: 1}, want: datadragon.ChampionDataExtended{ChampionData: datadragon.ChampionData{Name: "champion", Key: "1"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampion(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampion(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -414,20 +450,24 @@ func TestParticipant_GetChampion(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion": {Name: "champion", Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion": {Name: "champion", Key: "1"}, + }, + ), model: Participant{ChampionID: 1}, want: datadragon.ChampionDataExtended{ChampionData: datadragon.ChampionData{Name: "champion", Key: "1"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampion(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampion(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -442,20 +482,24 @@ func TestParticipant_GetSpell1(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.SummonerSpell{ - "champion": {Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.SummonerSpell{ + "champion": {Key: "1"}, + }, + ), model: Participant{Summoner1ID: 1}, want: datadragon.SummonerSpell{Key: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetSpell1(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetSpell1(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -470,20 +514,24 @@ func TestParticipant_GetSpell2(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.SummonerSpell{ - "champion": {Key: "2"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.SummonerSpell{ + "champion": {Key: "2"}, + }, + ), model: Participant{Summoner2ID: 2}, want: datadragon.SummonerSpell{Key: "2"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetSpell2(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetSpell2(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -498,20 +546,24 @@ func TestParticipant_GetItem0(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item0: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem0(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem0(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -526,20 +578,24 @@ func TestParticipant_GetItem1(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item1: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem1(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem1(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -554,20 +610,24 @@ func TestParticipant_GetItem2(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item2: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem2(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem2(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -582,20 +642,24 @@ func TestParticipant_GetItem3(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item3: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem3(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem3(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -610,20 +674,24 @@ func TestParticipant_GetItem4(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item4: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem4(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem4(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -638,20 +706,24 @@ func TestParticipant_GetItem5(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item5: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem5(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem5(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -666,20 +738,24 @@ func TestParticipant_GetItem6(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: Participant{Item6: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem6(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem6(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -694,20 +770,24 @@ func TestBannedChampion_GetChampion(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion": {Name: "champion", Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion": {Name: "champion", Key: "1"}, + }, + ), model: BannedChampion{ChampionID: 1}, want: datadragon.ChampionDataExtended{ChampionData: datadragon.ChampionData{Name: "champion", Key: "1"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampion(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampion(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -722,20 +802,24 @@ func TestCurrentGameParticipant_GetChampion(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.ChampionData{ - "champion": {Name: "champion", Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.ChampionData{ + "champion": {Name: "champion", Key: "1"}, + }, + ), model: CurrentGameParticipant{ChampionID: 1}, want: datadragon.ChampionDataExtended{ChampionData: datadragon.ChampionData{Name: "champion", Key: "1"}}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetChampion(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetChampion(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -750,20 +834,24 @@ func TestCurrentGameParticipant_GetSpell1(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.SummonerSpell{ - "champion": {Key: "1"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.SummonerSpell{ + "champion": {Key: "1"}, + }, + ), model: CurrentGameParticipant{Spell1ID: 1}, want: datadragon.SummonerSpell{Key: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetSpell1(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetSpell1(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -778,20 +866,24 @@ func TestCurrentGameParticipant_GetSpell2(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.SummonerSpell{ - "champion": {Key: "2"}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.SummonerSpell{ + "champion": {Key: "2"}, + }, + ), model: CurrentGameParticipant{Spell2ID: 2}, want: datadragon.SummonerSpell{Key: "2"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetSpell2(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetSpell2(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -812,12 +904,14 @@ func TestGameInfo_GetMatch(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) - got, err := test.model.GetMatch(NewClient(client)) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := internal.NewClient(api.RegionKorea, "key", test.doer, log.StandardLogger()) + got, err := test.model.GetMatch(NewClient(client)) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -832,20 +926,24 @@ func TestMatchEvent_GetItem(t *testing.T) { tests := []test{ { name: "valid", - doer: dataDragonResponseDoer(map[string]datadragon.Item{ - "1": {}, - }), + doer: dataDragonResponseDoer( + map[string]datadragon.Item{ + "1": {}, + }, + ), model: MatchEvent{ItemID: 1}, want: datadragon.Item{ID: "1"}, }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) - got, err := test.model.GetItem(client) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := datadragon.NewClient(test.doer, api.RegionKorea, log.StandardLogger()) + got, err := test.model.GetItem(client) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -857,7 +955,9 @@ type dataDragonResponse struct { } func dataDragonResponseDoer(object interface{}) internal.Doer { - return mock.NewJSONMockDoer(dataDragonResponse{ - Data: object, - }, 200) + return mock.NewJSONMockDoer( + dataDragonResponse{ + Data: object, + }, 200, + ) } diff --git a/riot/lol/spectator_test.go b/riot/lol/spectator_test.go index 25a4509..345e50c 100644 --- a/riot/lol/spectator_test.go +++ b/riot/lol/spectator_test.go @@ -34,14 +34,16 @@ func TestSpectatorClient_ListFeatured(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SpectatorClient{c: client}).ListFeatured() - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SpectatorClient{c: client}).ListFeatured() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -65,13 +67,15 @@ func TestSpectatorClient_GetCurrent(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SpectatorClient{c: client}).GetCurrent("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SpectatorClient{c: client}).GetCurrent("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/status_test.go b/riot/lol/status_test.go index 099dffd..8c61213 100644 --- a/riot/lol/status_test.go +++ b/riot/lol/status_test.go @@ -34,13 +34,15 @@ func TestStatusClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&StatusClient{c: client}).Get() - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&StatusClient{c: client}).Get() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/summoner_test.go b/riot/lol/summoner_test.go index 2bc2c4b..4cfc84a 100644 --- a/riot/lol/summoner_test.go +++ b/riot/lol/summoner_test.go @@ -32,15 +32,17 @@ func TestSummonerClient_GetByName(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SummonerClient{c: client}).GetByName("name") - assert.Equal(t, err, tt.wantErr) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + var err error + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SummonerClient{c: client}).GetByName("name") + assert.Equal(t, err, tt.wantErr) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -64,15 +66,17 @@ func TestSummonerClient_GetByAccountID(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SummonerClient{c: client}).GetByAccountID("accountID") - assert.Equal(t, err, tt.wantErr) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + var err error + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SummonerClient{c: client}).GetByAccountID("accountID") + assert.Equal(t, err, tt.wantErr) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -96,15 +100,17 @@ func TestSummonerClient_GetByPUUID(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SummonerClient{c: client}).GetByPUUID("puuid") - assert.Equal(t, err, tt.wantErr) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + var err error + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SummonerClient{c: client}).GetByPUUID("puuid") + assert.Equal(t, err, tt.wantErr) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -128,14 +134,16 @@ func TestSummonerClient_GetByID(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&SummonerClient{c: client}).GetByID("id") - assert.Equal(t, err, tt.wantErr) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + var err error + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&SummonerClient{c: client}).GetByID("id") + assert.Equal(t, err, tt.wantErr) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/third_party_code.go b/riot/lol/third_party_code.go index 0eb975f..31dec60 100644 --- a/riot/lol/third_party_code.go +++ b/riot/lol/third_party_code.go @@ -16,9 +16,11 @@ type ThirdPartyCodeClient struct { // Get returns the third party code for the given summoner id func (t *ThirdPartyCodeClient) Get(summonerID string) (string, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "Get", - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "Get", + }, + ) var code string if err := t.c.GetInto(fmt.Sprintf(endpointGetThirdPartyCode, summonerID), &code); err != nil { logger.Debug(err) diff --git a/riot/lol/third_party_code_test.go b/riot/lol/third_party_code_test.go index 1d2ee34..78a0d2d 100644 --- a/riot/lol/third_party_code_test.go +++ b/riot/lol/third_party_code_test.go @@ -34,13 +34,15 @@ func TestThirdPartyCodeClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&ThirdPartyCodeClient{c: client}).Get("id") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ThirdPartyCodeClient{c: client}).Get("id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/lol/tournament.go b/riot/lol/tournament.go index ea80f51..0273bb4 100644 --- a/riot/lol/tournament.go +++ b/riot/lol/tournament.go @@ -17,10 +17,12 @@ type TournamentClient struct { // For more information about the parameters see the documentation for TournamentCodeParameters. // Set the useStub flag to true to use the stub endpoints for mocking an implementation func (t *TournamentClient) CreateCodes(id, count int, params *TournamentCodeParameters, stub bool) ([]string, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "CreateCodes", - "stub": stub, - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "CreateCodes", + "stub": stub, + }, + ) endpoint := endpointCreateTournamentCodes if stub { endpoint = endpointCreateStubTournamentCodes @@ -36,10 +38,12 @@ func (t *TournamentClient) CreateCodes(id, count int, params *TournamentCodePara // ListLobbyEvents returns the lobby events for a lobby specified by the tournament code // Set the useStub flag to true to use the stub endpoints for mocking an implementation func (t *TournamentClient) ListLobbyEvents(code string, useStub bool) (*LobbyEventList, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "ListLobbyEvents", - "stub": useStub, - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "ListLobbyEvents", + "stub": useStub, + }, + ) endpoint := endpointGetLobbyEvents if useStub { endpoint = endpointGetStubLobbyEvents @@ -56,10 +60,12 @@ func (t *TournamentClient) ListLobbyEvents(code string, useStub bool) (*LobbyEve // For more information about the parameters see the documentation for ProviderRegistrationParameters. // Set the useStub flag to true to use the stub endpoints for mocking an implementation func (t *TournamentClient) CreateProvider(parameters *ProviderRegistrationParameters, useStub bool) (int, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "CreateProvider", - "stub": useStub, - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "CreateProvider", + "stub": useStub, + }, + ) endpoint := endpointCreateTournamentProvider if useStub { endpoint = endpointCreateStubTournamentProvider @@ -76,10 +82,12 @@ func (t *TournamentClient) CreateProvider(parameters *ProviderRegistrationParame // For more information about the parameters see the documentation for TournamentRegistrationParameters. // Set the useStub flag to true to use the stub endpoints for mocking an implementation func (t *TournamentClient) Create(parameters *TournamentRegistrationParameters, useStub bool) (int, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "Create", - "stub": useStub, - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "Create", + "stub": useStub, + }, + ) endpoint := endpointCreateTournament if useStub { endpoint = endpointCreateStubTournament @@ -94,9 +102,11 @@ func (t *TournamentClient) Create(parameters *TournamentRegistrationParameters, // Get returns an existing tournament func (t *TournamentClient) Get(code string) (*Tournament, error) { - logger := t.logger().WithFields(log.Fields{ - "method": "Get", - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "Get", + }, + ) var tournament Tournament if err := t.c.GetInto(fmt.Sprintf(endpointGetTournament, code), &tournament); err != nil { logger.Debug(err) @@ -107,9 +117,11 @@ func (t *TournamentClient) Get(code string) (*Tournament, error) { // Update updates an existing tournament func (t *TournamentClient) Update(code string, parameters TournamentUpdateParameters) error { - logger := t.logger().WithFields(log.Fields{ - "method": "Update", - }) + logger := t.logger().WithFields( + log.Fields{ + "method": "Update", + }, + ) if err := t.c.Put(fmt.Sprintf(endpointUpdateTournament, code), parameters); err != nil { logger.Debug(err) return err diff --git a/riot/lol/tournament_test.go b/riot/lol/tournament_test.go index 3c3e2fb..41ef789 100644 --- a/riot/lol/tournament_test.go +++ b/riot/lol/tournament_test.go @@ -34,14 +34,16 @@ func TestTournamentClient_CreateCodes(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&TournamentClient{c: client}).CreateCodes(0, 0, &TournamentCodeParameters{}, true) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&TournamentClient{c: client}).CreateCodes(0, 0, &TournamentCodeParameters{}, true) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -65,14 +67,16 @@ func TestTournamentClient_ListLobbyEvents(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&TournamentClient{c: client}).ListLobbyEvents("code", true) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&TournamentClient{c: client}).ListLobbyEvents("code", true) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -96,14 +100,16 @@ func TestTournamentClient_CreateProvider(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&TournamentClient{c: client}).CreateProvider(&ProviderRegistrationParameters{}, true) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&TournamentClient{c: client}).CreateProvider(&ProviderRegistrationParameters{}, true) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -127,14 +133,16 @@ func TestTournamentClient_Create(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&TournamentClient{c: client}).Create(&TournamentRegistrationParameters{}, true) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&TournamentClient{c: client}).Create(&TournamentRegistrationParameters{}, true) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -158,14 +166,16 @@ func TestTournamentClient_Get(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&TournamentClient{c: client}).Get("code") - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&TournamentClient{c: client}).Get("code") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } @@ -187,10 +197,12 @@ func TestTournamentClient_Update(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - err := (&TournamentClient{c: client}).Update("code", TournamentUpdateParameters{}) - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + err := (&TournamentClient{c: client}).Update("code", TournamentUpdateParameters{}) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + }, + ) } } diff --git a/riot/lor/ranked_test.go b/riot/lor/ranked_test.go index 8a3465e..c86be7d 100644 --- a/riot/lor/ranked_test.go +++ b/riot/lor/ranked_test.go @@ -42,13 +42,15 @@ func TestRankedClient_GetMasters(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) - got, err := (&RankedClient{c: client}).GetMasters() - require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) - if tt.wantErr == nil { - assert.Equal(t, got, tt.want) - } - }) + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&RankedClient{c: client}).GetMasters() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) } } diff --git a/riot/val/client.go b/riot/val/client.go new file mode 100644 index 0000000..83b4211 --- /dev/null +++ b/riot/val/client.go @@ -0,0 +1,21 @@ +package val + +import "github.com/KnutZuidema/golio/internal" + +// Client pools all methods for endpoints of the Valorant API. +type Client struct { + Content *ContentClient + Status *StatusClient + Ranked *RankedClient + Match *MatchClient +} + +// NewClient returns a new instance of a League of Legends client. +func NewClient(base *internal.Client) *Client { + return &Client{ + Content: &ContentClient{c: base}, + Status: &StatusClient{c: base}, + Ranked: &RankedClient{c: base}, + Match: &MatchClient{c: base}, + } +} diff --git a/riot/val/client_test.go b/riot/val/client_test.go new file mode 100644 index 0000000..d2625ef --- /dev/null +++ b/riot/val/client_test.go @@ -0,0 +1,18 @@ +package val + +import ( + "testing" + + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestNewClient(t *testing.T) { + c := NewClient(internal.NewClient(api.RegionBrasil, "key", mock.NewStatusMockDoer(200), log.StandardLogger())) + if c == nil { + t.Error("returned nil") + } +} diff --git a/riot/val/constants.go b/riot/val/constants.go new file mode 100644 index 0000000..97a699e --- /dev/null +++ b/riot/val/constants.go @@ -0,0 +1,78 @@ +package val + +import "github.com/KnutZuidema/golio/api" + +const ( + endpointBase = "/val" + endpointContentBase = endpointBase + "/content/v1" + endPointGetContent = endpointContentBase + "/contents?%s" + endpointStatusBase = endpointBase + "/status/v1" + endpointGetPlatformData = endpointStatusBase + "/platform-data" + endpointRankedBase = endpointBase + "/ranked/v1" + endpointGetLeaderboardByActID = endpointRankedBase + "/leaderboards/by-act/%s" + endpointMatchBase = endpointBase + "/match/v1" + endpointMatchByID = endpointMatchBase + "/matches/%s" + endpointMatchListByPUUID = endpointMatchBase + "/matchlists/by-puuid/%s" + endpointRecentMatchesByQueue = endpointMatchBase + "/recent-matches/by-queue/%s" +) + +// All existing regions +const ( + RegionAsiaPacific api.Region = "ap" + RegionBrazil api.Region = "br" + RegionESPORTS api.Region = "esports" + RegionEurope api.Region = "eu" + RegionKorea api.Region = "kr" + RegionLatinAmerica api.Region = "latam" + RegionNorthAmerica api.Region = "na" +) + +var ( + // Regions is a list of all available regions + Regions = []api.Region{ + RegionAsiaPacific, + RegionBrazil, + RegionESPORTS, + RegionEurope, + RegionKorea, + RegionLatinAmerica, + RegionNorthAmerica, + } + + // RegionToRoute maps each region to its route + RegionToRoute = map[api.Region]api.Route{ + RegionAsiaPacific: api.RouteAsia, + RegionBrazil: api.RouteAmericas, + RegionESPORTS: api.RouteAmericas, //todo: fix the correct route for esports region + RegionEurope: api.RouteEurope, + RegionKorea: api.RouteAsia, + RegionLatinAmerica: api.RouteAmericas, + RegionNorthAmerica: api.RouteAmericas, + } +) + +// Locale string value for language +type Locale string + +// All possible values of Locale +const ( + LocaleUnitedArabEmirates Locale = "ar-AE" + LocaleGermany Locale = "de-DE" + LocaleUnitedKingdom Locale = "en-GB" + LocaleUnitedStates Locale = "en-US" + LocaleSpain Locale = "es-ES" + LocaleMexico Locale = "es-MX" + LocaleFrance Locale = "fr-FR" + LocaleIndonesia Locale = "id-ID" + LocaleItaly Locale = "it-IT" + LocaleJapan Locale = "ja-JP" + LocaleSouthKorea Locale = "ko-KR" + LocalePoland Locale = "pl-PL" + LocaleBrazil Locale = "pt-BR" + LocaleRussia Locale = "ru-RU" + LocaleThailand Locale = "th-TH" + LocaleTurkish Locale = "tr-TR" + LocaleVietnam Locale = "vi-VN" + LocaleChina Locale = "zh-CN" + LocaleTaiwan Locale = "zh-TW" +) diff --git a/riot/val/content.go b/riot/val/content.go new file mode 100644 index 0000000..711744a --- /dev/null +++ b/riot/val/content.go @@ -0,0 +1,34 @@ +package val + +import ( + "fmt" + + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/internal" +) + +// ContentClient provides methods for the content endpoints of the VALORANT API. +type ContentClient struct { + c *internal.Client +} + +// GetContent returns information about the in-game contents e.g. skins, maps, etc. +func (cc *ContentClient) GetContent(locale Locale) (*ContentInfo, error) { + logger := cc.logger().WithField("method", "GetContent") + url := endPointGetContent + if locale != "" { + url = fmt.Sprintf(endPointGetContent, locale) + } + var contents *ContentInfo + if err := cc.c.GetInto(url, &contents); err != nil { + logger.Debug(err) + fmt.Println(err) + return nil, err + } + return contents, nil +} + +func (cc *ContentClient) logger() log.FieldLogger { + return cc.c.Logger().WithField("category", "content") +} diff --git a/riot/val/content_test.go b/riot/val/content_test.go new file mode 100644 index 0000000..63ec14c --- /dev/null +++ b/riot/val/content_test.go @@ -0,0 +1,48 @@ +package val + +import ( + "fmt" + "net/http" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestChallengesClient_GetConfigWithChallengeId(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *ContentInfo + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &ContentInfo{}, + doer: mock.NewJSONMockDoer(ContentInfo{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&ContentClient{c: client}).GetContent(LocaleTurkish) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} diff --git a/riot/val/match.go b/riot/val/match.go new file mode 100644 index 0000000..9187b3f --- /dev/null +++ b/riot/val/match.go @@ -0,0 +1,57 @@ +package val + +import ( + "fmt" + + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/internal" +) + +// MatchClient provides methods for the match endpoints of the VALORANT API. +type MatchClient struct { + c *internal.Client +} + +// GetMatchByID returns information about a match using match id +func (cc *MatchClient) GetMatchByID(matchID string) (*Match, error) { + logger := cc.logger().WithField("method", "GetMatchByID") + url := endpointMatchByID + var match *Match + if err := cc.c.GetInto(fmt.Sprintf(url, matchID), &match); err != nil { + logger.Debug(err) + fmt.Println(err) + return nil, err + } + return match, nil +} + +// GetMatchListByPUUID returns match history as a list using player UUID +func (cc *MatchClient) GetMatchListByPUUID(puuid string) (*MatchList, error) { + logger := cc.logger().WithField("method", "GetMatchListByPUUID") + url := endpointMatchListByPUUID + var matchList *MatchList + if err := cc.c.GetInto(fmt.Sprintf(url, puuid), &matchList); err != nil { + logger.Debug(err) + fmt.Println(err) + return nil, err + } + return matchList, nil +} + +// GetRecentMatchesByQueue returns last match IDs for live regions and e-sports routing +func (cc *MatchClient) GetRecentMatchesByQueue(queue string) (*RecentMatches, error) { + logger := cc.logger().WithField("method", "GetRecentMatchesByQueue") + url := endpointRecentMatchesByQueue + var recentMatches *RecentMatches + if err := cc.c.GetInto(fmt.Sprintf(url, queue), &recentMatches); err != nil { + logger.Debug(err) + fmt.Println(err) + return nil, err + } + return recentMatches, nil +} + +func (cc *MatchClient) logger() log.FieldLogger { + return cc.c.Logger().WithField("category", "match") +} diff --git a/riot/val/match_test.go b/riot/val/match_test.go new file mode 100644 index 0000000..1f8aafe --- /dev/null +++ b/riot/val/match_test.go @@ -0,0 +1,114 @@ +package val + +import ( + "fmt" + "net/http" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestChallengesClient_GetMatchById(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *Match + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &Match{}, + doer: mock.NewJSONMockDoer(Match{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&MatchClient{c: client}).GetMatchByID("match-id") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetMatchListByPUUID(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *MatchList + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &MatchList{}, + doer: mock.NewJSONMockDoer(MatchList{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&MatchClient{c: client}).GetMatchListByPUUID("puuid") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} + +func TestChallengesClient_GetRecentMatchesByQueue(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *RecentMatches + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &RecentMatches{}, + doer: mock.NewJSONMockDoer(RecentMatches{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&MatchClient{c: client}).GetRecentMatchesByQueue("queue") + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} diff --git a/riot/val/model.go b/riot/val/model.go new file mode 100644 index 0000000..82b3ee0 --- /dev/null +++ b/riot/val/model.go @@ -0,0 +1,271 @@ +package val + +// Act LocalizedNames is excluded because it is not sent when locale is set in request +type Act struct { + Name string `json:"name"` + ID string `json:"id"` + IsActive bool `json:"isActive"` +} + +// ContentItem represents an individual content in ContentInfo +type ContentItem struct { + Name string `json:"name"` + ID string `json:"id"` + AssetName string `json:"assetName"` + AssetPath string `json:"assetPath"` +} + +// ContentInfo represents all contents currently available in the game +type ContentInfo struct { + Version string `json:"version"` + Characters []*ContentItem `json:"characters"` + Maps []*ContentItem `json:"maps"` + Chromas []*ContentItem `json:"chromas"` + Skins []*ContentItem `json:"skins"` + SkinLevels []*ContentItem `json:"skinLevels"` + Equips []*ContentItem `json:"equips"` + GameModes []*ContentItem `json:"gameModes"` + Sprays []*ContentItem `json:"sprays"` + SprayLevels []*ContentItem `json:"sprayLevels"` + Charms []*ContentItem `json:"charms"` + CharmLevels []*ContentItem `json:"charmLevels"` + PlayerCards []*ContentItem `json:"playerCards"` + PlayerTitles []*ContentItem `json:"playerTitles"` + Acts []*Act `json:"acts"` +} + +// Content represents titles and translations fields of Update and Status +type Content struct { + Locale string `json:"locale"` + Content string `json:"content"` +} + +// Update holds data of current software updates for the platforms +type Update struct { + ID int32 `json:"id"` + Author string `json:"author"` + Publish bool `json:"publish"` + PublishLocations []string `json:"publish_locations"` + Translations []*Content `json:"translations"` + CreatedAt string `json:"created_at"` + UpdatedAt string `json:"updated_at"` +} + +// Status represents current maintenance and incidents +type Status struct { + ID int32 `json:"id"` + MaintenanceStatus string `json:"maintenance_status"` + IncidentSeverity string `json:"incident_severity"` + Titles []*Content `json:"titles"` + Updates []*Update `json:"updates"` + CreatedAt string `json:"created_at"` + ArchiveAt string `json:"archive_at"` + UpdatedAt string `json:"updated_at"` + Platforms []string `json:"platforms"` +} + +// PlatformData represents VALORANT status for given platform +type PlatformData struct { + ID string `json:"id"` + Name string `json:"name"` + Locales []string `json:"locales"` + Maintenances []*Status `json:"maintenances"` + Incidents []*Status `json:"incidents"` +} + +// Player holds data of individual players in a leaderboard +type Player struct { + PuuID string `json:"puuid"` + GameName string `json:"gameName"` + TagLine string `json:"tagLine"` + LeaderboardRank int64 `json:"leaderboardRank"` + RankedRating int64 `json:"rankedRating"` + NumberOfWins int64 `json:"numberOfWins"` +} + +// Leaderboard represents a leaderboard +type Leaderboard struct { + Shard string `json:"shard"` + ActID string `json:"actId"` + TotalPlayers int64 `json:"totalPlayers"` + Players []*Player `json:"players"` +} + +// Match represents a match with related data including players, match info and teams +type Match struct { + MatchInfo MatchInfo `json:"matchInfo"` + Players []MatchPlayer `json:"players"` + Coaches []Coach `json:"coaches"` + Teams []Team `json:"teams"` + RoundResults []RoundResult `json:"roundResults"` +} + +// MatchInfo contains the data for a specific match +type MatchInfo struct { + MatchID string `json:"matchId"` + MapID string `json:"mapId"` + GameLengthMillis int `json:"gameLengthMillis"` + GameStartMillis int64 `json:"gameStartMillis"` + ProvisioningFlowID string `json:"provisioningFlowId"` + IsCompleted bool `json:"isCompleted"` + CustomGameName string `json:"customGameName"` + QueueID string `json:"queueId"` + GameMode string `json:"gameMode"` + IsRanked bool `json:"isRanked"` + SeasonID string `json:"seasonId"` +} + +// MatchPlayer holds data of a player participating a match +type MatchPlayer struct { + PuuID string `json:"puuid"` + GameName string `json:"gameName"` + TagLine string `json:"tagLine"` + TeamID string `json:"teamId"` + PartyID string `json:"partyId"` + CharacterID string `json:"characterId"` + Stats PlayerStats `json:"stats"` + CompetitiveTier int `json:"competitiveTier"` + PlayerCard string `json:"playerCard"` + PlayerTitle string `json:"playerTitle"` +} + +// PlayerStats stats of a player in a match +type PlayerStats struct { + Score int `json:"score"` + RoundsPlayed int `json:"roundsPlayed"` + Kills int `json:"kills"` + Deaths int `json:"deaths"` + Assists int `json:"assists"` + PlaytimeMillis int `json:"playtimeMillis"` + AbilityCasts AbilityCasts `json:"abilityCasts"` +} + +// AbilityCasts number of casts of abilities for a player in a match +type AbilityCasts struct { + GrenadeCasts int `json:"grenadeCasts"` + Ability1Casts int `json:"ability1Casts"` + Ability2Casts int `json:"ability2Casts"` + UltimateCasts int `json:"ultimateCasts"` +} + +// Coach holds coach id and team id +type Coach struct { + PUUID string `json:"puuid"` + TeamID string `json:"teamId"` +} + +// Team contains statistics of a team in a match +type Team struct { + TeamID string `json:"teamId"` + Won bool `json:"won"` + RoundsPlayed int `json:"roundsPlayed"` + RoundsWon int `json:"roundsWon"` + NumPoints int `json:"numPoints"` +} + +// PlayerLocations represents player location for planting and defusing +type PlayerLocations struct { + PUUID string `json:"puuid"` + ViewRadians float32 `json:"viewRadians"` + Location Location `json:"location"` +} + +// Location represents the location for PlayerLocations +type Location struct { + X int `json:"x"` + Y int `json:"y"` +} + +// RoundResult holds result data of a round +type RoundResult struct { + RoundNum int `json:"roundNum"` + RoundResult string `json:"roundResult"` + RoundCeremony string `json:"roundCeremony"` + WinningTeam string `json:"winningTeam"` + BombPlanter string `json:"bombPlanter"` + BombDefuser string `json:"bombDefuser"` + PlantRoundTime int `json:"plantRoundTime"` + PlantPlayerLocations []PlayerLocations `json:"plantPlayerLocations"` + PlantLocation Location `json:"plantLocation"` + PlantSite string `json:"plantSite"` + DefuseRoundTime int `json:"defuseRoundTime"` + DefusePlayerLocations []PlayerLocations `json:"defusePlayerLocations"` + DefuseLocation Location `json:"defuseLocation"` + PlayerStats []PlayerRoundStats `json:"playerStats"` + RoundResultCode string `json:"roundResultCode"` +} + +// PlayerRoundStats holds player stats by round +type PlayerRoundStats struct { + PUUID string `json:"puuid"` + Kills []Kill `json:"kills"` + Damages []Damage `json:"damage"` + Score int `json:"score"` + Economy Economy `json:"economy"` + Ability Ability `json:"ability"` +} + +// Kill contains information of kills e.g. killer, victim, finishing damage +type Kill struct { + TimeSinceGameStartMillis int `json:"timeSinceGameStartMillis"` + TimeSinceRoundStartMillis int `json:"timeSinceRoundStartMillis"` + Killer string `json:"killer"` + Victim string `json:"victim"` + VictimLocation Location `json:"victimLocation"` + Assistants []string `json:"assistants"` + PlayerLocations []PlayerLocations `json:"playerLocations"` + FinishingDamage FinishingDamage `json:"finishingDamage"` +} + +// FinishingDamage contains information of the finishing damage +type FinishingDamage struct { + DamageType string `json:"damageType"` + DamageItem string `json:"damageItem"` + IsSecondaryFireMode bool `json:"isSecondaryFireMode"` +} + +// Damage contains information of a damage +type Damage struct { + Receiver string `json:"receiver"` + Damage bool `json:"damage"` + IsSecondaryFireMode bool `json:"isSecondaryFireMode"` + LegShots bool `json:"legshots"` + BodyShots bool `json:"bodyshots"` + Headshots bool `json:"headshots"` +} + +// Economy holds economy information including spent credits +type Economy struct { + LoadOutValue int `json:"loadoutValue"` + Weapon string `json:"weapon"` + Armor string `json:"armor"` + Remaining int `json:"remaining"` + Spent int `json:"spent"` +} + +// Ability holds ability effects of a player in a round +type Ability struct { + GrenadeEffects string `json:"grenadeEffects"` + Ability1Effects string `json:"ability1Effects"` + Ability2Effects string `json:"ability2Effects"` + UltimateEffects string `json:"ultimateEffects"` +} + +// MatchList represent match history of a player +type MatchList struct { + PUUID string `json:"puuid"` + History []MatchListEntry `json:"history"` +} + +// MatchListEntry holds information regarding each match +type MatchListEntry struct { + MatchID string `json:"matchId"` + GameStartTimeMillis int64 `json:"gameStartTimeMillis"` + QueueID string `json:"queueId"` +} + +// RecentMatches represents last matches for live regions and e-sports routing +type RecentMatches struct { + CurrentTime int64 `json:"currentTime"` + MatchIDs []string `json:"matchIds"` +} diff --git a/riot/val/ranked.go b/riot/val/ranked.go new file mode 100644 index 0000000..c85f46b --- /dev/null +++ b/riot/val/ranked.go @@ -0,0 +1,38 @@ +package val + +import ( + "fmt" + + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/internal" +) + +// RankedClient provides methods for the ranked endpoints of the VALORANT API. +type RankedClient struct { + c *internal.Client +} + +// GetLeaderboardByActID returns leaderboard for the competitive queue by act ID +func (cc *RankedClient) GetLeaderboardByActID(actID string, startIndex, size int32) (*Leaderboard, error) { + logger := cc.logger().WithField("method", "GetLeaderboardByActID") + var leaderboard *Leaderboard + if startIndex < 0 { + startIndex = 0 + } + if size < 1 { + size = 200 + } + if err := cc.c.GetInto( + fmt.Sprintf(endpointGetLeaderboardByActID+"?size=%d&startIndex=%d", actID, size, startIndex), &leaderboard, + ); err != nil { + logger.Debug(err) + fmt.Println(err) + return nil, err + } + return leaderboard, nil +} + +func (cc *RankedClient) logger() log.FieldLogger { + return cc.c.Logger().WithField("category", "ranked") +} diff --git a/riot/val/ranked_test.go b/riot/val/ranked_test.go new file mode 100644 index 0000000..da65aa7 --- /dev/null +++ b/riot/val/ranked_test.go @@ -0,0 +1,48 @@ +package val + +import ( + "fmt" + "net/http" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestChallengesClient_GetLeaderboardByActId(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *Leaderboard + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &Leaderboard{}, + doer: mock.NewJSONMockDoer(Leaderboard{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&RankedClient{c: client}).GetLeaderboardByActID("actId", -1, 0) + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} diff --git a/riot/val/status.go b/riot/val/status.go new file mode 100644 index 0000000..1d3acbd --- /dev/null +++ b/riot/val/status.go @@ -0,0 +1,27 @@ +package val + +import ( + log "github.com/sirupsen/logrus" + + "github.com/KnutZuidema/golio/internal" +) + +// StatusClient provides methods for the status endpoints of the VALORANT API. +type StatusClient struct { + c *internal.Client +} + +// GetPlatformData returns information about platform including maintenances and incidents +func (cc *StatusClient) GetPlatformData() (*PlatformData, error) { + logger := cc.logger().WithField("method", "GetPlatformData") + var platformData *PlatformData + if err := cc.c.GetInto(endpointGetPlatformData, &platformData); err != nil { + logger.Debug(err) + return nil, err + } + return platformData, nil +} + +func (cc *StatusClient) logger() log.FieldLogger { + return cc.c.Logger().WithField("category", "status") +} diff --git a/riot/val/status_test.go b/riot/val/status_test.go new file mode 100644 index 0000000..6e77b0a --- /dev/null +++ b/riot/val/status_test.go @@ -0,0 +1,48 @@ +package val + +import ( + "fmt" + "net/http" + "testing" + + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/KnutZuidema/golio/api" + "github.com/KnutZuidema/golio/internal" + "github.com/KnutZuidema/golio/internal/mock" +) + +func TestChallengesClient_GetPlatformData(t *testing.T) { + t.Parallel() + tests := []struct { + name string + want *PlatformData + doer internal.Doer + wantErr error + }{ + { + name: "get response", + want: &PlatformData{}, + doer: mock.NewJSONMockDoer(PlatformData{}, 200), + }, + { + name: "not found", + wantErr: api.ErrNotFound, + doer: mock.NewStatusMockDoer(http.StatusNotFound), + }, + } + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) + got, err := (&StatusClient{c: client}).GetPlatformData() + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) + if tt.wantErr == nil { + assert.Equal(t, got, tt.want) + } + }, + ) + } +} diff --git a/static/static_data_test.go b/static/static_data_test.go index 47f422b..887ad0e 100644 --- a/static/static_data_test.go +++ b/static/static_data_test.go @@ -41,17 +41,19 @@ func TestClient_GetSeasons(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - got, err := c.GetSeasons() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) got, err := c.GetSeasons() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetSeasons() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -83,17 +85,19 @@ func TestClient_GetQueues(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - got, err := c.GetQueues() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) got, err := c.GetQueues() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetQueues() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -125,17 +129,19 @@ func TestClient_GetMaps(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - got, err := c.GetMaps() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) got, err := c.GetMaps() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetMaps() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -167,17 +173,19 @@ func TestClient_GetGameModes(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - got, err := c.GetGameModes() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) got, err := c.GetGameModes() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetGameModes() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -209,17 +217,19 @@ func TestClient_GetGameTypes(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - got, err := c.GetGameTypes() - assert.Equal(t, tt.wantErr, err) - if tt.wantErr == nil { - assert.Equal(t, tt.want, got) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) got, err := c.GetGameTypes() - assert.Nil(t, err) - assert.Equal(t, tt.want, got) - } - }) + assert.Equal(t, tt.wantErr, err) + if tt.wantErr == nil { + assert.Equal(t, tt.want, got) + got, err := c.GetGameTypes() + assert.Nil(t, err) + assert.Equal(t, tt.want, got) + } + }, + ) } } @@ -253,12 +263,14 @@ func TestClient_GetGameMode(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, log.StandardLogger()) - got, err := client.GetGameMode(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, log.StandardLogger()) + got, err := client.GetGameMode(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -292,12 +304,14 @@ func TestClient_GetGameType(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, log.StandardLogger()) - got, err := client.GetGameType(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, log.StandardLogger()) + got, err := client.GetGameType(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -331,12 +345,14 @@ func TestClient_GetMap(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, log.StandardLogger()) - got, err := client.GetMap(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, log.StandardLogger()) + got, err := client.GetMap(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -370,12 +386,14 @@ func TestClient_GetQueue(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, log.StandardLogger()) - got, err := client.GetQueue(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, log.StandardLogger()) + got, err := client.GetQueue(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -409,12 +427,14 @@ func TestClient_GetSeason(t *testing.T) { }, } for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - client := NewClient(test.doer, log.StandardLogger()) - got, err := client.GetSeason(test.id) - assert.Equal(t, test.wantErr, err) - assert.Equal(t, test.want, got) - }) + t.Run( + test.name, func(t *testing.T) { + client := NewClient(test.doer, log.StandardLogger()) + got, err := client.GetSeason(test.id) + assert.Equal(t, test.wantErr, err) + assert.Equal(t, test.want, got) + }, + ) } } @@ -443,11 +463,13 @@ func TestClient_getInto(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c := NewClient(tt.doer, log.StandardLogger()) - err := c.getInto("endpoint", tt.target) - assert.Equal(t, tt.wantErr, err != nil) - }) + t.Run( + tt.name, func(t *testing.T) { + c := NewClient(tt.doer, log.StandardLogger()) + err := c.getInto("endpoint", tt.target) + assert.Equal(t, tt.wantErr, err != nil) + }, + ) } }