From 1301efd5a826acce3c8dc95dc544128664a7e3fc Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 26 Mar 2017 16:19:20 +0200 Subject: [PATCH 1/3] Add preview accept headers to ApiSettings for topics and license information on repository objects --- src/ApiSettings.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ApiSettings.php b/src/ApiSettings.php index 17040acf99..b806a45824 100644 --- a/src/ApiSettings.php +++ b/src/ApiSettings.php @@ -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, @@ -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; } } From f26ca2eee3109d4f23cf170256dea91541cd73ad Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 26 Mar 2017 16:21:51 +0200 Subject: [PATCH 2/3] License resource --- src/Resource/Async/EmptyLicense.php | 9 ++++ src/Resource/Async/License.php | 13 +++++ src/Resource/EmptyLicense.php | 40 ++++++++++++++ src/Resource/License.php | 64 +++++++++++++++++++++++ src/Resource/LicenseInterface.php | 30 +++++++++++ src/Resource/Sync/EmptyLicense.php | 9 ++++ src/Resource/Sync/License.php | 19 +++++++ tests/Resource/Async/EmptyLicenseTest.php | 18 +++++++ tests/Resource/Async/LicenseTest.php | 23 ++++++++ tests/Resource/Sync/EmptyLicenseTest.php | 18 +++++++ tests/Resource/Sync/LicenseTest.php | 23 ++++++++ yaml/license.yml | 6 +++ 12 files changed, 272 insertions(+) create mode 100644 src/Resource/Async/EmptyLicense.php create mode 100644 src/Resource/Async/License.php create mode 100644 src/Resource/EmptyLicense.php create mode 100644 src/Resource/License.php create mode 100644 src/Resource/LicenseInterface.php create mode 100644 src/Resource/Sync/EmptyLicense.php create mode 100644 src/Resource/Sync/License.php create mode 100644 tests/Resource/Async/EmptyLicenseTest.php create mode 100644 tests/Resource/Async/LicenseTest.php create mode 100644 tests/Resource/Sync/EmptyLicenseTest.php create mode 100644 tests/Resource/Sync/LicenseTest.php create mode 100644 yaml/license.yml diff --git a/src/Resource/Async/EmptyLicense.php b/src/Resource/Async/EmptyLicense.php new file mode 100644 index 0000000000..0e57763d7c --- /dev/null +++ b/src/Resource/Async/EmptyLicense.php @@ -0,0 +1,9 @@ +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; + } +} diff --git a/src/Resource/LicenseInterface.php b/src/Resource/LicenseInterface.php new file mode 100644 index 0000000000..97e9613737 --- /dev/null +++ b/src/Resource/LicenseInterface.php @@ -0,0 +1,30 @@ +wait($this->handleCommand( + new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) + )->then(function (LicenseInterface $license) { + return $license->refresh(); + })); + } +} diff --git a/tests/Resource/Async/EmptyLicenseTest.php b/tests/Resource/Async/EmptyLicenseTest.php new file mode 100644 index 0000000000..2809151bc4 --- /dev/null +++ b/tests/Resource/Async/EmptyLicenseTest.php @@ -0,0 +1,18 @@ + Date: Sun, 26 Mar 2017 16:22:27 +0200 Subject: [PATCH 3/3] Added topic and license to repository resource --- src/Resource/EmptyRepository.php | 17 +++++++++++++++ src/Resource/Repository.php | 31 ++++++++++++++++++++++++++-- src/Resource/RepositoryInterface.php | 10 +++++++++ yaml/repository.yml | 5 +++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Resource/EmptyRepository.php b/src/Resource/EmptyRepository.php index ae0fe64c24..e0640e7589 100644 --- a/src/Resource/EmptyRepository.php +++ b/src/Resource/EmptyRepository.php @@ -190,6 +190,7 @@ public function permissions() : array { return null; } + /** * @return string */ @@ -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; + } } diff --git a/src/Resource/Repository.php b/src/Resource/Repository.php index 273340432b..8fdcfbbc12 100644 --- a/src/Resource/Repository.php +++ b/src/Resource/Repository.php @@ -9,7 +9,8 @@ /** * @Nested( - * owner="User" + * owner="User", + * license="License" * ) * @EmptyResource("EmptyRepository") */ @@ -140,6 +141,16 @@ abstract class Repository extends AbstractResource implements RepositoryInterfac */ protected $owner; + /** + * @var License + */ + protected $license; + + /** + * @var array + */ + protected $topics; + /** * @return int */ @@ -177,7 +188,7 @@ public function url() : string */ public function description() : string { - return (string)$this->description; + return $this->description; } /** @@ -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; + } } diff --git a/src/Resource/RepositoryInterface.php b/src/Resource/RepositoryInterface.php index 8d07d55401..af7171bbd2 100644 --- a/src/Resource/RepositoryInterface.php +++ b/src/Resource/RepositoryInterface.php @@ -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; } diff --git a/yaml/repository.yml b/yaml/repository.yml index 29680b1b27..d8b9f94cdb 100644 --- a/yaml/repository.yml +++ b/yaml/repository.yml @@ -28,3 +28,8 @@ properties: type: User annotations: nested: User + license: + type: License + annotations: + nested: License + topics: array