The MalPHPhite API Wrapper

MalPHPhite is a small PHP API Wrapper for the League of Legends API. This library is especially simple as you don't need any special knowledge nor other frameworks like composer to run this library: All you need is to download the "library.php" file and include it in your script.

Let's get started

First, download the latest file of the library from the GitHub and deploy it on your webserver. Second, include the library on the top of your PHP script.

<?php

   include_once("/path/to/library.php"); # include the library. use "./library.php" if the library is in the same folder as the PHP script

?>

Next, we create a new instance of the LeagueOfLegendsAPI class. The class supports several arguments in its constructor to allow some modification on how the library should run. Let's create an instance first

<?php

   include_once("/path/to/library.php");

   $api = new LeagueOfLegendsAPI("API-KEY", "na", true, "/var/tmp");

?>

To take a look at the arguments:

  • "API-KEY" is required and your API key for the Riot Games API.
  • "NA" is the region/platform and also required. If your region is invalid, the script will throw an error.
  • True is a boolean and rules whether caching is enabled or not. Caching is enabled by default and therefore this field is not required.
  • "/var/tmp" is the path of the cache folder. The script does not clear the cache after it expired, so set up something like a cronjob to clear the folder from time to time. This field is also not required, the default folder is the /tmp directory.

The first request

After we got everything set up, we can start executing requests. IntelliSense in Visual Studio Code should already show you which methods are available, otherwise there is some documentation on GitHub. If you want to get the rank of a summoner, we need their encrypted summoner id first by using the getSummonerByName method.

<?php

   include_once("/path/to/library.php");

   $api = new LeagueOfLegendsAPI("API-KEY", "na", true, "/var/tmp");

   $summoner = $api->getSummonerByName("KatEvolved"); # get the summoner first
   $rank = $api->getRankBySummoner($summoner, true); # we can pass the whole summoner response to this function. 
   # The true in the getRankBySummoner method beautifies the result. 

?>

Error Handling

The library throws error if the usage is wrong. If the Riot Games API throws errors to the library, the library returns an integer as a return value.

$summoner = $api->getSummonerByName("THIS SUMMONER DOES NOT EXIST");
# returns 404

# possible catches are
if(gettype($summoner) === "integer") {
   echo "the requested summoner does not exist";
}

Note

Use this library at your own risk. Rate limiting is not supported. If you found an error within this library, please report it on GitHub or PR a change yourself.

The MalPHPhite API Wrapper
DarkIntaqt
DarkIntaqt
Published
Edited

©2020 - 2024

DarkIntaqt

DarkIntaqt

HomeAboutBlog