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
18 changes: 18 additions & 0 deletions examples/meta-async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use ApiClients\Client\Github\AsyncClient;
use ApiClients\Client\Github\Resource\MetaInterface;
use ApiClients\Client\Github\Resource\OrganizationInterface;
use React\EventLoop\Factory;
use function ApiClients\Foundation\resource_pretty_print;

require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';

$loop = Factory::create();
$client = AsyncClient::create($loop, require 'resolve_token.php');

$client->meta()->then(function (MetaInterface $meta) {
resource_pretty_print($meta);
}, 'display_throwable');

$loop->run();
5 changes: 5 additions & 0 deletions src/AsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ private function __construct(ClientInterface $client)
$this->client = $client;
}

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

public function user(string $user): PromiseInterface
{
return $this->client->handle(new Command\UserCommand($user));
Expand Down
2 changes: 2 additions & 0 deletions src/AsyncClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

interface AsyncClientInterface
{
public function meta(): PromiseInterface;

public function user(string $user): PromiseInterface;

public function whoami(): PromiseInterface;
Expand Down
12 changes: 12 additions & 0 deletions src/CommandBus/Command/MetaCommand.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\MetaHandler")
*/
final class MetaCommand
{
}
34 changes: 34 additions & 0 deletions src/CommandBus/Handler/MetaHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler;

use ApiClients\Client\Github\CommandBus\Command\MetaCommand;
use ApiClients\Client\Github\Resource\MetaInterface;
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
use React\Promise\PromiseInterface;

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

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

/**
* @param MetaCommand $command
* @return PromiseInterface
*/
public function handle(MetaCommand $command): PromiseInterface
{
return $this->service->fetch('meta', '', MetaInterface::HYDRATE_CLASS);
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/EmptyMeta.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\EmptyMeta as BaseEmptyMeta;

class EmptyMeta extends BaseEmptyMeta
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Meta.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\Meta as BaseMeta;

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

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Resource\EmptyResourceInterface;

abstract class EmptyMeta implements MetaInterface, EmptyResourceInterface
{
/**
* @return bool
*/
public function verifiablePasswordAuthentication() : bool
{
return null;
}

/**
* @return string
*/
public function githubServicesSha() : string
{
return null;
}

/**
* @return array
*/
public function hooks() : array
{
return null;
}

/**
* @return array
*/
public function git() : array
{
return null;
}

/**
* @return array
*/
public function pages() : array
{
return null;
}

/**
* @return array
*/
public function importer() : array
{
return null;
}
}
90 changes: 90 additions & 0 deletions src/Resource/Meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Hydrator\Annotations\EmptyResource;
use ApiClients\Foundation\Resource\AbstractResource;

/**
* @EmptyResource("EmptyMeta")
*/
abstract class Meta extends AbstractResource implements MetaInterface
{
/**
* @var bool
*/
protected $verifiable_password_authentication;

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

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

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

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

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

/**
* @return bool
*/
public function verifiablePasswordAuthentication() : bool
{
return $this->verifiable_password_authentication;
}

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

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

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

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

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

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Resource\ResourceInterface;

interface MetaInterface extends ResourceInterface
{
const HYDRATE_CLASS = 'Meta';

/**
* @return bool
*/
public function verifiablePasswordAuthentication() : bool;

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

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

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

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

/**
* @return array
*/
public function importer() : array;
}
9 changes: 9 additions & 0 deletions src/Resource/Sync/EmptyMeta.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\Sync;

use ApiClients\Client\Github\Resource\EmptyMeta as BaseEmptyMeta;

class EmptyMeta extends BaseEmptyMeta
{
}
19 changes: 19 additions & 0 deletions src/Resource/Sync/Meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Sync;

use ApiClients\Foundation\Hydrator\CommandBus\Command\BuildAsyncFromSyncCommand;
use ApiClients\Client\Github\Resource\Meta as BaseMeta;
use ApiClients\Client\Github\Resource\MetaInterface;

class Meta extends BaseMeta
{
public function refresh() : Meta
{
return $this->wait($this->handleCommand(
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
)->then(function (MetaInterface $meta) {
return $meta->refresh();
}));
}
}
25 changes: 25 additions & 0 deletions tests/CommandBus/Handler/MetaHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace ApiClients\Tests\Github\CommandBus\Handler;

use ApiClients\Client\Github\CommandBus\Command\MetaCommand;
use ApiClients\Client\Github\CommandBus\Handler\MetaHandler;
use ApiClients\Client\Github\Resource\MetaInterface;
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
use ApiClients\Tools\TestUtilities\TestCase;
use function React\Promise\resolve;

final class MetaHandlerTest extends TestCase
{
public function testCommand()
{
$meta = $this->prophesize(MetaInterface::class)->reveal();

$service = $this->prophesize(FetchAndHydrateService::class);
$service->fetch('meta', '', MetaInterface::HYDRATE_CLASS)->shouldBeCalled()->willReturn(resolve($meta));

$handler = new MetaHandler($service->reveal());

self::assertSame($meta, $this->await($handler->handle(new MetaCommand())));
}
}
18 changes: 18 additions & 0 deletions tests/Resource/Async/EmptyMetaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace ApiClients\Tests\Client\Github\Resource\Async;

use ApiClients\Tools\ResourceTestUtilities\AbstractEmptyResourceTest;
use ApiClients\Client\Github\Resource\Async\EmptyMeta;

final class EmptyMetaTest extends AbstractEmptyResourceTest
{
public function getSyncAsync() : string
{
return 'Async';
}
public function getClass() : string
{
return EmptyMeta::class;
}
}
23 changes: 23 additions & 0 deletions tests/Resource/Async/MetaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace ApiClients\Tests\Client\Github\Resource\Async;

use ApiClients\Tools\ResourceTestUtilities\AbstractResourceTest;
use ApiClients\Client\Github\ApiSettings;
use ApiClients\Client\Github\Resource\Meta;

class MetaTest extends AbstractResourceTest
{
public function getSyncAsync() : string
{
return 'Async';
}
public function getClass() : string
{
return Meta::class;
}
public function getNamespace() : string
{
return Apisettings::NAMESPACE;
}
}
Loading