Skip to content

Commit

Permalink
Restructure client code
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Dec 12, 2023
1 parent f275b75 commit 1db9668
Show file tree
Hide file tree
Showing 2,253 changed files with 154,952 additions and 141,280 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ on how to obtain an API token and how to get started with the API.

```php
use \Mittwald\ApiClient\Generated\V2\Clients\Project\ListProjects\ListProjectsRequest;
use \Mittwald\ApiClient\Generated\V2\Clients\Project\ListProjects\ListProjects200Response;

$listProjectRequest = new ListProjectsRequest();
$listProjectResponse = $client->project()->listProjects($listProjectRequest);

if ($listProjectResponse instanceof ListProjects200Response) {
foreach ($listProjectResponse->getBody() as $project) {
echo $project->getShortId() . PHP_EOL;
}
foreach ($listProjectResponse->getBody() as $project) {
echo $project->getShortId() . PHP_EOL;
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/Client/EmptyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* EmptyResponse models an empty HTTP response (typically accompanying a
* "204 No Content" response).
*/
readonly class EmptyResponse
readonly class EmptyResponse implements ResponseContainer
{
use ResponseTrait;

Expand Down
12 changes: 12 additions & 0 deletions src/Client/ResponseContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Mittwald\ApiClient\Client;

use Psr\Http\Message\ResponseInterface;

interface ResponseContainer
{
public function getResponse(): ?ResponseInterface;
}
2 changes: 1 addition & 1 deletion src/Client/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait ResponseTrait
/**
* Returns the underlying PSR-7 HTTP response object.
*/
public function getResponse(): ResponseInterface
public function getResponse(): ?ResponseInterface
{
return $this->response;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/StringResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* String models an HTTP response with a raw string body
*/
readonly class StringResponse
readonly class StringResponse implements ResponseContainer
{
use ResponseTrait;

Expand Down
2 changes: 1 addition & 1 deletion src/Client/UntypedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* UntypedResponse models an HTTP response with an arbitrary body.
*/
readonly class UntypedResponse
readonly class UntypedResponse implements ResponseContainer
{
use ResponseTrait;

Expand Down
34 changes: 34 additions & 0 deletions src/Error/UnexpectedResponseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Mittwald\ApiClient\Error;

use Exception;
use InvalidArgumentException;
use Mittwald\ApiClient\Client\ResponseContainer;
use Psr\Http\Message\ResponseInterface;
use Throwable;

class UnexpectedResponseException extends Exception
{
public readonly ResponseInterface $response;

public function __construct(ResponseContainer $response, Throwable $previous = null)
{
$response = $response->getResponse();
if ($response === null) {
throw new InvalidArgumentException('ResponseContainer must contain a response');
}

$this->response = $response;
parent::__construct(
sprintf(
'Unexpected response status code %d %s',
$this->response->getStatusCode(),
$this->response->getReasonPhrase(),
),
previous: $previous,
);
}
}
116 changes: 20 additions & 96 deletions src/Generated/V2/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Mittwald\ApiClient\Generated\V2;

use Mittwald\ApiClient\Client\BaseClient;
use Mittwald\ApiClient\Generated\V2\Clients\App\AppClient;
use Mittwald\ApiClient\Generated\V2\Clients\Article\ArticleClient;
use Mittwald\ApiClient\Generated\V2\Clients\Backup\BackupClient;
Expand Down Expand Up @@ -30,100 +29,25 @@
* (https://github.com/mittwald/api-client-php-builder). Please make any changes
* there.
*/
class Client extends BaseClient
interface Client
{
public function project(): ProjectClient
{
return new ProjectClient($this->client);
}

public function backup(): BackupClient
{
return new BackupClient($this->client);
}

public function sSHSFTPUser(): SSHSFTPUserClient
{
return new SSHSFTPUserClient($this->client);
}

public function cronjob(): CronjobClient
{
return new CronjobClient($this->client);
}

public function app(): AppClient
{
return new AppClient($this->client);
}

public function projectFileSystem(): ProjectFileSystemClient
{
return new ProjectFileSystemClient($this->client);
}

public function contract(): ContractClient
{
return new ContractClient($this->client);
}

public function database(): DatabaseClient
{
return new DatabaseClient($this->client);
}

public function domain(): DomainClient
{
return new DomainClient($this->client);
}

public function conversation(): ConversationClient
{
return new ConversationClient($this->client);
}

public function customer(): CustomerClient
{
return new CustomerClient($this->client);
}

public function user(): UserClient
{
return new UserClient($this->client);
}

public function notification(): NotificationClient
{
return new NotificationClient($this->client);
}

public function file(): FileClient
{
return new FileClient($this->client);
}

public function mail(): MailClient
{
return new MailClient($this->client);
}

public function article(): ArticleClient
{
return new ArticleClient($this->client);
}

public function container(): ContainerClient
{
return new ContainerClient($this->client);
}

public function pageInsights(): PageInsightsClient
{
return new PageInsightsClient($this->client);
}

public function relocation(): RelocationClient
{
return new RelocationClient($this->client);
}
public function project(): ProjectClient;
public function backup(): BackupClient;
public function sshSFTPUser(): SSHSFTPUserClient;
public function cronjob(): CronjobClient;
public function app(): AppClient;
public function projectFileSystem(): ProjectFileSystemClient;
public function contract(): ContractClient;
public function database(): DatabaseClient;
public function domain(): DomainClient;
public function conversation(): ConversationClient;
public function customer(): CustomerClient;
public function user(): UserClient;
public function notification(): NotificationClient;
public function file(): FileClient;
public function mail(): MailClient;
public function article(): ArticleClient;
public function container(): ContainerClient;
public function pageInsights(): PageInsightsClient;
public function relocation(): RelocationClient;
}
148 changes: 148 additions & 0 deletions src/Generated/V2/ClientImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

namespace Mittwald\ApiClient\Generated\V2;

use Mittwald\ApiClient\Client\BaseClient;
use Mittwald\ApiClient\Generated\V2\Clients\App\AppClient;
use Mittwald\ApiClient\Generated\V2\Clients\App\AppClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Article\ArticleClient;
use Mittwald\ApiClient\Generated\V2\Clients\Article\ArticleClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Backup\BackupClient;
use Mittwald\ApiClient\Generated\V2\Clients\Backup\BackupClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Container\ContainerClient;
use Mittwald\ApiClient\Generated\V2\Clients\Container\ContainerClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\ContractClient;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\ContractClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Conversation\ConversationClient;
use Mittwald\ApiClient\Generated\V2\Clients\Conversation\ConversationClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Cronjob\CronjobClient;
use Mittwald\ApiClient\Generated\V2\Clients\Cronjob\CronjobClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Customer\CustomerClient;
use Mittwald\ApiClient\Generated\V2\Clients\Customer\CustomerClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Database\DatabaseClient;
use Mittwald\ApiClient\Generated\V2\Clients\Database\DatabaseClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\DomainClient;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\DomainClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\File\FileClient;
use Mittwald\ApiClient\Generated\V2\Clients\File\FileClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Mail\MailClient;
use Mittwald\ApiClient\Generated\V2\Clients\Mail\MailClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Notification\NotificationClient;
use Mittwald\ApiClient\Generated\V2\Clients\Notification\NotificationClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\PageInsights\PageInsightsClient;
use Mittwald\ApiClient\Generated\V2\Clients\PageInsights\PageInsightsClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Project\ProjectClient;
use Mittwald\ApiClient\Generated\V2\Clients\Project\ProjectClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\ProjectFileSystem\ProjectFileSystemClient;
use Mittwald\ApiClient\Generated\V2\Clients\ProjectFileSystem\ProjectFileSystemClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\Relocation\RelocationClient;
use Mittwald\ApiClient\Generated\V2\Clients\Relocation\RelocationClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\SSHSFTPUser\SSHSFTPUserClient;
use Mittwald\ApiClient\Generated\V2\Clients\SSHSFTPUser\SSHSFTPUserClientImpl;
use Mittwald\ApiClient\Generated\V2\Clients\User\UserClient;
use Mittwald\ApiClient\Generated\V2\Clients\User\UserClientImpl;

/**
* Auto-generated factory for mittwald mStudio v2 clients.
*
* DO NOT EDIT; this class was generated by the mittwald/api-client-builder package
* (https://github.com/mittwald/api-client-php-builder). Please make any changes
* there.
*/
class ClientImpl extends BaseClient implements Client
{
public function project(): ProjectClient
{
return new ProjectClientImpl($this->client);
}

public function backup(): BackupClient
{
return new BackupClientImpl($this->client);
}

public function sshSFTPUser(): SSHSFTPUserClient
{
return new SSHSFTPUserClientImpl($this->client);
}

public function cronjob(): CronjobClient
{
return new CronjobClientImpl($this->client);
}

public function app(): AppClient
{
return new AppClientImpl($this->client);
}

public function projectFileSystem(): ProjectFileSystemClient
{
return new ProjectFileSystemClientImpl($this->client);
}

public function contract(): ContractClient
{
return new ContractClientImpl($this->client);
}

public function database(): DatabaseClient
{
return new DatabaseClientImpl($this->client);
}

public function domain(): DomainClient
{
return new DomainClientImpl($this->client);
}

public function conversation(): ConversationClient
{
return new ConversationClientImpl($this->client);
}

public function customer(): CustomerClient
{
return new CustomerClientImpl($this->client);
}

public function user(): UserClient
{
return new UserClientImpl($this->client);
}

public function notification(): NotificationClient
{
return new NotificationClientImpl($this->client);
}

public function file(): FileClient
{
return new FileClientImpl($this->client);
}

public function mail(): MailClient
{
return new MailClientImpl($this->client);
}

public function article(): ArticleClient
{
return new ArticleClientImpl($this->client);
}

public function container(): ContainerClient
{
return new ContainerClientImpl($this->client);
}

public function pageInsights(): PageInsightsClient
{
return new PageInsightsClientImpl($this->client);
}

public function relocation(): RelocationClient
{
return new RelocationClientImpl($this->client);
}
}
Loading

0 comments on commit 1db9668

Please sign in to comment.