rgl

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 9 Imported by: 1

README

RGL

Note that RGL's API is in alpha right now and subject to change. This library could break at any moment.

Reference:
Go Reference Go Report Card

Tips:
Create an RGL object: r := rgl.DefaultRateLimit()
Then do stuff. player, err := r.GetPlayer("steam64")
404/Not Found errors do not return errors, they return zero values where 404 represents an expected "no results for your query".
I made the decision to avoid nil values where possible, so check the zero values carefully.

A type without slices in it can be compared to like player != Player{}, but when types include slices, the slice has to be made: results != SearchResults{Results: make([]string, 0)}. This is verbose so you can use something like len(results.Results > 0) , or just test a single field. results.Count > 0 is readable for SearchResults, but for something like Team you'll probably want to check team.Id > 0. Just take a look at the types in the reference.

You can use your own implementation of the rate.Limiter object by setting r.rl, or you can set it to nil and ratelimit your requests yourself.

Some fields are time strings. Convert to time.Time with t := rgl.ToGoTime(ban.Ends)

Documentation

Overview

RGL api implementation See README for usage and gotchas.

Index

Constants

View Source
const BULK_PLAYER_ENDPOINT = PLAYER_ENDPOINT + "getmany"
View Source
const MATCH_ENDPOINT = RGL_ENDPOINT + "matches/"
View Source
const PLAYER_ENDPOINT = RGL_ENDPOINT + "profile/"
View Source
const RGL_ENDPOINT = "https://api.rgl.gg/v0/"
View Source
const SEARCH_ALIAS_ENDPOINT = RGL_ENDPOINT + "search/players"
View Source
const SEARCH_TEAM_ENDPOINT = RGL_ENDPOINT + "search/teams"
View Source
const SEASON_ENDPOINT = RGL_ENDPOINT + "seasons/"
View Source
const TEAM_ENDPOINT = RGL_ENDPOINT + "teams/"

Variables

This section is empty.

Functions

func ToGoTime

func ToGoTime(str string) time.Time

Wrapper around time.Parse("2006-01-02T15:04:05.999Z", str)

Types

type Ban

type Ban struct {
	Ends   string `json:"endsAt"`
	Reason string `json:"reason"`
}

Used in Player to represent ban information

type BulkBan

type BulkBan struct {
	SteamId string `json:"steamId"`
	Alias   string `json:"alias"`
	Expires string `json:"expiresAt"`
	Created string `json:"createdAt"`
	Reason  string `json:"reason"`
}

Used when receiving paginated bans

type CurrTeam

type CurrTeam struct {
	Id       int    `json:"id"`
	Tag      string `json:"tag"`
	Name     string `json:"name"`
	Status   string `json:"status"`
	SeasonId int    `json:"seasonId"`
	DivId    int    `json:"divisionId"`
	DivName  string `json:"divisionName"`
}

Used in Player.CurrentTeams to represent the teams a player is on

type CurrentTeams

type CurrentTeams struct {
	Sixes      *CurrTeam `json:"sixes"`
	Highlander *CurrTeam `json:"highlander"`
	Prolander  *CurrTeam `json:"prolander"`
}

Used in Player to represent the teams a player is on in each format

type Match

type Match struct {
	Id         int         `json:"matchId"`
	SeasonName string      `json:"seasonName"`
	DivName    string      `json:"divName"`
	SeasonId   int         `json:"seasonId"`
	MatchDate  string      `json:"matchDate"`
	MatchName  string      `json:"matchName"`
	Teams      []MatchTeam `json:"teams"`
	Maps       []MatchMap  `json:"maps"`
}

Toplevel endpoint for a match found by id

type MatchMap

type MatchMap struct {
	MapName   string `json:"mapName"`
	HomeScore int    `json:"homeScore"`
	AwayScore int    `json:"awayScore"`
}

Embedded in Match to represent maps played (multiple maps per match for playoffs)

type MatchTeam

type MatchTeam struct {
	Id       int    `json:"teamId"`
	TeamName string `json:"teamName"`
	TeamTag  string `json:"teamTag"`
	IsHome   bool   `json:"isHome"`
	Points   string `json:"points"`
}

Embedded in Match to represent the teams playing

type Player

type Player struct {
	SteamId      string       `json:"steamId"`
	Avatar       string       `json:"avatar"`
	Name         string       `json:"name"`
	Updated      string       `json:"updatedAt"`
	Status       PlayerStatus `json:"status"`
	Ban          *Ban         `json:"banInformation"`
	CurrentTeams CurrentTeams `json:"currentTeams"`
}

Toplevel endpoint for a player found by id

type PlayerStatus

type PlayerStatus struct {
	IsVerified    bool `json:"isVerified"`
	IsBanned      bool `json:"isBanned"`
	IsOnProbation bool `json:"isOnProbation"`
}

Used in Player to represent status information

type PlayerTeamHistory

