Skip to content

LeagueAPI: CLI support

Daniel Dolejška edited this page Feb 24, 2020 · 11 revisions

Version v3.1.0

This feature allows you to easily use this library in CLI mode. Below you can see general examples of library usage in console.

Options

Config file

This option is always required.

Option --config PATH (-c PATH) contains path to JSON configuration file. Configuration file contains JSON object containing settings to be passed to library when initializing it - it looks almost the same, as if you were using it normally in PHP.

Please see this wiki page for complete list of library's settings.

config.json

{
	"SET_KEY"		: "YOUR_API_KEY",
	"SET_REGION"		: "eune",
	"SET_INTERIM"		: true,
	"SET_CACHE_RATELIMIT"	: true
}

Output file

Option --output PATH (-o PATH) contains path to output file. Request result will be saved into this file instead of being output to stdout.

Extended format

Option --extend (-x) modifies format of the output - instead of only request result being returned additional information is also provided:

  • HTTP response headers (in headers)
  • Current API key limits (in limits)
  • Response data itself (in response)

New output format then looks like:

{
    "headers": {},
    "limits": {},
    "result": {},
}

Real example:

{
    "headers": {
        "Content-Type": "application\/json;charset=utf-8",
        "Date": "Mon, 24 Feb 2020  20:54:12 GMT",
        "Vary": "Accept-Encoding",
        "X-App-Rate-Limit": "20:1,100:120",
        "X-App-Rate-Limit-Count": "1:1,3:120",
        "X-Method-Rate-Limit": "1600:60",
        "X-Method-Rate-Limit-Count": "2:60",
        "X-Riot-Edge-Trace-Id": "2ea80fee-4357-4dda-b106-3cd1737527a7",
        "Content-Length": "299",
        "Connection": "keep-alive"
    },
    "limits": {
        "app": {
            "1": {
                "used": 1,
                "limit": 20,
                "expires": 1582577653
            },
            "120": {
                "used": 3,
                "limit": 100,
                "expires": 1582577772
            }
        },
        "method": {
            "60": {
                "used": 2,
                "limit": 1600,
                "expires": 1582577712
            }
        }
    },
    "result": {
        "id": "klbHI4JuYqcnAOqIrwOHMVQ-I94gQ3tHOaf1wFlr8L_u6to",
        "accountId": "FxvRRw0ysD-d225YklbrnDaij_sTGtdcMi7O8TBGgRNDIQ",
        "puuid": "Fg3oXC12fgUFmsL5KrKaxartmQCI437lsvHn2Mxn8NfsjMlkzRBi8iyAC_TGWsDmam6P4hjELYWtaA",
        "name": "I am TheKronnY",
        "profileIconId": 540,
        "revisionDate": 1582577312000,
        "summonerLevel": 158
    }
}

Output formatting

Option --pretty forces JSON output to be formatted before saving/printing it.

General usage

root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli command [arguments] [options]
  • command - name of the function you want to call (or namespace:command identifier).
  • arguments - are space separated parameters for invoked method. For more information regarding methods and their parameters see LeagueAPI.php file.
  • options - are options for the CLI itself.

Usage examples

Initial help

This command provides all the necessary information on CLI usage.

Console:

root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli help
root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli help command

If command is specified then command-specific help is shown.

Command list

List of all available commands and their namespaces can be printed out using:

Console:

root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli list
root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli list namespace

If namespace is specified then only commands from the specified namespace are shown. Available namespaces:

  • champion
  • champion-mastery
  • league
  • league-exp
  • match
  • spectator
  • static-data
  • status
  • summoner
  • third-party-code
  • tournament

Command usage

Library methods are invoked as follows (for full list of available methods see Command list section):

Console:

root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli summoner:get-by-name "I am TheKronnY" --config ~/path/to/cfg.json
root@localhost:~/riot-api/src/LeagueAPICLI# leagueapicli getSummonerByName "I am TheKronnY" --config ~/path/to/cfg.json

Result of successful request is valid JSON string (in specific cases it could be an integer, something else or nothing). Unsuccessful request results in termination of the script by raising corresponding exception.

More usage examples for LeagueAPICLI can be found here.