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
29 changes: 29 additions & 0 deletions examples/user-repositories-releases-async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
use ApiClients\Client\Github\AsyncClient;
use ApiClients\Client\Github\Resource\Async\Repository;
use ApiClients\Client\Github\Resource\Async\User;
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->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
resource_pretty_print($user);

return $user->repository($argv[2] ?? 'github');
})->then(function (Repository $repository) {
resource_pretty_print($repository, 1, true);
$repository->releases()->subscribe(function ($release) {
resource_pretty_print($release, 2, true);
}, function ($error) {
echo (string)$error;
});
})->done(null, 'display_throwable');

$loop->run();

displayState($client->getRateLimitState());
29 changes: 29 additions & 0 deletions examples/user-repositories-tags-async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);
use ApiClients\Client\Github\AsyncClient;
use ApiClients\Client\Github\Resource\Async\Repository;
use ApiClients\Client\Github\Resource\Async\User;
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->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
resource_pretty_print($user);

return $user->repository($argv[2] ?? 'github');
})->then(function (Repository $repository) {
resource_pretty_print($repository, 1, true);
$repository->tags()->subscribe(function ($tag) {
resource_pretty_print($tag, 2, true);
}, function ($error) {
echo (string)$error;
});
})->done(null, 'display_throwable');

$loop->run();

displayState($client->getRateLimitState());
32 changes: 32 additions & 0 deletions src/CommandBus/Command/Repository/ReleasesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Command\Repository;

use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\ReleasesHandler")
*/
final class ReleasesCommand
{
/**
* @var string
*/
private $fullName;

/**
* @param string $fullName
*/
public function __construct(string $fullName)
{
$this->fullName = $fullName;
}

/**
* @return string
*/
public function getFullName(): string
{
return $this->fullName;
}
}
32 changes: 32 additions & 0 deletions src/CommandBus/Command/Repository/TagsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Command\Repository;

use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\TagsHandler")
*/
final class TagsCommand
{
/**
* @var string
*/
private $fullName;

/**
* @param string $fullName
*/
public function __construct(string $fullName)
{
$this->fullName = $fullName;
}

/**
* @return string
*/
public function getFullName(): string
{
return $this->fullName;
}
}
51 changes: 51 additions & 0 deletions src/CommandBus/Handler/Repository/ReleasesHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler\Repository;

use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand;
use ApiClients\Client\Github\Resource\Repository\ReleaseInterface;
use ApiClients\Client\Github\Service\IteratePagesService;
use ApiClients\Foundation\Hydrator\Hydrator;
use React\Promise\PromiseInterface;
use function ApiClients\Tools\Rx\observableFromArray;
use function React\Promise\resolve;

final class ReleasesHandler
{
/**
* @var IteratePagesService
*/
private $iteratePagesService;

/**
* @var Hydrator
*/
private $hydrator;

/**
* @param IteratePagesService $iteratePagesService
* @param Hydrator $hydrator
*/
public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
{
$this->iteratePagesService = $iteratePagesService;
$this->hydrator = $hydrator;
}

/**
* @param TagsCommand $command
* @return PromiseInterface
*/
public function handle(ReleasesCommand $command): PromiseInterface
{
return resolve(
$this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/releases')
->flatMap(function ($labels) {
return observableFromArray($labels);
})->map(function ($label) {
return $this->hydrator->hydrate(ReleaseInterface::HYDRATE_CLASS, $label);
})
);
}
}
50 changes: 50 additions & 0 deletions src/CommandBus/Handler/Repository/TagsHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler\Repository;

use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand;
use ApiClients\Client\Github\Resource\Repository\TagInterface;
use ApiClients\Client\Github\Service\IteratePagesService;
use ApiClients\Foundation\Hydrator\Hydrator;
use React\Promise\PromiseInterface;
use function ApiClients\Tools\Rx\observableFromArray;
use function React\Promise\resolve;

final class TagsHandler
{
/**
* @var IteratePagesService
*/
private $iteratePagesService;

/**
* @var Hydrator
*/
private $hydrator;

/**
* @param IteratePagesService $iteratePagesService
* @param Hydrator $hydrator
*/
public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
{
$this->iteratePagesService = $iteratePagesService;
$this->hydrator = $hydrator;
}

/**
* @param TagsCommand $command
* @return PromiseInterface
*/
public function handle(TagsCommand $command): PromiseInterface
{
return resolve(
$this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/tags')
->flatMap(function ($labels) {
return observableFromArray($labels);
})->map(function ($label) {
return $this->hydrator->hydrate(TagInterface::HYDRATE_CLASS, $label);
})
);
}
}
16 changes: 16 additions & 0 deletions src/Resource/Async/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand;
use ApiClients\Client\Github\Resource\Repository as BaseRepository;
use React\Promise\PromiseInterface;
use Rx\Observable;
Expand Down Expand Up @@ -67,4 +69,18 @@ public function communityHealth(): PromiseInterface
new CommunityHealthCommand($this->fullName())
);
}

public function tags(): ObservableInterface
{
return unwrapObservableFromPromise($this->handleCommand(
new TagsCommand($this->fullName())
));
}

public function releases(): ObservableInterface
{
return unwrapObservableFromPromise($this->handleCommand(
new ReleasesCommand($this->fullName())
));
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/Repository/EmptyRelease.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\Repository;

use ApiClients\Client\Github\Resource\Repository\EmptyRelease as BaseEmptyRelease;

class EmptyRelease extends BaseEmptyRelease
{
}
9 changes: 9 additions & 0 deletions src/Resource/Async/Repository/EmptyTag.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\Repository;

use ApiClients\Client\Github\Resource\Repository\EmptyTag as BaseEmptyTag;

class EmptyTag extends BaseEmptyTag
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/Release.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\Repository;

use ApiClients\Client\Github\Resource\Repository\Release as BaseRelease;

class Release extends BaseRelease
{
public function refresh(): Release
{
throw new \Exception('TODO: create refresh method!');
}
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/Release/Asset.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\Repository\Release;

use ApiClients\Client\Github\Resource\Repository\Release\Asset as BaseAsset;

class Asset extends BaseAsset
{
public function refresh(): Asset
{
throw new \Exception('TODO: create refresh method!');
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/Repository/Release/EmptyAsset.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\Repository\Release;

use ApiClients\Client\Github\Resource\Repository\Release\EmptyAsset as BaseEmptyAsset;

class EmptyAsset extends BaseEmptyAsset
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/Tag.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\Repository;

use ApiClients\Client\Github\Resource\Repository\Tag as BaseTag;

class Tag extends BaseTag
{
public function refresh(): Tag
{
throw new \Exception('TODO: create refresh method!');
}
}
Loading