equinox

package module
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 16 Imported by: 1

README

equinox

UsageExampleTodoAbout

Features

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

equinox currently uses the proposed jsonv2 package, read more about it here.

Usage

Get the library:

go get github.com/Kyagara/equinox # or: go get github.com/Kyagara/equinox@master

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:

  • Key: The provided key.
  • LogLevel: zerolog.WarnLevel. zerolog.Disabled disables logging.
  • Retries: Retries a request n times if the API returns an error, defaults to 3.
  • HTTPClient: http.Client with a timeout of 15 seconds.
  • Cache: BigCache with an eviction time of 4 minutes.
  • RateLimit: Internal rate limiter.

A custom Client can be created using equinox.NewClientWithConfig().

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

You can disable rate limiting by passing nil in config.RateLimit, this can be useful if you have Equinox passing through a proxy that handles rate limiting.

See Cache and Rate limit for more details.

Using different endpoints:

// 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

For a slightly more advanced example, check out lol-match-crawler.

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}
}

Todo

  • Maybe create a custom BigCache config
  • More tests for the internal client and rate limit
  • Maybe implement custom HTTP traffic mocking, removing gock
  • Improve DDragon/CDragon support

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, this will change coming 1.0.0.

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` : zerolog.WarnLevel
  • `Retries` : Retry 3 times
  • `HTTPClient` : http.Client with timeout of 15 seconds
  • `Cache` : BigCache with TTL of 4 minutes
  • `RateLimit` : Internal rate limit

Types

type Equinox

type Equinox struct {
	Cache   *cache.Cache
	DDragon *ddragon.Client
	CDragon *cdragon.Client
	Riot    *riot.Client
	LOL     *lol.Client
	TFT     *tft.Client
	VAL     *val.Client
	LOR     *lor.Client
}

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 cache stores.
Cache package to provide an interface to interact with cache stores.
clients
cdragon
This package is used to interact with Community Dragon endpoints.
This package is used to interact with Community Dragon endpoints.
ddragon
This package is used to interact with Data Dragon endpoints.
This package is used to interact with Data Dragon 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