2017 © Pedro Peláez
 

library lol-php-api-client

League of Legends PHP API Client

image

elogank/lol-php-api-client

League of Legends PHP API Client

  • Thursday, November 27, 2014
  • by Divi
  • Repository
  • 1 Watchers
  • 7 Stars
  • 65 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Since the October 1st 2014, a custom API is not fully allowed by the League of Legend's Terms of Use, only some API calls are allowed. More information : https://developer.riotgames.com


League of Legends PHP API Client

This client use the API server provided by : https://github.com/EloGank/lol-php-api, (*1)

Installation

From Composer

In the require key :, (*2)

``` json { "require": { "elogank/lol-php-api-client": "1.0.*@dev" } }, (*3)


Then, in a CLI window : php composer.phar update "elogank/php-lol-api" #### Composer what ? Ok, here a fast lesson about Composer. Composer is a PHP CLI dependency manager. Download Composer in your project root directory, here : https://getcomposer.org/download/ Then, you'll have a new file : `composer.phar`. Now create a `composer.json`, and read this brief documentation : https://getcomposer.org/doc/00-intro.md Finally, install this repository ! ## How to use The `Client` object need three parameters, and two as optionals : * `$host` the server host IP address * `$port` the server port * `$format` the default output format * `$throwException` (optional, default: true) if true, an `ApiException` will be throw on error and the response won't contain the first array level which contain "success" & "result"/"error" keys. * `$timeout` (optional, default: your php.ini "default_socket_timeout" configuration) the connection timeout, in second. In short : ``` php // Declare your client and the configuration $client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json'); // Do your API request try { $response = $client->send('EUW', 'summoner.summoner_existence', ['Foobar']); } catch (\EloGank\ApiClient\Exception\ApiException $e) { // error var_dump($e->getCause(), $e->getMessage()); }

The send() method have three parameters and one optional : * region it's the client region short name (EUW, NA, ...). Make sure there is a registered client for the selected region in your API ! * route the API route, in short it's the "controller_name.method_name" * parameters it's the route parameters, it's an array * format (optional) if you need a specific format for a specific route (see the API configuration documentation for available formats), (*4)

Example

This example is available in the file examples/index.php., (*5)

Note 1: use 192.168.100.10 instead of 127.0.0.1 if you using Virtual Machine for the API server.
Note 2: a ConnectionException can be thrown if there is a problem with the server (timeout or connection refused, for example). Be sure to handle this case by surrounding with a try/catch and set the timeout in the Client::__construct() when an API client timeout., (*6)

``` php // examples/index.php, (*7)

<?php, (*8)

require DIR . '/../vendor/autoload.php';, (*9)

// Good response, no error, with exception $client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json'); $response = $client->send('EUW', 'summoner.summoner_existence', ['Foobar']);, (*10)

var_dump($response);, (*11)

// Error response, with exception $client = null; $client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json');, (*12)

try { $response = $client->send('EUW', 'summoner.summoner_existence', ['Not_found_summoner']); } catch (\EloGank\ApiClient\Exception\ApiException $e) { var_dump($e->getCause(), $e->getMessage()); }, (*13)

// Good response, without exception $client = null; $client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json', false); $response = $client->send('EUW', 'summoner.summoner_existence', ['Foobar']);, (*14)

if ($response['success']) { var_dump($response['result']); } else { // catch error }, (*15)

// Error response, without exception // Good response, without exception $client = null; $client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json', false); $response = $client->send('EUW', 'summoner.summoner_existence', ['Not_found_summoner']);, (*16)

if ($response['success']) { // do some process } else { var_dump($response['error']); }, (*17)

// Request with timeout $client = null; $client = new \EloGank\ApiClient\Client('128.0.0.1', 8080, 'json', false, 1); $response = $client->send('EUW', 'summoner.summoner_existence', ['Not_found_summoner']);, (*18)

if ($response['success']) { // do some process } else { var_dump($response['error']); } ```, (*19)

The Versions

27/11 2014

dev-master

9999999-dev

League of Legends PHP API Client

  Sources   Download

The Requires

  • php >=5.4.0

 

by Sylvain Lorinet

api client lol league of legends lol api rtmp