r6api

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 14 Imported by: 3

README

r6api

Disclaimer

  • I don't have the time to maintain this repo properly.
  • This project is just for fun.
  • I am a Golang beginner, be kind
  • Feel free to fork and do whatever you like with it.
  • I didn't have time to write tests, so use with caution!

Background information

Example usage

import (
	"os"
	"time"

	"github.com/rs/zerolog"
	"github.com/stnokott/r6api"
)

func main() {
	// setup
	writer := zerolog.ConsoleWriter{
		Out:           os.Stdout,
		TimeFormat:    time.RFC3339,
		PartsOrder:    []string{"time", "level", "name", "message"},
		FieldsExclude: []string{"name"},
	}
	logger := zerolog.New(writer).Level(zerolog.DebugLevel).With().Timestamp().Str("name", "R6API -").Logger()

	email := "<myubiemail>"
	password := "<myubipassword>"

	// create API instance
	a := r6api.NewR6API(email, password, logger)

	// resolve username to profile
	profile, err := a.ResolveUser("<myubiusername>")
	if err != nil {
		logger.Fatal().Err(err).Msg("error resolving user")
	}

	// get ranked history for profile with history depth of 2
	ranked, err := a.GetRankedHistory(profile, 2)
	if err != nil {
		logger.Fatal().Err(err).Msg("error getting ranked history")
	}
	// get most-recent ranked season
	r := ranked[1]

	metadata, err := a.GetMetadata()
	if err != nil {
		logger.Fatal().Err(err).Msg("error getting metadata")
	}

	// retrieve season slug for last ranked season
	seasonSlug := metadata.SeasonSlugFromID(r.SeasonID)
	if seasonSlug == "" {
		seasonSlug = "n/a"
	}
	// print info
	logger.Info().Str("season", seasonSlug).Int("kills", r.Kills).Int("deaths", r.Deaths).Send()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Profile

type Profile struct {
	Name      string
	ProfileID string
}

func (*Profile) MarshalZerologObject

func (p *Profile) MarshalZerologObject(e *zerolog.Event)

func (*Profile) ProfilePicURL

func (p *Profile) ProfilePicURL() string

type R6API added in v0.1.0

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

func NewR6API added in v0.1.0

func NewR6API(email string, password string, logger zerolog.Logger) *R6API

NewR6API creates a new instance with the provided login credentials and logger.

func (*R6API) GetMetadata added in v0.1.0

func (a *R6API) GetMetadata() (m *metadata.Metadata, err error)

GetMetadata retrieves information about seasons, i.e. season slug or MMR bounds. This is an expensive operation as it performs Javascript evaluations.

func (*R6API) GetRankedHistory added in v0.1.0

func (a *R6API) GetRankedHistory(profile *Profile, numSeasons uint8) (ranked.SkillHistory, error)

GetRankedHistory returns a list of stats for the last numSeasons past ranked seasons. The resulting list will be ordered historically, i.e. the most-recent season last.

func (*R6API) GetStats added in v0.1.0

func (a *R6API) GetStats(profile *Profile, season string, dst stats.Provider) error

GetStats retrieves statistics for a specific profile and season, loading the results into dst. dst needs to implement stats.Provider, the preconfigured providers can be found in the stats package.

func (*R6API) ResolveUser added in v0.1.0

func (a *R6API) ResolveUser(username string) (*Profile, error)

ResolveUser attempts to resolve the provided username to a Profile instance which can then be used for other requests.

Directories

Path Synopsis
types

Jump to

Keyboard shortcuts

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