An API client for the Poggit API written in PHP. This client is a combination of code generated by OpenAPI Generator and some wrappers around it to improve the usability.
The generated code can be found in src/Api
and src/Model
. It is recommended
to use the Wrappers in src/Client
instead of the generated code.
Install the package via composer:
composer require aternos/poggit-api
The main entry point for the API is the PoggitAPIClient
class.
<?php
use Aternos\PoggitApi\Client\PoggitAPIClient;
// create an API client. This is the main entry point for the API
$poggitClient = new PoggitAPIClient();
// set a user agent (recommended)
$poggitClient->setUserAgent('aternos/php-poggit-api-example');
The Poggit API does not seperate projects and versions. It only provides Release
objects which contain data about a project and a specific version. You can get a
list of releases for a project with the getReleases()
method.
$releases = $poggitClient->getReleases("poggit/project");
foreach ($releases as $release) {
echo $release->getData()->getName() . PHP_EOL;
}
Pagination is not supported by the Poggit API. The getReleases()
method will return
a list of all releases of all plugins by default.
You can filter the releases using search options:
use \Aternos\PoggitApi\Client\SearchOptions;
use \Aternos\PoggitApi\Model\State;
use \Aternos\PoggitApi\Model\CategoryId;
$searchOptions = new SearchOptions();
// Only get approved releases
$searchOptions->setMinStability(State::APPROVED);
// Only show versions of a specific project by name
$searchOptions->setName("AdminTrollV2");
// Only get a specific version of a project
$searchOptions->setName("AdminTrollV2")
->setVersion("1.2.1");
// Get releases in a certain category
$searchOptions->setCategory(CategoryId::ADMIN_TOOLS);
// Only show releases by a specific author
$searchOptions->setOwner("JavierLeon9966");
// Only get the latest version of every project
$searchOptions->setLatestOnly(true);
$releases = $poggitClient->getReleases($searchOptions);
You can get a specific release by its ID:
$release = $poggitClient->getRelease(1234);
You can get the latest release of a plugin by its name:
$release = $poggitClient->getLatestReleaseByPluginName("AdminTrollV2");
You can download a release by the project name and version:
$release = $poggitClient->downloadVersion("AdminTrollV2", "1.2.1");
Note
This method downloads the release to a new file in the current working directory. There is no option to specify a download location. Using the artifact URL from a release and downloading it with a HTTP client is recommended for more control over the download process.
You can get the hashes of a release by the project name and version:
$release = $poggitClient->getLatestReleaseByPluginName("AdminTrollV2");
$md5 = $release->getMD5Hash();
$sha1 = $release->getSHA1Hash();
The generated code can be updated by installing the openapi generator and running the following command:
openapi-generator-cli generate -c config.yaml