equinox

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 14 Imported by: 1

README

equinox

FeaturesTodoUsageExampleAboutDisclaimer

Features

  • Riot APIs implemented:
    • Riot Account
    • League of Legends
    • Teamfight Tactics
    • Valorant
    • Legends of Runeterra
  • Data Dragon and Community Dragon (Incomplete)
  • Caching
  • Retry on 429 n times

Todo

  • More tests for the client
  • Rate limit
  • Improve DDragon/CDragon support
  • Maybe more logging

Usage

Get the library:

go get github.com/Kyagara/equinox

To access the diferent parts of the Riot Games API, create a new instance of the Equinox client:

client, err := equinox.NewClient("RIOT_API_KEY")

A client without a configuration comes with the default options:

cacheConfig := bigcache.DefaultConfig(4 * time.Minute)
config := &api.EquinoxConfig{
	Key: "RIOT_API_KEY", // The API Key provided as a parameter.
	LogLevel: api.WARN_LOG_LEVEL, // The logging level, NOP_LOG_LEVEL disables logging.
	HTTPClient: &http.Client{Timeout: 15 * time.Second}, // http.Client used internally.
	Cache: cache.NewBigCache(cacheConfig), // The default client uses BigCache with an eviction time of 4 minutes.
	Retry: 1, // Retries a request n times if the API returns a 429 response.
}

A custom Client can be created using equinox.NewClientWithConfig(), requires an &api.EquinoxConfig{} struct.

A different storage can be provided to the client using cache.NewRedis() or cache.NewBigCache(), passing nil in config.Cache disables caching.

Now you can access different games endpoints by their abbreviations. For example:

// This method uses a lol.PlatformRoute. Can be accessed with a Development key.
summoner, err := client.LOL.SummonerV4.ByPUUID(lol.BR1, "summoner_puuid")

// This method uses a api.RegionalRoute. Can be accessed with a Development key.
match, err := client.LOL.MatchV5.ByID(api.AMERICAS, "match_id")

// This method uses a api.RegionalRoute. Can be accessed with a Development key.
account, err := client.Riot.AccountV1.ByPUUID(api.AMERICAS, "puuid")

// This method uses a val.PlatformRoute. May not be available in your policy.
matches, err := client.VAL.MatchV1.Recent(val.BR, "competitive")

Example

package main

import (
	"fmt"

	"github.com/Kyagara/equinox"
	"github.com/Kyagara/equinox/clients/lol"
)

func main() {
	client, err := equinox.NewClient("RIOT_API_KEY")
	if err != nil {
		fmt.Println("error creating client: ", err)
		return
	}
	// Get this week's champion rotation.
	rotation, err := client.LOL.ChampionV3.Rotation(lol.BR1)
	if err != nil {
		fmt.Println("error retrieving champion rotation: ", err)
		return
	}
	fmt.Printf("%+v\n", rotation)
	// &{FreeChampionIDs:[17 43 56 62 67 79 85 90 133 145 147 157 201 203 245 518]
	// FreeChampionIDsForNewPlayers:[222 254 427 82 131 147 54 17 18 37]
	// MaxNewPlayerLevel:10}
}

About

This is my first time developing and publishing an API client, I am constantly changing the project as I test and learn new things, please, check the commits for any breaking changes.

These projects helped me learn a lot:

Disclaimer

equinox isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing Riot Games properties. Riot Games, and all associated properties are trademarks or registered trademarks of Riot Games, Inc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig added in v0.14.1

func DefaultConfig(key string) (*api.EquinoxConfig, error)

Returns the default Equinox config with a provided key.

  • `LogLevel` : api.WARN_LOG_LEVEL
  • `HTTPClient` : http.Client with timeout of 15 seconds
  • `Retry` : Maximum amount of retries allowed, defaults to 1
  • `Cache` : BigCache with TTL of 4 minutes

func NewTestEquinoxConfig added in v0.18.0

func NewTestEquinoxConfig() *api.EquinoxConfig

Creates an EquinoxConfig for tests.

  • `LogLevel` : api.DEBUG_LOG_LEVEL
  • `HTTPClient` : http.Client{}
  • `Retry` : 0
  • `Cache` : &cache.Cache{TTL: 0}

Types

type Equinox

type Equinox struct {
	Cache   *cache.Cache
	DDragon *ddragon.DDragonClient
	CDragon *cdragon.CDragonClient
	Riot    *riot.RiotClient
	LOL     *lol.LOLClient
	TFT     *tft.TFTClient
	VAL     *val.VALClient
	LOR     *lor.LORClient
}

func NewClient

func NewClient(key string) (*Equinox, error)

Creates a new Equinox client with the default configuration

func NewClientWithConfig added in v0.3.0

func NewClientWithConfig(config *api.EquinoxConfig) (*Equinox, error)

Creates a new Equinox client using a custom configuration.

Directories

Path Synopsis
Package used to share common constants and structs.
Package used to share common constants and structs.
Cache package to provide an interface to interact with stores like BigCache and Redis.
Cache package to provide an interface to interact with stores like BigCache and Redis.
clients
cdragon
This package is used to interact with CDragon endpoints.
This package is used to interact with CDragon endpoints.
ddragon
This package is used to interact with DDragon endpoints.
This package is used to interact with DDragon endpoints.
lol
This package is used to interact with all League of Legends endpoints.
This package is used to interact with all League of Legends endpoints.
lor
This package is used to interact with all Legends of Runeterra endpoints.
This package is used to interact with all Legends of Runeterra endpoints.
riot
This package is used to interact with all Riot Games endpoints.
This package is used to interact with all Riot Games endpoints.
tft
This package is used to interact with all Teamfight Tactics endpoints.
This package is used to interact with all Teamfight Tactics endpoints.
val
This package is used to interact with all VALORANT endpoints.
This package is used to interact with all VALORANT endpoints.
codegen module
test
integration
This package only contains integration tests and are meant to be run manually.
This package only contains integration tests and are meant to be run manually.

Jump to

Keyboard shortcuts

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