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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ To request more information about an author from the API, use the methods on the
// get a specific author (by numeric id)
$author = $spigotClient->getAuthor(1);

// get projects as a PaginatedProjectList
$projects = $author->getProjects();
// fetch the projects from the API as a PaginatedAuthorProjectList (sends a request)
$projects = $author->fetchProjects();
```

### getAuthorProjects()
Expand Down
23 changes: 20 additions & 3 deletions src/Client/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ public function getId(): int
}

/**
* Get a list of projects by this author.
* Fetch the projects of this author from the API (paginated).
*
* This sends a request to the SpigotMC API every time it is called. The result is not cached.
*
* @return PaginatedAuthorProjectList
* @throws ApiException
*/
public function getProjects(): PaginatedAuthorProjectList
public function fetchProjects(): PaginatedAuthorProjectList
{
return $this->client->getAuthorProjects($this->getId());
}
}

/**
* Fetch the projects of this author 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 fetchProjects()} instead. Methods that send a request to the API are prefixed with "fetch".
* @return PaginatedAuthorProjectList
* @throws ApiException
*/
public function getProjects(): PaginatedAuthorProjectList
{
return $this->fetchProjects();
}
}
4 changes: 2 additions & 2 deletions tests/Integration/Client/AuthorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function setUp(): void
/**
* @throws ApiException
*/
public function testGetProjects(): void
public function testFetchProjects(): void
{
$projects = $this->author->getProjects();
$projects = $this->author->fetchProjects();
$this->assertNotNull($projects);
$this->assertNotEmpty($projects);

Expand Down
20 changes: 18 additions & 2 deletions tests/Unit/Client/AuthorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ protected function getAuthorModel(): \Aternos\SpigotApi\Model\Author
/**
* @throws ApiException
*/
public function testGetProjects(): void
public function testFetchProjects(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourcesByAuthor.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$author = new Author($this->apiClient, $this->getAuthorModel());

$projects = $author->getProjects();
$projects = $author->fetchProjects();
$this->assertNotNull($projects);
$this->assertNotEmpty($projects);

Expand All @@ -45,4 +45,20 @@ public function testGetProjects(): void
}
}

/**
* @throws ApiException
*/
public function testDeprecatedGetProjectsFetchesProjects(): void
{
$handler = new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . "/Fixtures/getResourcesByAuthor.json")),
]);
$this->apiClient->setHttpClient(new Client(['handler' => HandlerStack::create($handler)]));
$author = new Author($this->apiClient, $this->getAuthorModel());

$projects = $author->getProjects();
$this->assertNotEmpty($projects);
$this->assertSame(0, $handler->count());
}

}
Loading