goriot

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT

README

Riot Games SDK for Go

goriot is a SDK written in Go to facilitate the use of Riot Games API. Currently the SDK implements the League of Legends, Live Client Data and Data Dragon API.

Installation

$ go get github.com/JoaoDanielRufino/goriot

Usage

To use League of Legends API, you need to provide your Riot Games API Key. You can generate a development key by accessing developer.riotgames.com

The default region of the SDK is Brazil (br1).

If you only want to use Live Client Data or Data Dragon, the API Key is not required.

Basic example
package main

import (
	"encoding/json"
	"fmt"

	"github.com/JoaoDanielRufino/goriot/riot"
	"github.com/JoaoDanielRufino/goriot/riot/lol"
)

func handleError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	client, err := lol.NewClient(lol.WithApiKey("API KEY"), lol.WithRegion(riot.RegionKorea))
	handleError(err)

	res, err := client.GetSummonerByName("Hide on bush")
	handleError(err)

	pretty, err := json.MarshalIndent(res, "", "  ")
	handleError(err)

	fmt.Println(string(pretty))
}
Live Client Data usage

To safely use Live Client Data API, it's recommended to download the root certificate to validate the HTTPS requests. You can find the certificate on developer.riotgames.com/docs/lol#game-client-api_root-certificatessl-errors

But if you wish, you can omit the lol.WithCertificate() option to use Live Client Data API without the certificate.

package main

import (
	"encoding/json"
	"fmt"

	"github.com/JoaoDanielRufino/goriot/riot"
	"github.com/JoaoDanielRufino/goriot/riot/lol"
)

func handleError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	client, err := lol.NewClient(lol.WithCertificate("./riotgames.pem"))
	handleError(err)

	res, err := client.LiveClientData.AllGameData()
	handleError(err)

	pretty, err := json.MarshalIndent(res, "", "  ")
	handleError(err)

	fmt.Println(string(pretty))
}
Data Dragon usage
package main

import (
	"encoding/json"
	"fmt"

	"github.com/JoaoDanielRufino/goriot/riot"
	"github.com/JoaoDanielRufino/goriot/riot/lol"
)

func handleError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	client, err := lol.NewClient()
	handleError(err)

	res, err := client.DataDragon.GetChampions()
	handleError(err)

	pretty, err := json.MarshalIndent(res, "", "  ")
	handleError(err)

	fmt.Println(string(pretty))
}

Directories

Path Synopsis
lol

Jump to

Keyboard shortcuts

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