diff --git a/README.md b/README.md index d0bcfaa..eaf3ac1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ * [Enable a customer](#enable-a-customer) * [Disable a customer](#disable-a-customer) * [List a customer's packages](#list-a-customers-packages) + * [Show a customer's package](#show-a-customers-package) * [Grant a customer access to a package or edit the limitations](#grant-a-customer-access-to-a-package-or-edit-the-limitations) * [Revoke access to a package from a customer](#revoke-access-to-a-package-from-a-customer) * [Regenerate a customer's Composer repository token](#regenerate-a-customers-composer-repository-token) @@ -107,7 +108,7 @@ * [Validate incoming webhook payloads](#validate-incoming-webhook-payloads) * [License](#license) - + @@ -286,6 +287,14 @@ $packages = $client->customers()->listPackages($customerId); ``` Returns an array of customer packages. +#### Show a customer's package +```php +$customerId = 42; +$package = $client->customers()->showPackage($customerId, $packageName); +$accessibleVersions = $package['versions']; +``` +Returns a customer's package, including the versions that the customer has been granted access to. + #### Grant a customer access to a package or edit the limitations ```php $customerId = 42; @@ -508,7 +517,7 @@ $mirroredRepository = $client->subrepositories()->mirroredRepositories()->add($s ``` Returns a list of added mirrored repositories. -#### Edit the mirroring behaviour of mirrored repository in a subrepository +#### Edit the mirroring behaviour of mirrored repository in a subrepository ```php $subrepositoryName = 'subrepository'; $mirroredRepositoryId = 42; @@ -845,7 +854,7 @@ When you create or update a webhook in Private Packagist an optional secret can $request = /** any Psr7 request */; $secret = 'webhook-secret'; $webhookSignature = new \PrivatePackagist\ApiClient\WebhookSignature($secret); -$requestSignature = $request->hasHeader('Packagist-Signature') ? $request->getHeader('Packagist-Signature')[0] : null; +$requestSignature = $request->hasHeader('Packagist-Signature') ? $request->getHeader('Packagist-Signature')[0] : null; $webhookSignature->validate($requestSignature, (string) $request->getBody()); ``` diff --git a/src/Api/Customers.php b/src/Api/Customers.php index f98c4ee..0d1abb5 100644 --- a/src/Api/Customers.php +++ b/src/Api/Customers.php @@ -71,6 +71,11 @@ public function listPackages($customerIdOrUrlName) return $this->get(sprintf('/customers/%s/packages/', $customerIdOrUrlName)); } + public function showPackage($customerIdOrUrlName, $packageName) + { + return $this->get(sprintf('/customers/%s/packages/%s/', $customerIdOrUrlName, $packageName)); + } + /** * @deprecated Use addOrEditPackages instead */ diff --git a/tests/Api/CustomersTest.php b/tests/Api/CustomersTest.php index be0ce7c..e9a9755 100644 --- a/tests/Api/CustomersTest.php +++ b/tests/Api/CustomersTest.php @@ -203,6 +203,34 @@ public function testListPackages() $this->assertSame($expected, $api->listPackages(1)); } + public function testShowPackage() + { + $expected = [ + 'name' => 'composer/composer', + 'origin' => 'private', + 'versionConstraint' => null, + 'expirationDate' => null, + 'versions' => [ + [ + 'version' => '2.3.9', + 'versionNormalized' => '2.3.9.0', + 'sourceReference' => '015f524c9969255a29cdea8890cbd4fec240ee47', + 'distReference' => '015f524c9969255a29cdea8890cbd4fec240ee47', + 'releasedAt' => '2022-07-05T14:52:00+00:00', + ], + ], + ]; + + /** @var Customers&MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with($this->equalTo('/customers/1/packages/composer/composer/')) + ->willReturn($expected); + + $this->assertSame($expected, $api->showPackage(1, 'composer/composer')); + } + public function testAddOrEditPackages() { $expected = [