Skip to content

Commit affd33a

Browse files
committed
API: add endpoints to list, add, remove customer vendor bundles
1 parent ff42e4c commit affd33a

File tree

6 files changed

+144
-5
lines changed

6 files changed

+144
-5
lines changed

README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
* [Grant a customer access to a package or edit the limitations](#grant-a-customer-access-to-a-package-or-edit-the-limitations)
4040
* [Revoke access to a package from a customer](#revoke-access-to-a-package-from-a-customer)
4141
* [Regenerate a customer's Composer repository token](#regenerate-a-customers-composer-repository-token)
42+
* [List a customer's vendor bundles](#list-a-customers-vendor-bundles)
43+
* [Grant a customer access to a vendor bundle or edit the limitations](#grant-a-customer-access-to-a-vendor-bundle-or-edit-the-limitations)
44+
* [Revoke access to a vendor bundle from a customer](#revoke-access-to-a-vendor-bundle-from-a-customer)
4245
* [Vendor Bundle](#vendor-bundle)
4346
* [List an organization's vendor bundles](#list-an-organizations-vendor-bundles)
4447
* [Show a vendor bundle](#show-a-vendor-bundle)
@@ -123,7 +126,7 @@
123126
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
124127
* [License](#license)
125128

126-
<!-- Added by: glaubinix, at: Thu 9 Feb 2023 15:12:39 GMT -->
129+
<!-- Added by: glaubinix, at: Thu 9 Feb 2023 15:40:34 GMT -->
127130

128131
<!--te-->
129132

@@ -423,6 +426,29 @@ $composerRepository = $client->customers()->regenerateToken($customerId, $confir
423426
```
424427
Returns the edited Composer repository.
425428

429+
#### List a customer's vendor bundles
430+
```php
431+
$customerId = 42;
432+
$packages = $client->customers()->vendorBundles()->listVendorBundles($customerId);
433+
```
434+
Returns an array of customer vendor bundles.
435+
436+
#### Grant a customer access to a vendor bundle or edit the limitations
437+
```php
438+
$customerId = 42;
439+
$vendorBundleId = 12;
440+
$expirationDate = (new \DateTime())->add(new \DateInterval('P1Y'))->format('c'), // optional expiration date to limit updates the customer receives
441+
$packages = $client->customers()->vendorBundles()->addOrEditVendorBundle($customerId, $vendorBundleId, $expirationDate);
442+
```
443+
Returns the added or edited customer vendor bundle.
444+
445+
#### Revoke access to a vendor bundle from a customer
446+
```php
447+
$customerId = 42;
448+
$vendorBundleId = 12;
449+
$client->customers()->vendorBundles()->removeVendorBundle($customerId, $vendorBundleId);
450+
```
451+
426452
### Vendor Bundle
427453

428454
#### List an organization's vendor bundles

src/Api/Customers.php

+5
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,9 @@ public function magentoLegacyKeys()
122122
{
123123
return new MagentoLegacyKeys($this->client);
124124
}
125+
126+
public function vendorBundles()
127+
{
128+
return new \PrivatePackagist\ApiClient\Api\Customers\VendorBundles($this->client);
129+
}
125130
}

src/Api/Customers/VendorBundles.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* (c) Packagist Conductors GmbH <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace PrivatePackagist\ApiClient\Api\Customers;
11+
12+
use PrivatePackagist\ApiClient\Api\AbstractApi;
13+
14+
class VendorBundles extends AbstractApi
15+
{
16+
public function listVendorBundles($customerIdOrUrlName)
17+
{
18+
return $this->get(sprintf('/customers/%s/vendor-bundles/', $customerIdOrUrlName));
19+
}
20+
21+
/**
22+
* @param int|string $customerIdOrUrlName
23+
* @param int $vendorBundleId
24+
* @param null|string $expirationDate
25+
*/
26+
public function addOrEditVendorBundle($customerIdOrUrlName, $vendorBundleId, $expirationDate = null)
27+
{
28+
return $this->post(sprintf('/customers/%s/vendor-bundles/', $customerIdOrUrlName), [
29+
'vendorBundleId' => $vendorBundleId,
30+
'expirationDate' => $expirationDate,
31+
]);
32+
}
33+
34+
/**
35+
* @param int|string $customerIdOrUrlName
36+
* @param int $vendorBundleId
37+
*/
38+
public function removeVendorBundle($customerIdOrUrlName, $vendorBundleId)
39+
{
40+
return $this->delete(sprintf('/customers/%s/vendor-bundles/%s/', $customerIdOrUrlName, $vendorBundleId));
41+
}
42+
}

src/Api/VendorBundles/Packages.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public function listPackages($vendorBundleIds)
2525

2626
/**
2727
* @param int $vendorBundleId
28-
* @param array{name: string, versionConstraint?: string, minimumAccessibleStability?: string}[]
28+
* @param array{name: string, versionConstraint?: string, minimumAccessibleStability?: string}[] $packages
2929
* @return array[]
3030
*/
3131
public function addOrEditPackages($vendorBundleId, array $packages)
3232
{
3333
foreach ($packages as $package) {
34-
if (!isset($package['name'])) {
34+
if (!isset($package['name'])) { // @phpstan-ignore-line
3535
throw new InvalidArgumentException('Parameter "name" is required.');
3636
}
3737
}
@@ -42,7 +42,6 @@ public function addOrEditPackages($vendorBundleId, array $packages)
4242
/**
4343
* @param int $vendorBundleId
4444
* @param string $packageName
45-
* @return null
4645
*/
4746
public function removePackage($vendorBundleId, $packageName)
4847
{
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PrivatePackagist\ApiClient\Api\Customers;
4+
5+
use PHPUnit\Framework\MockObject\MockObject;
6+
use PrivatePackagist\ApiClient\Api\ApiTestCase;
7+
8+
class VendorBundlesTest extends ApiTestCase
9+
{
10+
public function testListVendorBundles()
11+
{
12+
$expected = [
13+
[
14+
'expirationDate' => null,
15+
'vendorBundle' => ['id' => 12],
16+
],
17+
];
18+
19+
/** @var VendorBundles&MockObject $api */
20+
$api = $this->getApiMock();
21+
$api->expects($this->once())
22+
->method('get')
23+
->with($this->equalTo('/customers/1/vendor-bundles/'))
24+
->willReturn($expected);
25+
26+
$this->assertSame($expected, $api->listVendorBundles(1));
27+
}
28+
29+
public function testAddOrEditVendorBundle()
30+
{
31+
$expected = [
32+
'expirationDate' => null,
33+
'vendorBundle' => ['id' => 12],
34+
];
35+
36+
/** @var VendorBundles&MockObject $api */
37+
$api = $this->getApiMock();
38+
$api->expects($this->once())
39+
->method('post')
40+
->with($this->equalTo('/customers/1/vendor-bundles/'), $this->equalTo([
41+
'vendorBundleId' => 12,
42+
'expirationDate' => null,
43+
]))
44+
->willReturn($expected);
45+
46+
$this->assertSame($expected, $api->addOrEditVendorBundle(1, 12));
47+
}
48+
49+
public function testRemoveVendorBundle()
50+
{
51+
$expected = '';
52+
53+
/** @var VendorBundles&MockObject $api */
54+
$api = $this->getApiMock();
55+
$api->expects($this->once())
56+
->method('delete')
57+
->with($this->equalTo(sprintf('/customers/1/vendor-bundles/%s/', 12)))
58+
->willReturn($expected);
59+
60+
$this->assertSame($expected, $api->removeVendorBundle(1, 12));
61+
}
62+
63+
protected function getApiClass()
64+
{
65+
return VendorBundles::class;
66+
}
67+
}

tests/Api/VendorBundles/PackagesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testAddOrEditPackagesMissingName()
6565
/** @var Packages&MockObject $api */
6666
$api = $this->getApiMock();
6767

68-
$api->addOrEditPackages(1, [[]]);
68+
$api->addOrEditPackages(1, [[]]); // @phpstan-ignore-line
6969
}
7070

7171
public function testRemovePackage()

0 commit comments

Comments
 (0)