PHP code example of aternos / spigot-api

1. Go to this page and download the library: Download aternos/spigot-api 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/ */

    

aternos / spigot-api example snippets



use Aternos\SpigotApi\Client\SpigotAPIClient;

// create an API client (main entry point)
$spigotClient = new SpigotAPIClient();

// set a user agent (recommended)
$spigotClient->setUserAgent('aternos/php-spigot-api-example');

$projects = $spigotClient->listProjects(1);

foreach ($projects as $project) {
    // wrappers expose underlying model via getData()
    echo $project->getData()->getTitle() . PHP_EOL;
}

$projects = $projects->getNextPage();

foreach ($projects as $project) {
    echo $project->getData()->getTitle() . PHP_EOL;
}

$projects = $spigotClient->listProjectsForCategory(Category::SPIGOT, 1);

foreach ($projects as $project) {
    // wrappers expose underlying model via getData()
    echo $project->getData()->getTitle() . PHP_EOL;
}

$projects = $projects->getNextPage();

foreach ($projects as $project) {
    echo $project->getData()->getTitle() . PHP_EOL;
}

// get a specific project (by numeric id)
$project = $spigotClient->getProject(2);

// get data from the wrapper
$id = $project->getData()->getId();
$title = $project->getData()->getTitle();
$description = $project->getData()->getDescription();

// get a specific project (by numeric id)
$project = $spigotClient->getProject(2);

// get versions as a PaginatedVersionList
$versions = $project->getVersions();

// get the author
$author = $project->getAuthor();

$author = $spigotClient->getAuthor(1);

// get data from the wrapper
$id = $author->getData()->getId();
$username = $author->getData()->getUsername();
$resources = $author->getData()->getResourceCount();
$identities = $author->getData()->getIdentities();
$avatarUrl = $author->getData()->getAvatar();
$activity = $author->getData()->getLastActivity();

$author = $spigotClient->findAuthor("md_5");

// get data from the wrapper
$id = $author->getData()->getId();
$username = $author->getData()->getUsername();
$resources = $author->getData()->getResourceCount();
$identities = $author->getData()->getIdentities();
$avatarUrl = $author->getData()->getAvatar();
$activity = $author->getData()->getLastActivity();

// get a specific author (by numeric id)
$author = $spigotClient->getAuthor(1);

// get projects as a PaginatedProjectList
$projects = $author->getProjects();

// list all projects from Luck
$projects = $spigotClient->getAuthorProjects(100356);
foreach ($projects as $project) {
    echo $project->getData()->getTitle() . PHP_EOL;
}

$versions = $spigotClient->getProjectVersions(2);
foreach ($versions as $version) {
    echo $version->getData()->getTitle() . PHP_EOL;
}

$version = $spigotClient->getVersion(352711);
echo $version->getData()->getTitle() . PHP_EOL;
echo $version->getData()->getMessage() . PHP_EOL;

// get a specific version (by numeric id)
$version = $spigotClient->getVersion(352711);

// get the ID of the project this version belongs to
$projectId = $version->getProjectId();

// get the project as a Project wrapper
$project = $version->getProject();