@@ -5,8 +5,10 @@ This client is a combination of code generated by [OpenAPI Generator](https://op
55from the Hangar OpenAPI specification and some wrappers around it to improve the usability.
66
77The generated code can be found in ` src/Api ` and ` src/Model ` . It is recommended to use the wrappers in
8- ` src/Client ` instead. The wrappers provide methods to fetch related data from the API, the data returned
9- by the API is available through ` getData() ` .
8+ ` src/Client ` instead. The wrappers extend the generated models, so the data returned by the API is available
9+ through the getters of the wrapper, e.g. ` $project->getName() ` . They also provide methods to fetch related data
10+ from the API. These methods start with ` fetch ` , e.g. ` $project->fetchVersions() ` , and send a request each time
11+ they are called. Only ` fetchProject() ` of ` Version ` and ` ProjectPage ` keeps the project once it is known.
1012
1113## Requirements
1214- PHP 8.4 or newer
@@ -92,7 +94,7 @@ you can use it like an array. It also has a `getResults()` method which returns
9294$projects = $hangarClient->getProjects();
9395
9496foreach ($projects as $project) {
95- echo $project->getData()-> getName() . PHP_EOL;
97+ echo $project->getName() . PHP_EOL;
9698}
9799
98100if ($projects->hasNextPage()) {
@@ -130,7 +132,7 @@ $projects = $hangarClient->getProjects($options);
130132``` php
131133// get a project by its slug or id
132134$project = $hangarClient->getProject("mclogs");
133- echo $project->getData()-> getName() . ": " . $project->getData() ->getStats()->getDownloads() . " downloads" . PHP_EOL;
135+ echo $project->getName() . ": " . $project->getStats()->getDownloads() . " downloads" . PHP_EOL;
134136
135137// get the project a file belongs to by the SHA-256 hash of the file
136138$project = $hangarClient->getProjectByVersionHash(hash_file("sha256", "/path/to/plugin.jar"));
@@ -142,30 +144,30 @@ The `Project` wrapper provides methods to fetch related data:
142144$project = $hangarClient->getProject("mclogs");
143145
144146// versions of the project (paginated), optionally filtered by channel and platform
145- $versions = $project->getVersions ();
146- $versions = $project->getVersions ("Release", Platform::PAPER);
147+ $versions = $project->fetchVersions ();
148+ $versions = $project->fetchVersions ("Release", Platform::PAPER);
147149
148150// a specific version by its name
149- $version = $project->getVersion ("3.3.4");
151+ $version = $project->fetchVersion ("3.3.4");
150152
151153// the owner of the project
152- $owner = $project->getOwner ();
154+ $owner = $project->fetchOwner ();
153155
154156// members, stargazers and watchers of the project (paginated)
155- $members = $project->getMembers ();
156- $stargazers = $project->getStarGazers ();
157- $watchers = $project->getWatchers ();
157+ $members = $project->fetchMembers ();
158+ $stargazers = $project->fetchStarGazers ();
159+ $watchers = $project->fetchWatchers ();
158160
159161// pages of the project
160- $mainPage = $project->getMainPage ();
161- $page = $project->getPage ("config");
162+ $mainPage = $project->fetchMainPage ();
163+ $page = $project->fetchPage ("config");
162164```
163165
164166The daily stats of a project require an API key of a member of the project:
165167``` php
166168// stats since the project was created, or for a specific period
167- $stats = $project->getDailyStats ();
168- $stats = $project->getDailyStats (new DateTime("2026-01-01"), new DateTime("2026-02-01"));
169+ $stats = $project->fetchDailyStats ();
170+ $stats = $project->fetchDailyStats (new DateTime("2026-01-01"), new DateTime("2026-02-01"));
169171
170172foreach ($stats as $date => $dayStats) {
171173 echo $date . ": " . $dayStats->getDownloads() . " downloads, " . $dayStats->getViews() . " views" . PHP_EOL;
@@ -176,8 +178,8 @@ foreach ($stats as $date => $dayStats) {
176178Some methods, e.g. the projects a user has starred, return ` CompactProject ` objects. They contain less data,
177179but provide the same methods as ` Project ` . You can fetch the full project:
178180``` php
179- foreach ($hangarClient->getUser("Aternos")->getStarredProjects () as $compactProject) {
180- $project = $compactProject->getProject ();
181+ foreach ($hangarClient->getUser("Aternos")->fetchStarredProjects () as $compactProject) {
182+ $project = $compactProject->fetchProject ();
181183}
182184```
183185
@@ -202,12 +204,12 @@ $latestRelease = $hangarClient->getLatestReleaseVersion("mclogs");
202204$latestVersion = $hangarClient->getLatestVersion("mclogs", "Release");
203205
204206// get the project of a version
205- $project = $version->getProject ();
207+ $project = $version->fetchProject ();
206208```
207209
208210The daily stats of a version require an API key:
209211``` php
210- $stats = $version->getDailyStats ();
212+ $stats = $version->fetchDailyStats ();
211213
212214foreach ($stats as $date => $dayStats) {
213215 echo $date . ": " . $dayStats->getTotalDownloads() . " downloads" . PHP_EOL;
@@ -222,7 +224,7 @@ use Aternos\HangarApi\Client\Options\UserSearch\UserSortField;
222224
223225// get a user by name
224226$user = $hangarClient->getUser("Aternos");
225- echo $user->getData()-> getName() . ": " . $user->getData() ->getProjectCount() . " projects" . PHP_EOL;
227+ echo $user->getName() . ": " . $user->getProjectCount() . " projects" . PHP_EOL;
226228
227229// search for users (paginated)
228230$users = $hangarClient->getUsers(new UserSearchOptions()->setQuery("aternos")->setSort(UserSortField::NAME));
@@ -232,14 +234,14 @@ $staff = $hangarClient->getStaff(sort: StaffSortField::ROLES);
232234$authors = $hangarClient->getAuthors("aternos");
233235
234236// get the projects of a user (paginated)
235- $projects = $user->getProjects ();
237+ $projects = $user->fetchProjects ();
236238
237239// get the projects a user has starred or is watching (paginated)
238- $starredProjects = $user->getStarredProjects ();
239- $watchedProjects = $user->getWatchedProjects ();
240+ $starredProjects = $user->fetchStarredProjects ();
241+ $watchedProjects = $user->fetchWatchedProjects ();
240242
241243// get the projects a user has pinned on their profile
242- $pinnedProjects = $user->getPinnedProjects ();
244+ $pinnedProjects = $user->fetchPinnedProjects ();
243245```
244246
245247## Project Pages
0 commit comments