Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ $client->setUserAgent("my-app/1.0.0 (contact@example.com)");
**You need an API key to use this client.** If you're a third party you can read more
about how to get one [here](https://support.curseforge.com/en/support/solutions/articles/9000208346).

## Wrappers
Most methods return wrappers like `Game`, `Mod` or `File`. They extend the generated models in `src/Model`,
so all getters of the models can be used directly, e.g. `$mod->getName()`.
Methods of the wrappers that send a request to the API start with `fetch`, e.g. `$mod->fetchFiles()`.

## Paginated Lists
Most methods return a paginated list containing a list of results on the current page and methods to
navigate to the next and previous page. The paginated list implements `Iterator`, `ArrayAccess` and `Countable` so
Expand Down Expand Up @@ -60,24 +65,24 @@ A game contains various different version types, you can fetch them like this:
```php
$versionTypes = $client->getGameVersionTypes(432);
// or
$versionTypes = $game->getVersionTypes();
$versionTypes = $game->fetchVersionTypes();
```
Since this endpoint isn't paginated, it returns an array instead of a paginated list.

You can also fetch the versions of a specific version type:
```php
$versions = $client->getGameVersionTypeVersions(432, 68441);
$versions = $client->getGameVersionsByType(432, 68441);
// or
$versionType = $versionTypes[0];
$versions = $versionType->getVersions();
$versions = $versionType->fetchVersions();
```
For example: 68441 is the mod loader selection for Minecraft.

You can also get all versions for all version types of a game:
```php
$versions = $client->getGameVersions(432);
// or
$versions = $game->getVersions();
$versions = $game->fetchVersions();
```

### Game Categories
Expand All @@ -87,22 +92,22 @@ You can fetch them like this:
```php
$categoryClasses = $client->getCategories(432);
// or
$categoryClasses = $game->getCategories();
$categoryClasses = $game->fetchCategories();
```
Note that this will return both, category classes AND categories.

If you want to get only the category classes you can set the parameter `onlyClasses` to `true`:
```php
$categoryClasses = $client->getCategories(432, null, true);
// or
$categoryClasses = $game->getCategories(null, true);
$categoryClasses = $game->fetchCategories(null, true);
```

You can fetch categories in a class using the parameter `classId`:
```php
$categories = $client->getCategories(432, 6);
// or
$categories = $game->getCategories(6);
$categories = $game->fetchCategories(6);
```

## Mods
Expand All @@ -118,7 +123,7 @@ You can also get a list of featured mods for a game:
```php
$mods = $client->getFeaturedMods(432);
// or
$mods = $game->getFeaturedMods();
$mods = $game->fetchFeaturedMods();

$featured = $mods->getFeatured();
$popular = $mods->getPopular();
Expand All @@ -136,13 +141,13 @@ $mods = $client->getMods([420561, 278568, 715033]);

You can also fetch the HTML for mod descriptions:
```php
$description = $mod->getDescription();
$description = $mod->fetchDescription();
```

### Mod Files
To fetch mod files use the method `getFiles()`:
To fetch mod files use the method `fetchFiles()`:
```php
$files = $mod->getFiles();
$files = $mod->fetchFiles();
```
It optionally takes a ModFilesOptions object as a parameter:
```php
Expand Down
8 changes: 5 additions & 3 deletions src/Client/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public function __construct(

/**
* Search mods in this category
* This sends a request to the CurseForge API every time it is called.
* @param ModSearchOptions|null $options
* @return PaginatedModList
* @throws ApiException
*/
public function getMods(?ModSearchOptions $options = null): PaginatedModList
public function fetchMods(?ModSearchOptions $options = null): PaginatedModList
{
if ($options === null) {
$options = new ModSearchOptions($this->getGameId());
Expand All @@ -39,11 +40,12 @@ public function getMods(?ModSearchOptions $options = null): PaginatedModList
}

/**
* Get the game of this category
* Fetch the game of this category
* This sends a request to the CurseForge API every time it is called.
* @return Game
* @throws ApiException
*/
public function getGame(): Game
public function fetchGame(): Game
{
return $this->client->getGame($this->getGameId());
}
Expand Down
15 changes: 9 additions & 6 deletions src/Client/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public function __construct(
}

/**
* Get the server pack file for this version (if it exists)
* Fetch the server pack file for this version (if it exists)
* This sends a request to the CurseForge API every time it is called.
* @return File|null
* @throws ApiException
*/
public function getServerPack(): ?File
public function fetchServerPack(): ?File
{
if (!$this->getServerPackFileId()) {
return null;
Expand All @@ -30,24 +31,26 @@ public function getServerPack(): ?File
}

/**
* Get the changelog of this file
* Fetch the changelog of this file
* This sends a request to the CurseForge API every time it is called.
* @param bool|null $raw Get raw changelog without things like external link redirects
* @param bool|null $stripped Get the changelog with all HTML tags removed
* @param bool|null $markup
* @return string
* @throws ApiException
*/
public function getChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $markup = null): string
public function fetchChangelog(?bool $raw = null, ?bool $stripped = null, ?bool $markup = null): string
{
return $this->client->getModFileChangelog($this->getModId(), $this->getId(), $raw, $stripped, $markup);
}

/**
* Get the mod of this file
* Fetch the mod of this file
* This sends a request to the CurseForge API every time it is called.
* @return Mod
* @throws ApiException
*/
public function getMod(): Mod
public function fetchMod(): Mod
{
return $this->client->getMod($this->getModId());
}
Expand Down
27 changes: 17 additions & 10 deletions src/Client/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,55 @@ public function __construct(
}

/**
* Get all version types for this game
* Fetch all version types for this game
* This sends a request to the CurseForge API every time it is called.
* @return GameVersionType[]
* @throws ApiException
*/
public function getVersionTypes(): array
public function fetchVersionTypes(): array
{
return $this->client->getGameVersionTypes($this->getId());
}

/**
* Get all versions for each version type of this game
* Fetch all versions for each version type of this game
* This sends a request to the CurseForge API every time it is called.
* @return GameVersionsByTypeV2[]
* @throws ApiException
*/
public function getVersions(): array
public function fetchVersions(): array
{
return $this->client->getGameVersions($this->getId());
}

/**
* Get all versions of a version type of this game
* Fetch all versions of a version type of this game
* This sends a request to the CurseForge API every time it is called.
* @param int $versionTypeId
* @return GameVersionsByTypeV2[]
* @throws ApiException
*/
public function getGameVersionsByType(int $versionTypeId): array
public function fetchGameVersionsByType(int $versionTypeId): array
{
return $this->client->getGameVersionsByType($this->getId(), $versionTypeId);
}

/**
* Fetch the categories of this game
* This sends a request to the CurseForge API every time it is called.
* @param int|null $classId The ID of the category class you want to query categories for (e.g. 5 for plugins or 6 for mods)
* @param bool|null $classesOnly only return category classes (e.g. plugins or mods).
* @return array
* @throws ApiException
*/
public function getCategories(?int $classId = null, ?bool $classesOnly = null): array
public function fetchCategories(?int $classId = null, ?bool $classesOnly = null): array
{
return $this->client->getCategories($this->getId(), $classId, $classesOnly);
}

/**
* Search for mods
* Search for mods in this game
* This sends a request to the CurseForge API every time it is called.
* @param ModSearchOptions|null $options
* @return PaginatedModList
* @throws ApiException
Expand All @@ -77,14 +83,15 @@ public function searchMods(?ModSearchOptions $options = null): PaginatedModList
}

/**
* Get all featured mods for this game
* Fetch all featured mods for this game
* This sends a request to the CurseForge API every time it is called.
* @param int[] $excludedModIds
* @param int|null $gameVersionTypeId
* @param bool|null $clientCompatible
* @return FeaturedMods
* @throws ApiException
*/
public function getFeaturedMods(array $excludedModIds = [], ?int $gameVersionTypeId = null, ?bool $clientCompatible = null): FeaturedMods
public function fetchFeaturedMods(array $excludedModIds = [], ?int $gameVersionTypeId = null, ?bool $clientCompatible = null): FeaturedMods
{
return $this->client->getFeaturedMods($this->getId(), $excludedModIds, $gameVersionTypeId, $clientCompatible);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Client/GameVersionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ public function __construct(
}

/**
* Get all versions of this type
* Fetch all versions of this type
* This sends a request to the CurseForge API every time it is called.
* @return GameVersionsByTypeV2[]
* @throws ApiException
*/
public function getVersions(): array
public function fetchVersions(): array
{
return $this->client->getGameVersionsByType($this->getGameId(), $this->getId());
}

/**
* Get the game of this type
* Fetch the game of this type
* This sends a request to the CurseForge API every time it is called.
* @return Game
* @throws ApiException
*/
public function getGame(): Game
public function fetchGame(): Game
{
return $this->client->getGame($this->getGameId());
}
Expand Down
29 changes: 18 additions & 11 deletions src/Client/Mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,35 @@ public static function fromModels(CurseForgeAPIClient $client, array $models): a

/**
* Fetch the description of this mod as html
* This sends a request to the CurseForge API every time it is called.
* @param string|null $lang
* @return string|null
* @throws ApiException
*/
public function getDescription(?string $lang = null): ?string
public function fetchDescription(?string $lang = null): ?string
{
return $this->client->getModDescription($this->getId(), $lang);
}

/**
* Get the files of this mod
* Fetch the files of this mod
* This sends a request to the CurseForge API every time it is called.
* @param ModFilesOptions|null $options
* @return PaginatedFilesList
* @throws ApiException
*/
public function getFiles(?ModFilesOptions $options = null): PaginatedFilesList
public function fetchFiles(?ModFilesOptions $options = null): PaginatedFilesList
{
return $this->client->getModFiles($options ?? new ModFilesOptions($this->getId()));
}

/**
* Get game this mod belongs to
* Fetch the game this mod belongs to
* This sends a request to the CurseForge API every time it is called.
* @return Game
* @throws ApiException
*/
public function getGame(): Game
public function fetchGame(): Game
{
return $this->client->getGame($this->getGameId());
}
Expand All @@ -74,31 +77,35 @@ public function getPrimaryCategory(): ?Category
}

/**
* Get the category class of this mod
* Fetch the category class of this mod
* This sends a request to the CurseForge API every time it is called.
* @return Category
* @throws ApiException
*/
public function getCategoryClass(): Category
public function fetchCategoryClass(): Category
{
return $this->client->getCategory($this->getGameId(), $this->getClassId());
}

/**
* Get the main file of this mod
* Fetch the main file of this mod
* This sends a request to the CurseForge API every time it is called.
* @return File
* @throws ApiException
*/
public function getMainFile(): File
public function fetchMainFile(): File
{
return $this->getFile($this->getMainFileId());
return $this->fetchFile($this->getMainFileId());
}

/**
* Fetch a file of this mod
* This sends a request to the CurseForge API every time it is called.
* @param int $fileId
* @return File
* @throws ApiException
*/
public function getFile(int $fileId): File
public function fetchFile(int $fileId): File
{
return $this->client->getModFile($this->getId(), $fileId);
}
Expand Down
Loading
Loading