PHP code example of joebocock / chess-api-php

1. Go to this page and download the library: Download joebocock/chess-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joebocock / chess-api-php example snippets



use JoeBocock\ChessApi\Chess;

$client = new Chess();

/** @var JoeBocock\ChessApi\Entities\PlayerProfile */
$playerProfile = $client->playerProfile('gothamchess');

echo $playerProfile->name;
// 'Levy Rozman'



use GuzzleHttp\Client;
use JoeBocock\ChessApi\Chess;

$client = new Chess(
    new Client([
        // configuration...
    ])
);



use JoeBocock\ChessApi\Chess;
use JoeBocock\ChessApi\Requests\PlayerProfileRequest;

$client = new Chess();

$request = new PlayerProfileRequest();

$request->setUsername('lud-skywalker');

$response = $client->send($request);



use JoeBocock\ChessApi\Chess;
use JoeBocock\ChessApi\Exceptions\ChessRequestException;
use JoeBocock\ChessApi\Exceptions\ChessResponseException;

$client = new Chess();

try {
    $playerProfile = $client->playerProfile('gothamchess');
} catch (ChessRequestException|ChessResponseException|\InvalidArgumentException $e) {
    // handle...
}

shell
composer