KnutZuidema / golio

League of Legends, Legends of Runeterra and Valorant API client library for Go
MIT License
72 stars 29 forks source link

More options to "MatchClient" #37

Closed ironpark closed 4 years ago

ironpark commented 4 years ago

More options to "MatchClient"

/lol/match/v4/matchlists/by-account/{encryptedAccountId}

It has a total of 7 optional parameters. Since the season is DEPRECATED, in the remaining 6 cases, the current golio library supports only beginIndex and endIndex. The rest of the parameters are also useful depending on the situation, so I think it is better to support the rest. However, if all the parameters are supported, the following method is proposed as the function argument will be greatly enlarged..

Option Struct

import (
  "github.com/KnutZuidema/golio/api"
  "github.com/KnutZuidema/golio/riot/lol"
)

func main(){
  ...
  client.Riot.LoL.Match.List(accountId, lol.MatchListOption{
    BeginIndex:1,
    EndTime: ...,
    ...
  })
}

Option Function

import (
  "github.com/KnutZuidema/golio/api"
  "github.com/KnutZuidema/golio/riot/lol"
  "time"
)

func main(){
  ...
  client.Riot.LoL.Match.List(accountId,
     lol.Index(0,100),
     lol.BeginTime(time.Now().Add(-time.Second*100)
  ))
}

Builder

import (
  "github.com/KnutZuidema/golio/api"
  "github.com/KnutZuidema/golio/riot/lol"
  "time"
)

func main(){
  ...
  client.Riot.LoL.Match.Request().
    List().
    Index(0,100).
    BeginTime(time.Now().Add(-time.Second*100).
    Do()
}
KnutZuidema commented 4 years ago

You are right, these missing options should be added. I would prefer an options struct as a vararg parameter, so existing usages of this method do not break. Like this:

func (c *MatchClient) List(accountID string, beginIndex, endIndex int, options... *MatchListOptions) (*Matchlist, error)