Skip to content

Commit 61fabb0

Browse files
authored
Merge pull request #54 from zanbaldwin/z/customer-package-versions
API: Add Listing Customer Package with Accessible Versions Method
2 parents 6c846fb + 8a84b93 commit 61fabb0

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [Enable a customer](#enable-a-customer)
3030
* [Disable a customer](#disable-a-customer)
3131
* [List a customer's packages](#list-a-customers-packages)
32+
* [Show a customer's package](#show-a-customers-package)
3233
* [Grant a customer access to a package or edit the limitations](#grant-a-customer-access-to-a-package-or-edit-the-limitations)
3334
* [Revoke access to a package from a customer](#revoke-access-to-a-package-from-a-customer)
3435
* [Regenerate a customer's Composer repository token](#regenerate-a-customers-composer-repository-token)
@@ -107,7 +108,7 @@
107108
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
108109
* [License](#license)
109110

110-
<!-- Added by: glaubinix, at: Thu 13 Jan 2022 13:34:48 GMT -->
111+
<!-- Added by: zanbaldwin, at: Thu 18 Aug 12:50:05 CEST 2022 -->
111112

112113
<!--te-->
113114

@@ -286,6 +287,14 @@ $packages = $client->customers()->listPackages($customerId);
286287
```
287288
Returns an array of customer packages.
288289

290+
#### Show a customer's package
291+
```php
292+
$customerId = 42;
293+
$package = $client->customers()->showPackage($customerId, $packageName);
294+
$accessibleVersions = $package['versions'];
295+
```
296+
Returns a customer's package, including the versions that the customer has been granted access to.
297+
289298
#### Grant a customer access to a package or edit the limitations
290299
```php
291300
$customerId = 42;
@@ -508,7 +517,7 @@ $mirroredRepository = $client->subrepositories()->mirroredRepositories()->add($s
508517
```
509518
Returns a list of added mirrored repositories.
510519

511-
#### Edit the mirroring behaviour of mirrored repository in a subrepository
520+
#### Edit the mirroring behaviour of mirrored repository in a subrepository
512521
```php
513522
$subrepositoryName = 'subrepository';
514523
$mirroredRepositoryId = 42;
@@ -845,7 +854,7 @@ When you create or update a webhook in Private Packagist an optional secret can
845854
$request = /** any Psr7 request */;
846855
$secret = 'webhook-secret';
847856
$webhookSignature = new \PrivatePackagist\ApiClient\WebhookSignature($secret);
848-
$requestSignature = $request->hasHeader('Packagist-Signature') ? $request->getHeader('Packagist-Signature')[0] : null;
857+
$requestSignature = $request->hasHeader('Packagist-Signature') ? $request->getHeader('Packagist-Signature')[0] : null;
849858
$webhookSignature->validate($requestSignature, (string) $request->getBody());
850859
```
851860

src/Api/Customers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public function listPackages($customerIdOrUrlName)
7171
return $this->get(sprintf('/customers/%s/packages/', $customerIdOrUrlName));
7272
}
7373

74+
public function showPackage($customerIdOrUrlName, $packageName)
75+
{
76+
return $this->get(sprintf('/customers/%s/packages/%s/', $customerIdOrUrlName, $packageName));
77+
}
78+
7479
/**
7580
* @deprecated Use addOrEditPackages instead
7681
*/

tests/Api/CustomersTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,34 @@ public function testListPackages()
203203
$this->assertSame($expected, $api->listPackages(1));
204204
}
205205

206+
public function testShowPackage()
207+
{
208+
$expected = [
209+
'name' => 'composer/composer',
210+
'origin' => 'private',
211+
'versionConstraint' => null,
212+
'expirationDate' => null,
213+
'versions' => [
214+
[
215+
'version' => '2.3.9',
216+
'versionNormalized' => '2.3.9.0',
217+
'sourceReference' => '015f524c9969255a29cdea8890cbd4fec240ee47',
218+
'distReference' => '015f524c9969255a29cdea8890cbd4fec240ee47',
219+
'releasedAt' => '2022-07-05T14:52:00+00:00',
220+
],
221+
],
222+
];
223+
224+
/** @var Customers&MockObject $api */
225+
$api = $this->getApiMock();
226+
$api->expects($this->once())
227+
->method('get')
228+
->with($this->equalTo('/customers/1/packages/composer/composer/'))
229+
->willReturn($expected);
230+
231+
$this->assertSame($expected, $api->showPackage(1, 'composer/composer'));
232+
}
233+
206234
public function testAddOrEditPackages()
207235
{
208236
$expected = [

0 commit comments

Comments
 (0)