Skip to content

Commit

Permalink
Merge pull request #70 from php-api-clients/app
Browse files Browse the repository at this point in the history
Support for getting current app
  • Loading branch information
WyriHaximus authored Apr 3, 2020
2 parents 6978d50 + 7540003 commit 2eed199
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/AsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public function rateLimit(): PromiseInterface
return $this->client->handle(new Command\RateLimitCommand());
}

public function app(): PromiseInterface
{
return $this->client->handle(new Command\AppCommand());
}

public function renderMarkdown(
ReadableStreamInterface $stream,
string $mode = 'markdown',
Expand Down
12 changes: 12 additions & 0 deletions src/CommandBus/Command/AppCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Command;

use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\AppHandler")
*/
final class AppCommand
{
}
41 changes: 41 additions & 0 deletions src/CommandBus/Handler/AppHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler;

use ApiClients\Client\Github\CommandBus\Command\AppCommand;
use ApiClients\Client\Github\Resource\AppInterface;
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

final class AppHandler
{
/**
* @var FetchAndHydrateService
*/
private $service;

/**
* RateLimitHandler constructor.
* @param FetchAndHydrateService $service
*/
public function __construct(FetchAndHydrateService $service)
{
$this->service = $service;
}

/**
* @param AppCommand $command
* @return PromiseInterface
*/
public function handle(AppCommand $command): PromiseInterface
{
return resolve(
$this->service->fetch(
'app',
'',
AppInterface::HYDRATE_CLASS
)
);
}
}
173 changes: 173 additions & 0 deletions src/Resource/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
use ApiClients\Foundation\Hydrator\Annotation\Nested;
use ApiClients\Foundation\Resource\AbstractResource;
use DateTimeInterface;

/**
* @Nested(
* owner="User"
* )
* @EmptyResource("EmptyApp")
*/
abstract class App extends AbstractResource implements AppInterface
{
/**
* @var int
*/
protected $id;

/**
* @var string
*/
protected $slug;

/**
* @var User
*/
protected $owner;

/**
* @var string
*/
protected $name;

/**
* @var string
*/
protected $description;

/**
* @var string
*/
protected $external_url;

/**
* @var string
*/
protected $html_url;

/**
* @var DateTimeInterface
*/
protected $created_at;

/**
* @var DateTimeInterface
*/
protected $updated_at;

/**
* @var array
*/
protected $permissions;

/**
* @var array
*/
protected $events;

/**
* @var int
*/
protected $installations_count;

/**
* @return int
*/
public function id(): int
{
return $this->id;
}

/**
* @return string
*/
public function slug(): string
{
return $this->slug;
}

/**
* @return User
*/
public function owner(): User
{
return $this->owner;
}

/**
* @return string
*/
public function name(): string
{
return $this->name;
}

/**
* @return string
*/
public function description(): string
{
return $this->description;
}

/**
* @return string
*/
public function externalUrl(): string
{
return $this->external_url;
}

/**
* @return string
*/
public function htmlUrl(): string
{
return $this->html_url;
}

/**
* @return DateTimeInterface
*/
public function createdAt(): DateTimeInterface
{
return $this->created_at;
}

/**
* @return DateTimeInterface
*/
public function updatedAt(): DateTimeInterface
{
return $this->updated_at;
}

/**
* @return array
*/
public function permissions(): array
{
return $this->permissions;
}

/**
* @return array
*/
public function events(): array
{
return $this->events;
}

/**
* @return int
*/
public function installationsCount(): int
{
return $this->installations_count;
}
}
71 changes: 71 additions & 0 deletions src/Resource/AppInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Resource\ResourceInterface;
use DateTimeInterface;

interface AppInterface extends ResourceInterface
{
const HYDRATE_CLASS = 'App';

/**
* @return int
*/
public function id(): int;

/**
* @return string
*/
public function slug(): string;

/**
* @return User
*/
public function owner(): User;

/**
* @return string
*/
public function name(): string;

/**
* @return string
*/
public function description(): string;

/**
* @return string
*/
public function externalUrl(): string;

/**
* @return string
*/
public function htmlUrl(): string;

/**
* @return DateTimeInterface
*/
public function createdAt(): DateTimeInterface;

/**
* @return DateTimeInterface
*/
public function updatedAt(): DateTimeInterface;

/**
* @return array
*/
public function permissions(): array;

/**
* @return array
*/
public function events(): array;

/**
* @return int
*/
public function installationsCount(): int;
}
13 changes: 13 additions & 0 deletions src/Resource/Async/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async;

use ApiClients\Client\Github\Resource\App as BaseApp;

class App extends BaseApp
{
public function refresh(): App
{
throw new \Exception('TODO: create refresh method!');
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/EmptyApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async;

use ApiClients\Client\Github\Resource\EmptyApp as BaseEmptyApp;

class EmptyApp extends BaseEmptyApp
{
}
Loading

0 comments on commit 2eed199

Please sign in to comment.