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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ use Aternos\SpigotApi\Client\VersionOrder;
// get a specific project (by numeric id)
$project = $spigotClient->getProject(2);

// get versions as a PaginatedVersionList
$versions = $project->getVersions();
// fetch the versions from the API as a PaginatedVersionList (sends a request)
$versions = $project->fetchVersions();

// get the newest versions first
$versions = $project->getVersions(1, VersionOrder::POST_DATE, SortDirection::DESC);
// fetch the newest versions first
$versions = $project->fetchVersions(1, VersionOrder::POST_DATE, SortDirection::DESC);

// get the author
$author = $project->getAuthor();
Expand Down
28 changes: 26 additions & 2 deletions src/Client/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,43 @@ public function getAuthor(): Author
}

/**
* Get a list of versions for this project.
* Fetch the versions of this project from the API (paginated).
*
* This sends a request to the SpigotMC API every time it is called. The result is not cached.
*
* @param int $page
* @param VersionOrder|null $order Field to order the results by. When null, the API default (id) is used.
* @param SortDirection|null $direction Direction to order the results by. When null, the API default (asc) is used.
* @return PaginatedVersionList
* @throws ApiException
*/
public function getVersions(
public function fetchVersions(
int $page = 1,
?VersionOrder $order = null,
?SortDirection $direction = null,
): PaginatedVersionList
{
return $this->client->getProjectVersions($this->getId(), $page, $order, $direction);
}

/**
* Fetch the versions of this project from the API (paginated).
*
* This sends a request to the SpigotMC API every time it is called. The result is not cached.
*
* @deprecated Use {@see fetchVersions()} instead. Methods that send a request to the API are prefixed with "fetch".
* @param int $page
* @param VersionOrder|null $order Field to order the results by. When null, the API default (id) is used.
* @param SortDirection|null $direction Direction to order the results by. When null, the API default (asc) is used.
* @return PaginatedVersionList
* @throws ApiException
*/
public function getVersions(
int $page = 1,
?VersionOrder $order = null,
?SortDirection $direction = null,
): PaginatedVersionList
{
return $this->fetchVersions($page, $order, $direction);
}
}
2 changes: 1 addition & 1 deletion tests/Integration/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function testGetVersionsFromProject(): void
{
$project = $this->apiClient->getProject(2);

$versions = $project->getVersions();
$versions = $project->fetchVersions();
$this->assertNotNull($versions);
$this->assertNotEmpty($versions);
foreach ($versions as $version) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Client/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function testGetAuthor(): void
/**
* @throws ApiException
*/
public function testGetVersions(): void
public function testFetchVersions(): void
{
$versions = $this->project->getVersions();
$versions = $this->project->fetchVersions();
$this->assertNotNull($versions);
$this->assertNotEmpty($versions);

Expand Down
20 changes: 18 additions & 2 deletions tests/Unit/Client/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public function testGetAuthor(): void
/**
* @throws ApiException
*/
public function testGetVersions(): void
public function testFetchVersions(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourceUpdates.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$project = new Project($this->apiClient, $this->getResourceModel());

$versions = $project->getVersions();
$versions = $project->fetchVersions();
$this->assertNotNull($versions);
$this->assertNotEmpty($versions);

Expand All @@ -141,5 +141,21 @@ public function testGetVersions(): void
}
}

/**
* @throws ApiException
*/
public function testDeprecatedGetVersionsFetchesVersions(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourceUpdates.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$project = new Project($this->apiClient, $this->getResourceModel());

$versions = $project->getVersions();
$this->assertNotEmpty($versions);
$this->assertSame(0, $handler->count());
}


}
Loading