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
15 changes: 15 additions & 0 deletions src/ApiSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ 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 @@ -47,6 +58,10 @@ public static function getOptions(
$options = options_merge(self::TRANSPORT_OPTIONS, $auth->getOptions());
$options = options_merge($options, $suppliedOptions);
$options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix;

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

return $options;
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/EmptyLicense.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\EmptyLicense as BaseEmptyLicense;

class EmptyLicense extends BaseEmptyLicense
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/License.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\License as BaseLicense;

class License extends BaseLicense
{
public function refresh() : License
{
throw new \Exception('TODO: create refresh method!');
}
}
40 changes: 40 additions & 0 deletions src/Resource/EmptyLicense.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\EmptyResourceInterface;

abstract class EmptyLicense implements LicenseInterface, EmptyResourceInterface
{
/**
* @return string
*/
public function key() : string
{
return null;
}

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

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

/**
* @return string
*/
public function url() : string
{
return null;
}
}
17 changes: 17 additions & 0 deletions src/Resource/EmptyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function permissions() : array
{
return null;
}

/**
* @return string
*/
Expand All @@ -205,4 +206,20 @@ public function owner() : User
{
return null;
}

/**
* @return License
*/
public function license() : License
{
return null;
}

/**
* @return array
*/
public function topics() : array
{
return null;
}
}
64 changes: 64 additions & 0 deletions src/Resource/License.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("EmptyLicense")
*/
abstract class License extends AbstractResource implements LicenseInterface
{
/**
* @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;
}
}
30 changes: 30 additions & 0 deletions src/Resource/LicenseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource;

use ApiClients\Foundation\Resource\ResourceInterface;

interface LicenseInterface extends ResourceInterface
{
const HYDRATE_CLASS = 'License';

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

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

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

/**
* @return string
*/
public function url() : string;
}
31 changes: 29 additions & 2 deletions src/Resource/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

/**
* @Nested(
* owner="User"
* owner="User",
* license="License"
* )
* @EmptyResource("EmptyRepository")
*/
Expand Down Expand Up @@ -140,6 +141,16 @@ abstract class Repository extends AbstractResource implements RepositoryInterfac
*/
protected $owner;

/**
* @var License
*/
protected $license;

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

/**
* @return int
*/
Expand Down Expand Up @@ -177,7 +188,7 @@ public function url() : string
*/
public function description() : string
{
return (string)$this->description;
return $this->description;
}

/**
Expand Down Expand Up @@ -339,4 +350,20 @@ public function owner() : User
{
return $this->owner;
}

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

/**
* @return array
*/
public function topics() : array
{
return $this->topics;
}
}
10 changes: 10 additions & 0 deletions src/Resource/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ public function htmlUrl() : string;
* @return User
*/
public function owner() : User;

/**
* @return License
*/
public function license() : License;

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

class EmptyLicense extends BaseEmptyLicense
{
}
19 changes: 19 additions & 0 deletions src/Resource/Sync/License.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\License as BaseLicense;
use ApiClients\Client\Github\Resource\LicenseInterface;

class License extends BaseLicense
{
public function refresh() : License
{
return $this->wait($this->handleCommand(
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this)
)->then(function (LicenseInterface $license) {
return $license->refresh();
}));
}
}
18 changes: 18 additions & 0 deletions tests/Resource/Async/EmptyLicenseTest.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\EmptyLicense;

final class EmptyLicenseTest extends AbstractEmptyResourceTest
{
public function getSyncAsync() : string
{
return 'Async';
}
public function getClass() : string
{
return EmptyLicense::class;
}
}
23 changes: 23 additions & 0 deletions tests/Resource/Async/LicenseTest.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\License;

class LicenseTest extends AbstractResourceTest
{
public function getSyncAsync() : string
{
return 'Async';
}
public function getClass() : string
{
return License::class;
}
public function getNamespace() : string
{
return Apisettings::NAMESPACE;
}
}
18 changes: 18 additions & 0 deletions tests/Resource/Sync/EmptyLicenseTest.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\Sync;

use ApiClients\Tools\ResourceTestUtilities\AbstractEmptyResourceTest;
use ApiClients\Client\Github\Resource\Sync\EmptyLicense;

final class EmptyLicenseTest extends AbstractEmptyResourceTest
{
public function getSyncAsync() : string
{
return 'Sync';
}
public function getClass() : string
{
return EmptyLicense::class;
}
}
Loading