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 identifying your application (recommended)
$spigotClient->setUserAgent("my-app/1.0.0 ([email protected])");
use Aternos\SpigotApi\Configuration;
use GuzzleHttp\Client;
$spigotClient = new SpigotAPIClient(new Configuration(), new Client(["timeout" => 10]));
// or
$spigotClient->setHttpClient(new Client(["timeout" => 10]));
use Aternos\SpigotApi\Client\ProjectOrder;
use Aternos\SpigotApi\Client\SortDirection;
$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;
}
// list the most downloaded projects
// the order is kept when navigating with getNextPage() / getPreviousPage()
$projects = $spigotClient->listProjects(1, ProjectOrder::DOWNLOAD_COUNT, SortDirection::DESC);
use Aternos\SpigotApi\Client\Category;
use Aternos\SpigotApi\Client\ProjectOrder;
use Aternos\SpigotApi\Client\SortDirection;
$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;
}
// list the most recently updated projects in a category
$projects = $spigotClient->listProjectsForCategory(Category::SPIGOT, 1, ProjectOrder::LAST_UPDATE, SortDirection::DESC);
// 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();
use Aternos\SpigotApi\Client\SortDirection;
use Aternos\SpigotApi\Client\VersionOrder;
// get a specific project (by numeric id)
$project = $spigotClient->getProject(2);
// fetch the versions from the API as a PaginatedVersionList (sends a request)
$versions = $project->fetchVersions();
// fetch the newest versions first
$versions = $project->fetchVersions(1, VersionOrder::POST_DATE, SortDirection::DESC);
// 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);
// fetch the projects from the API as a PaginatedAuthorProjectList (sends a request)
$projects = $author->fetchProjects();
// list all projects from Luck
$projects = $spigotClient->getAuthorProjects(100356);
foreach ($projects as $project) {
echo $project->getData()->getTitle() . PHP_EOL;
}
use Aternos\SpigotApi\Client\SortDirection;
use Aternos\SpigotApi\Client\VersionOrder;
$versions = $spigotClient->getProjectVersions(2);
foreach ($versions as $version) {
echo $version->getData()->getTitle() . PHP_EOL;
}
// list the newest versions first
$versions = $spigotClient->getProjectVersions(2, 1, VersionOrder::POST_DATE, SortDirection::DESC);
// get a specific version (by numeric id)
$version = $spigotClient->getVersion(352711);
// get the ID of the project this version belongs to
$projectId = $version->getProjectId();
// fetch the project from the API as a Project wrapper (sends a request)
$project = $version->fetchProject();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.