Download the PHP package aternos/hangar-api without Composer
On this page you can find all versions of the php package aternos/hangar-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hangar-api
Aternos/php-hangar-api
An API client for the Hangar API written in PHP.
This client is a combination of code generated by OpenAPI Generator from the Hangar OpenAPI specification 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. The wrappers extend the generated models, so the data returned by the API is available
through the getters of the wrapper, e.g. $project->getName(). They also provide methods to fetch related data
from the API. These methods start with fetch, e.g. $project->fetchVersions(), and send a request each time
they are called. Only fetchProject() of Version and ProjectPage keeps the project once it is known.
Requirements
- PHP 8.4 or newer
- PHP extensions: curl, json, mbstring
Installation
Install the package via composer:
Usage
The main entry point for the API is the HangarAPIClient class.
User Agent
It is recommended to set a user agent that identifies your application, ideally including contact information.
If you don't set a user agent, the client sends its own user agent including the installed version,
e.g. aternos/php-hangar-api/6.0.0. A user agent set with setUserAgent() replaces it.
Authentication
Most endpoints are public. Some endpoints (e.g. the daily stats of projects and versions or editing pages) require an API key, which you can create in your account settings. If an API key is set, it is used for all requests. The client exchanges it for a JWT automatically.
You can check whether the API key has certain permissions, optionally for a specific project:
Error Handling
All methods that send a request throw an Aternos\HangarApi\ApiException if the request fails.
The exception code is the HTTP status code of the response.
It is also thrown if a required permission is missing, e.g. when requesting daily stats without an API key.
Custom HTTP Client or Configuration
You can pass your own Guzzle client, e.g. to set timeouts or add middlewares,
and your own Aternos\HangarApi\Configuration.
Each client creates its own configuration if none is passed, so changes to Configuration::getDefaultConfiguration()
do not affect the client. A configuration passed to the client is used as is, so set your user agent on it.
Paginated Lists
Most methods return a paginated list (Aternos\HangarApi\Client\List\PaginatedList) which contains the results
on the current page and methods to navigate to the next and previous page. The list implements Iterator,
ArrayAccess and Countable so you can use it like an array. It also has a getResults() method which returns the underlying array of results.
Projects
Searching for Projects
You can search for a query, apply filters, change the sort order and set the page size. All options are optional and can be combined.
Fetching Projects
Additional Project Data
The Project wrapper provides methods to fetch related data:
The daily stats of a project require an API key of a member of the project:
Compact Projects
Some methods, e.g. the projects a user has starred, return CompactProject objects. They contain less data,
but provide the same methods as Project. You can fetch the full project:
Versions
The daily stats of a version require an API key:
Users
Project Pages
Editing pages requires an API key with the edit_page permission for the project:
Development
Updating the Generated Code
Install the OpenAPI Generator and run:
All versions of hangar-api with dependencies
composer-runtime-api Version ^2.0
ext-curl Version *
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.15.2 || ^8.2
guzzlehttp/psr7 Version ^2.12.3 || ^3.1