type PlayerTeamHistory struct {
	FormatId     int    `json:"formatId"`
	FormatName   string `json:"formatName"`
	RegionId     int    `json:"regionId"`
	RegionName   string `json:"regionName"`
	SeasonId     int    `json:"seasonId"`
	SeasonName   string `json:"seasonName"`
	Started      string `json:"startedAt"`
	DivisionId   int    `json:"divisionId"`
	DivisionName string `json:"divisionName"`
	Left         string `json:"leftAt"` //Can be empty to indicate a null value (player hasn't left team)
	TeamName     string `json:"teamName"`
	TeamTag      string `json:"teamTag"`
	TeamId       int    `json:"teamId"`
	Stats        struct {
		Wins         int `json:"wins"`
		WinsWithout  int `json:"winsWithout"`
		Loses        int `json:"loses"`
		LosesWithout int `json:"losesWithout"`
		GamesPlayed  int `json:"gamesPlayed"`
		GamesWithout int `json:"gamesWithout"`
	} `json:"stats"`
}

Used when finding the past teams of a specific player ID

type PostError

type PostError struct {
	StatusCode int    `json:"statusCode"`
	Error      string `json:"error"`
	Message    []struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"message"`
}

An error that comes from POSTing (at least to /search/players. Message has varying fields, but the important ones are constant.

type RGL

type RGL struct {
	// contains filtered or unexported fields
}

The RGL type contains all endpoints as methods. Create one with rgl.DefaultRateLimit() or use RGL{rl: *rate.Limiter} or use RGL{} if you don't want to use the ratelimiter object at all (you will have to implement your own)

func DefaultRateLimit

func DefaultRateLimit() RGL

Create an RGL instance with a default rate limiter based on present ratelimits (2 calls per 1 second)>

func (*RGL) BulkPlayers

func (rgl *RGL) BulkPlayers(ids []string) ([]Player, error)

Search multiple IDs for RGL players

func (*RGL) GetBans

func (rgl *RGL) GetBans(take int, skip int) ([]BulkBan, error)

A paginated look at RGL bans. (Newest first). This is a historic record and includes expired bans, as far as I can tell.

func (*RGL) GetMatch

func (rgl *RGL) GetMatch(id int) (Match, error)

Get match by RGL Id

func (*RGL) GetPlayer

func (rgl *RGL) GetPlayer(steam64 string) (Player, error)

Get player by steam id

func (*RGL) GetPlayerTeamHistory

func (rgl *RGL) GetPlayerTeamHistory(id string) ([]PlayerTeamHistory, error)

Get a player's teams (past and present). Current teams have the Left field as ""

func (*RGL) GetSeason

func (rgl *RGL) GetSeason(id int) (Season, error)

Get season by RGL Id

func (*RGL) GetTeam

func (rgl *RGL) GetTeam(id int) (Team, error)

Get team by RGL Id

func (*RGL) SearchPlayers

func (rgl *RGL) SearchPlayers(alias string, take int, skip int) (SearchResults, error)

Search for players whose aliases contain the string. Take the first `take` results, skipping the first `skip`.

func (*RGL) SearchTeams

func (rgl *RGL) SearchTeams(partial string, take int, skip int) (SearchResults, error)

Bulk search for teams whose names or tags contain the partial string.

type SearchResults

type SearchResults struct {
	Results       []string `json:"results"` //A slice of Steam64 IDs (Steam64s for Players, RGL Team IDs for Teams)
	Count         int      `json:"int"`
	TotalHitCount int      `json:"totalHitCount"`
}

To check if this is empty, use len(SearchResults.Results) == 0 instead of equality checking == SearchResults{} (If you want to equality check the results of rgl.SearchPlayers, you'd have to use SearchResults{Results: make([]string, 0)}

type Season

type Season struct {
	Name    string   `json:"name"`
	Format  *string  `json:"formatName"`
	Region  *string  `json:"regionName"`
	Maps    []string `json:"maps"`
	Teams   []int    `json:"participatingTeams"`
	Matches []int    `json:"matchesPlayedDuringSeason"`
}

Toplevel endpoint for a season found by id

type Team

type Team struct {
	Id          int          `json:"teamId"`
	LinkedTeams []int        `json:"linkedTeams"`
	SeasonId    int          `json:"seasonId"`
	DivId       int          `json:"divisionId"`
	DivName     string       `json:"divisionName"`
	TeamLeader  string       `json:"teamLeader"`
	Created     string       `json:"createdAt"`
	Updated     string       `json:"updatedAt"`
	Tag         string       `json:"tag"`
	Name        string       `json:"name"`
	FinalRank   *int         `json:"finalRank"`
	Players     []TeamPlayer `json:"players"`
}

Toplevel endpoint for a team found by id

type TeamPlayer

type TeamPlayer struct {
	Name     string `json:"name"`
	SteamId  string `json:"steamId"`
	IsLeader bool   `json:"isLeader"`
	Joined   string `json:"joinedAt"`
}

Used in Team to represent at-a-glance information about the roster

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL