Skip to content

Commit

Permalink
Replace remaining namespace parameters with slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianVennen committed Dec 20, 2023
1 parent 4da6129 commit b1e2758
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 94 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ $projects = $hangarClient->getProjects($options);
The Project wrapper provides methods to fetch additional data about the project.
```php
// get a specific project
$project = $hangarClient->getProject("Aternos", "mclogs");
$project = $hangarClient->getProject("mclogs");

// get versions of the project (paginated)
$versions = $project->getVersions();
Expand All @@ -95,17 +95,13 @@ $watchers = $project->getWatchers();
## Versions
```php
// get versions of a project by name (paginated)
$versions = $hangarClient->getProjectVersions("Aternos", "mclogs");
$versions = $hangarClient->getProjectVersions("mclogs");

// get the versions from a project (paginated)
$versions = $project->getVersions();

// get a specific version of a project by name
use \Aternos\HangarApi\Model\ProjectNamespace;
$namespace = (new ProjectNamespace())
->setOwner("Aternos")
->setProject("mclogs");
$version = $hangarClient->getProjectVersion($namespace, "2.6.2");
$version = $hangarClient->getProjectVersion("mclogs", "2.6.2");

// get a specific version of a project
$version = $project->getVersion("2.6.2");
Expand Down Expand Up @@ -135,10 +131,10 @@ $watchedProjects = $user->getWatchedProjects();
## Project Pages
```php
// get the main page of a project
$page = $hangarClient->getProjectMainPage("Aternos", "mclogs");
$page = $hangarClient->getProjectMainPage("mclogs");

// get other pages
$page = $hangarClient->getProjectPage("Aternos", "mclogs", "Config");
$page = $hangarClient->getProjectPage("mclogs", "Config");

// get a page from a project
$page = $project->getPage("Config");
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
invokerPackage: Aternos\HangarApi
artifactVersion: 2.0.0
artifactVersion: 3.0.0
generatorName: php
outputDir: .
sourceFolder: src
Expand Down
29 changes: 19 additions & 10 deletions lib/Client/CompactProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ public function getData(): ProjectCompact
return $this->project;
}

/**
* Get the slug of this project (shorthand for getData()->getNamespace()->getSlug())
* @return string
*/
public function getSlug(): string
{
return $this->project->getNamespace()->getSlug();
}

/**
* Get the full project data
* @return Project
* @throws ApiException
*/
public function getProject(): Project
{
return $this->client->getProject($this->project->getNamespace()->getSlug());
return $this->client->getProject($this->getSlug());
}

/**
Expand All @@ -55,11 +64,11 @@ public function getProject(): Project
*/
public function getVersions(?string $channel = null, ?Platform $platform = null, ?string $platformVersion = null): ProjectVersionList
{
$options = new VersionSearchOptions($this->getData()->getNamespace());
$options = new VersionSearchOptions($this->getSlug());
$options->setChannel($channel);
$options->setPlatform($platform);
$options->setPlatformVersion($platformVersion);
return $this->client->getProjectVersions($this->project->getNamespace(), $options);
return $this->client->getProjectVersions($this->getSlug(), $options);
}

/**
Expand All @@ -70,7 +79,7 @@ public function getVersions(?string $channel = null, ?Platform $platform = null,
*/
public function getVersion(string $name): Version
{
return $this->client->getProjectVersion($this->getData()->getNamespace(), $name);
return $this->client->getProjectVersion($this->getSlug(), $name);
}

/**
Expand All @@ -80,7 +89,7 @@ public function getVersion(string $name): Version
*/
public function getWatchers(): UserList
{
return $this->client->getProjectWatchers($this->project->getNamespace());
return $this->client->getProjectWatchers($this->getSlug());
}

/**
Expand All @@ -94,7 +103,7 @@ public function getWatchers(): UserList
public function getDailyStats(?DateTime $from = null, ?DateTime $to = null): array
{
return $this->client->getDailyProjectStats(
$this->project->getNamespace()->getSlug(),
$this->getSlug(),
$from ?? $this->getData()->getCreatedAt(),
$to
);
Expand All @@ -107,7 +116,7 @@ public function getDailyStats(?DateTime $from = null, ?DateTime $to = null): arr
*/
public function getStarGazers(): UserList
{
return $this->client->getProjectStarGazers($this->project->getNamespace());
return $this->client->getProjectStarGazers($this->getSlug());
}

/**
Expand All @@ -117,7 +126,7 @@ public function getStarGazers(): UserList
*/
public function getMembers(): ProjectMemberList
{
return $this->client->getProjectMembers($this->project->getNamespace());
return $this->client->getProjectMembers($this->getSlug());
}

/**
Expand All @@ -137,7 +146,7 @@ public function getOwner(): User
*/
public function getMainPage(): ProjectPage
{
return $this->client->getProjectMainPage($this->project->getNamespace()->getSlug());
return $this->client->getProjectMainPage($this->getSlug());
}

/**
Expand All @@ -148,6 +157,6 @@ public function getMainPage(): ProjectPage
*/
public function getPage(string $path): ProjectPage
{
return $this->client->getProjectPage($this->project->getNamespace()->getSlug(), $path);
return $this->client->getProjectPage($this->getSlug(), $path);
}
}
47 changes: 23 additions & 24 deletions lib/Client/HangarAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Aternos\HangarApi\Model\DayProjectStats;
use Aternos\HangarApi\Model\NamedPermission;
use Aternos\HangarApi\Model\PageEditForm;
use Aternos\HangarApi\Model\ProjectNamespace;
use Aternos\HangarApi\Model\RequestPagination;
use Aternos\HangarApi\Model\StringContent;
use Aternos\HangarApi\Model\VersionStats;
Expand Down Expand Up @@ -219,24 +218,24 @@ public function getProject(string $slug): Project

/**
* Get a list of people watching a project
* @param ProjectNamespace $namespace
* @param string $projectSlug
* @param RequestPagination|null $pagination
* @return ProjectWatcherList
* @throws ApiException
*/
public function getProjectWatchers(ProjectNamespace $namespace, ?RequestPagination $pagination = null): ProjectWatcherList
public function getProjectWatchers(string $projectSlug, ?RequestPagination $pagination = null): ProjectWatcherList
{
$this->authenticate();

$pagination ??= (new RequestPagination())
->setOffset(0)
->setLimit(25);

$result = $this->projects->getProjectWatchers($namespace->getSlug(), $pagination);
$result = $this->projects->getProjectWatchers($projectSlug, $pagination);
return new ProjectWatcherList(
$this,
$result,
$namespace,
$projectSlug,
$pagination,
);
}
Expand Down Expand Up @@ -271,56 +270,56 @@ public function getDailyProjectStats(string $slug, DateTime $from, ?DateTime $to

/**
* Get a list of people starring a project
* @param ProjectNamespace $namespace
* @param string $projectSlug
* @param RequestPagination|null $pagination
* @return ProjectStarGazersList
* @throws ApiException
*/
public function getProjectStarGazers(ProjectNamespace $namespace, ?RequestPagination $pagination = null): ProjectStarGazersList
public function getProjectStarGazers(string $projectSlug, ?RequestPagination $pagination = null): ProjectStarGazersList
{
$this->authenticate();

$pagination ??= (new RequestPagination())
->setOffset(0)
->setLimit(25);

$result = $this->projects->getProjectStarGazers($namespace->getSlug(), $pagination);
$result = $this->projects->getProjectStarGazers($projectSlug, $pagination);
return new ProjectStarGazersList(
$this,
$result,
$namespace,
$projectSlug,
$pagination,
);
}

/**
* Get a list of members of a project
* @param ProjectNamespace $namespace
* @param string $projectSlug
* @param RequestPagination|null $pagination
* @return ProjectMemberList
* @throws ApiException
*/
public function getProjectMembers(ProjectNamespace $namespace, ?RequestPagination $pagination = null): ProjectMemberList
public function getProjectMembers(string $projectSlug, ?RequestPagination $pagination = null): ProjectMemberList
{
$this->authenticate();

$pagination ??= (new RequestPagination())
->setOffset(0)
->setLimit(25);

$result = $this->projects->getProjectMembers($namespace->getSlug(), $pagination);
return new ProjectMemberList($this, $result, $namespace, $pagination);
$result = $this->projects->getProjectMembers($projectSlug, $pagination);
return new ProjectMemberList($this, $result, $projectSlug, $pagination);
}

/**
* Get versions of a project
* @param ProjectNamespace|Project $project
* @param string|Project $project project slug or object
* @param VersionSearchOptions $options
* @return ProjectVersionList
* @throws ApiException
*/
public function getProjectVersions(
ProjectNamespace|Project $project,
string|Project $project,
VersionSearchOptions $options,
): ProjectVersionList
{
Expand All @@ -329,11 +328,11 @@ public function getProjectVersions(
if ($project instanceof Project) {
$options->setProject($project);
} else {
$options->setProjectNamespace($project);
$options->setProjectSlug($project);
}

$result = $this->versions->listVersions(
$options->getProjectNamespace()->getSlug(),
$options->getProjectSlug(),
$options->getPagination(),
$options->getChannel(),
$options->getPlatform()?->value,
Expand All @@ -345,21 +344,21 @@ public function getProjectVersions(

/**
* Get a single project version
* @param ProjectNamespace|Project $project
* @param string|Project $project project slug or object
* @param string $name
* @return Version
* @throws ApiException
*/
public function getProjectVersion(ProjectNamespace|Project $project, string $name): Version
public function getProjectVersion(string|Project $project, string $name): Version
{
$this->authenticate();

$namespace = $project instanceof Project ? $project->getData()->getNamespace() : $project;
$result = $this->versions->showVersion($namespace->getSlug(), $name);
$projectSlug = $project instanceof Project ? $project->getSlug() : $project;
$result = $this->versions->showVersion($projectSlug, $name);
return new Version(
$this,
$result,
$namespace,
$projectSlug,
$project instanceof Project ? $project : null
);
}
Expand All @@ -379,14 +378,14 @@ public function getDailyProjectVersionStats(Version $version, DateTime $from, ?D
{
$this->authenticate();

if (!$this->hasPermission(NamedPermission::IS_SUBJECT_MEMBER, $version->getProjectNamespace()->getSlug())) {
if (!$this->hasPermission(NamedPermission::IS_SUBJECT_MEMBER, $version->getProjectSlug())) {
throw new ApiException('You need the is_subject_member permission to view version statistics');
}

$to ??= new DateTime();

return $this->versions->showVersionStats(
$version->getProjectNamespace()->getSlug(),
$version->getProjectSlug(),
$version->getData()->getName(),
$from->format(DateTimeInterface::RFC3339),
$to->format(DateTimeInterface::RFC3339),
Expand Down
5 changes: 2 additions & 3 deletions lib/Client/List/ProjectMemberList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Aternos\HangarApi\ApiException;
use Aternos\HangarApi\Client\HangarAPIClient;
use Aternos\HangarApi\Model\PaginatedResultProjectMember;
use Aternos\HangarApi\Model\ProjectNamespace;
use Aternos\HangarApi\Model\RequestPagination;

/**
Expand All @@ -19,7 +18,7 @@ class ProjectMemberList extends ResultList
public function __construct(
protected HangarAPIClient $client,
PaginatedResultProjectMember $result,
protected ProjectNamespace $namespace,
protected string $projectSlug,
protected RequestPagination $requestPagination,
)
{
Expand All @@ -35,6 +34,6 @@ public function getOffset(int $offset): static
{
$pagination = clone $this->requestPagination;
$pagination->setOffset($offset);
return $this->client->getProjectMembers($this->namespace, $pagination);
return $this->client->getProjectMembers($this->projectSlug, $pagination);
}
}
4 changes: 2 additions & 2 deletions lib/Client/List/ProjectVersionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
return new Version(
$this->client,
$version,
$options->getProjectNamespace(),
$options->getProjectSlug(),
$options->getProject(),
);
}, $result->getResult()));
Expand All @@ -38,7 +38,7 @@ public function getOffset(int $offset): static
$options = clone $this->options;
$options->setOffset($offset);
return $this->client->getProjectVersions(
$this->options->getProject() ?? $this->options->getProjectNamespace(),
$this->options->getProject() ?? $this->options->getProjectSlug()->getSlug(),
$options
);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Client/List/User/ProjectStarGazersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Aternos\HangarApi\Client\HangarAPIClient;
use Aternos\HangarApi\Client\List\UserList;
use Aternos\HangarApi\Model\PaginatedResultUser;
use Aternos\HangarApi\Model\ProjectNamespace;
use Aternos\HangarApi\Model\RequestPagination;

/**
Expand All @@ -19,7 +18,7 @@ class ProjectStarGazersList extends UserList
public function __construct(
HangarAPIClient $client,
PaginatedResultUser $result,
protected ProjectNamespace $namespace,
protected string $projectSlug,
protected RequestPagination $requestPagination,
)
{
Expand All @@ -30,6 +29,6 @@ public function getOffset(int $offset): static
{
$pagination = clone $this->requestPagination;
$pagination->setOffset($offset);
return $this->client->getProjectStarGazers($this->namespace, $pagination);
return $this->client->getProjectStarGazers($this->projectSlug, $pagination);
}
}
Loading

0 comments on commit b1e2758

Please sign in to comment.