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
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions examples/user-repository-community-health-async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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);
return $repository->communityHealth();
})->done(function (Repository\CommunityHealth $communityHealth) {
resource_pretty_print($communityHealth, 1, true);
}, 'display_throwable');

$loop->run();
34 changes: 34 additions & 0 deletions src/AcceptHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github;

final class AcceptHeader
{
const PRESET_DEFAULT = [
self::LICENSE,
self::TOPICS,
self::DEFAULT,
];

const PRESET_COMMUNITY_HEALTH = [
self::COMMUNITY_HEALTH,
self::DEFAULT,
];

// Community Health: https://developer.github.com/v3/repos/community/#community-health
const COMMUNITY_HEALTH = 'application/vnd.github.black-panther-preview+json';

// Default header: https://developer.github.com/v3/#current-version
const DEFAULT = 'application/vnd.github.v3+json';

// License on repository object: https://developer.github.com/v3/licenses/#licenses
const LICENSE = 'application/vnd.github.drax-preview+json';

// Topics on repository object: https://developer.github.com/v3/repos/#repositories
const TOPICS = 'application/vnd.github.mercy-preview+json';

public static function getHeader(array $chunks): string
{
return implode('; ', $chunks);
}
}
13 changes: 1 addition & 12 deletions src/ApiSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ final class ApiSettings
{
const NAMESPACE = 'ApiClients\\Client\\Github\\Resource';

const ACCEPT_HEADER = [
// License on repository object: https://developer.github.com/v3/licenses/#licenses
'application/vnd.github.drax-preview+json',

// Topics on repository object: https://developer.github.com/v3/repos/#repositories
'application/vnd.github.mercy-preview+json',

// Default header: https://developer.github.com/v3/#current-version
'application/vnd.github.v3+json',
];

const TRANSPORT_OPTIONS = [
FoundationOptions::HYDRATOR_OPTIONS => [
HydratorOptions::NAMESPACE => self::NAMESPACE,
Expand Down Expand Up @@ -59,7 +48,7 @@ public static function getOptions(
$options = options_merge($options, $suppliedOptions);
$options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix;

$acceptHeader = implode('; ', self::ACCEPT_HEADER);
$acceptHeader = AcceptHeader::getHeader(AcceptHeader::PRESET_DEFAULT);
$options[FoundationOptions::TRANSPORT_OPTIONS][TransportOptions::HEADERS]['Accept'] = $acceptHeader;

return $options;
Expand Down
33 changes: 33 additions & 0 deletions src/CommandBus/Command/Repository/CommunityHealthCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\CommunityHealthHandler")
*/
final class CommunityHealthCommand
{
/**
* @var string
*/
private $fullName;

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

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

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

use ApiClients\Client\Github\AcceptHeader;
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand;
use ApiClients\Client\Github\Resource\Repository\CommunityHealthInterface;
use ApiClients\Foundation\Transport\Options as TransportOptions;
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
use React\Promise\PromiseInterface;

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

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

/**
* @param CommunityHealthCommand $command
* @return PromiseInterface
*/
public function handle(CommunityHealthCommand $command): PromiseInterface
{
return $this->service->fetch(
'repos/' . $command->getFullName() . '/community/profile',
'',
CommunityHealthInterface::HYDRATE_CLASS,
[
TransportOptions::HEADERS => [
'Accept' => AcceptHeader::getHeader(AcceptHeader::PRESET_COMMUNITY_HEALTH),
],
]
);
}
}
13 changes: 13 additions & 0 deletions src/Resource/Async/CodeOfConduct.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\CodeOfConduct as BaseCodeOfConduct;

class CodeOfConduct extends BaseCodeOfConduct
{
public function refresh() : CodeOfConduct
{
throw new \Exception('TODO: create refresh method!');
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/EmptyCodeOfConduct.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\EmptyCodeOfConduct as BaseEmptyCodeOfConduct;

class EmptyCodeOfConduct extends BaseEmptyCodeOfConduct
{
}
9 changes: 9 additions & 0 deletions src/Resource/Async/EmptyUrl.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\EmptyUrl as BaseEmptyUrl;

class EmptyUrl extends BaseEmptyUrl
{
}
8 changes: 8 additions & 0 deletions src/Resource/Async/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ApiClients\Client\Github\CommandBus\Command\Repository\AddLabelCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand;
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\Resource\Repository as BaseRepository;
Expand Down Expand Up @@ -61,4 +62,11 @@ public function contents(): Observable
)
);
}

public function communityHealth(): PromiseInterface
{
return $this->handleCommand(
new CommunityHealthCommand($this->fullName())
);
}
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/CommunityHealth.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\CommunityHealth as BaseCommunityHealth;

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

use ApiClients\Client\Github\Resource\Repository\CommunityHealth\EmptyFiles as BaseEmptyFiles;

class EmptyFiles extends BaseEmptyFiles
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/CommunityHealth/Files.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\CommunityHealth;

use ApiClients\Client\Github\Resource\Repository\CommunityHealth\Files as BaseFiles;

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

class EmptyCommunityHealth extends BaseEmptyCommunityHealth
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Url.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\Url as BaseUrl;

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

namespace ApiClients\Client\Github\Resource;

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

/**
* @EmptyResource("EmptyCodeOfConduct")
*/
abstract class CodeOfConduct extends AbstractResource implements CodeOfConductInterface
{
/**
* @var string
*/
protected $key;

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

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

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

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

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

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

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