Skip to content

Commit 28985a1

Browse files
authored
Merge pull request #62 from packagist/vendor-bundles-api
API: add endpoints to manage vendor bundles
2 parents 5df947b + affd33a commit 28985a1

11 files changed

+618
-2
lines changed

README.md

+107-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
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)
45+
* [Vendor Bundle](#vendor-bundle)
46+
* [List an organization's vendor bundles](#list-an-organizations-vendor-bundles)
47+
* [Show a vendor bundle](#show-a-vendor-bundle)
48+
* [Create a vendor bundle](#create-a-vendor-bundle)
49+
* [Edit a customer](#edit-a-customer-1)
50+
* [Delete a vendor bundle](#delete-a-vendor-bundle)
51+
* [List packages in a vendor bundle](#list-packages-in-a-vendor-bundle)
52+
* [Add one or more packages to a vendor bundle or edit their limitations](#add-one-or-more-packages-to-a-vendor-bundle-or-edit-their-limitations)
53+
* [Remove a package from a vendor bundle](#remove-a-package-from-a-vendor-bundle)
4254
* [Subrepository](#subrepository)
4355
* [List an organization's subrepositories](#list-an-organizations-subrepositories)
4456
* [Show a subrepository](#show-a-subrepository)
@@ -114,7 +126,7 @@
114126
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
115127
* [License](#license)
116128

117-
<!-- Added by: glaubinix, at: Tue 24 Jan 2023 14:03:21 GMT -->
129+
<!-- Added by: glaubinix, at: Thu 9 Feb 2023 15:40:34 GMT -->
118130

119131
<!--te-->
120132

@@ -414,6 +426,100 @@ $composerRepository = $client->customers()->regenerateToken($customerId, $confir
414426
```
415427
Returns the edited Composer repository.
416428

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+
452+
### Vendor Bundle
453+
454+
#### List an organization's vendor bundles
455+
```php
456+
$vendorBundles = $client->vendorBundles()->all();
457+
```
458+
Returns an array of vendor bundles.
459+
460+
#### Show a vendor bundle
461+
```php
462+
$vendorBundleId = 42;
463+
$vendorBundle = $client->vendorBundles()->show($vendorBundleId);
464+
```
465+
Returns a single vendor bundle.
466+
467+
#### Create a vendor bundle
468+
```php
469+
$vendorBundle = $client->vendorBundles()->create('New bundle name');
470+
// or
471+
$vendorBundle = $client->vendorBundles()->create('New bundle name', 'dev', '^1.0', true, [123]);
472+
```
473+
Returns the vendor bundle.
474+
475+
#### Edit a customer
476+
```php
477+
$vendorBundleId = 42;
478+
$vendorBundleData = [
479+
'name' => 'Bundle name',
480+
'minimumAccessibleStability' => 'dev',
481+
'versionConstraint' => '^1.0',
482+
'assignAllPackages' => true,
483+
'synchronizationIds' => [123], // A list of synchronization ids for which new packages should automatically be added to the bundle.
484+
];
485+
$vendorBundle = $client->vendorBundles()->edit($vendorBundleId, $vendorBundleData);
486+
```
487+
Returns the vendor bundle.
488+
489+
#### Delete a vendor bundle
490+
```php
491+
$vendorBundleId = 42;
492+
$client->vendorBundles()->remove($vendorBundleId);
493+
```
494+
495+
#### List packages in a vendor bundle
496+
```php
497+
$vendorBundleId = 42;
498+
$packages = $client->vendorBundles()->packages()->listPackages($vendorBundleId);
499+
```
500+
Returns an array of vendor bundle packages.
501+
502+
#### Add one or more packages to a vendor bundle or edit their limitations
503+
```php
504+
$vendorBundleId = 42;
505+
$packages = [
506+
[
507+
'name' => 'acme-website/package',
508+
'versionConstraint' => '^1.0 | ^2.0', // optional version constraint to limit updates the customer receives
509+
'minimumAccessibleStability' => 'beta', // optional stability to restrict customers to specific package version stabilities like alpha, beta, or RC
510+
],
511+
];
512+
$packages = $client->vendorBundles()->packages()->addOrEditPackages($vendorBundleId, $packages);
513+
```
514+
Returns an array of all added or edited customer packages.
515+
516+
#### Remove a package from a vendor bundle
517+
```php
518+
$vendorBundleId = 42;
519+
$packageName = 'acme-website/package';
520+
$client->vendorBundles()->packages()->removePackage($vendorBundleId, $packageName);
521+
```
522+
417523
### Subrepository
418524

419525
#### List an organization's subrepositories

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/Synchronizations.php

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?php
22

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+
310
namespace PrivatePackagist\ApiClient\Api;
411

512
class Synchronizations extends AbstractApi

src/Api/VendorBundles.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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;
11+
12+
class VendorBundles extends AbstractApi
13+
{
14+
/**
15+
* @return array[]
16+
*/
17+
public function all()
18+
{
19+
return $this->get('/vendor-bundles/');
20+
}
21+
22+
/**
23+
* @param int $vendorBundleId
24+
* @return array
25+
*/
26+
public function show($vendorBundleId)
27+
{
28+
return $this->get(sprintf('/vendor-bundles/%s/', $vendorBundleId));
29+
}
30+
31+
/**
32+
* @param string $name
33+
* @param string|null $minimumAccessibleStability
34+
* @param string|null $versionConstraint
35+
* @param bool $assignAllPackages
36+
* @param int[] $synchronizationIds
37+
*/
38+
public function create($name, $minimumAccessibleStability = null, $versionConstraint = null, $assignAllPackages = false, array $synchronizationIds = [])
39+
{
40+
return $this->post('/vendor-bundles/', [
41+
'name' => $name,
42+
'minimumAccessibleStability' => $minimumAccessibleStability,
43+
'versionConstraint' => $versionConstraint,
44+
'assignAllPackages' => $assignAllPackages,
45+
'synchronizationIds' => $synchronizationIds,
46+
]);
47+
}
48+
49+
/**
50+
* @param int $vendorBundleId
51+
* @param array{name: string, minimumAccessibleStability?: string, versionConstraint?: string, assignAllPackages: bool, synchronizationIds?: int[]} $bundle
52+
* @return array
53+
*/
54+
public function edit($vendorBundleId, array $bundle)
55+
{
56+
return $this->put(sprintf('/vendor-bundles/%s/', $vendorBundleId), $bundle);
57+
}
58+
59+
/**
60+
* @param int $vendorBundleId
61+
*/
62+
public function remove($vendorBundleId)
63+
{
64+
return $this->delete(sprintf('/vendor-bundles/%s/', $vendorBundleId));
65+
}
66+
67+
public function packages(): \PrivatePackagist\ApiClient\Api\VendorBundles\Packages
68+
{
69+
return new \PrivatePackagist\ApiClient\Api\VendorBundles\Packages($this->client);
70+
}
71+
}

src/Api/VendorBundles/Packages.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\VendorBundles;
11+
12+
use PrivatePackagist\ApiClient\Api\AbstractApi;
13+
use PrivatePackagist\ApiClient\Exception\InvalidArgumentException;
14+
15+
class Packages extends AbstractApi
16+
{
17+
/**
18+
* @param int $vendorBundleIds
19+
* @return array[]
20+
*/
21+
public function listPackages($vendorBundleIds)
22+
{
23+
return $this->get(sprintf('/vendor-bundles/%s/packages/', $vendorBundleIds));
24+
}
25+
26+
/**
27+
* @param int $vendorBundleId
28+
* @param array{name: string, versionConstraint?: string, minimumAccessibleStability?: string}[] $packages
29+
* @return array[]
30+
*/
31+
public function addOrEditPackages($vendorBundleId, array $packages)
32+
{
33+
foreach ($packages as $package) {
34+
if (!isset($package['name'])) { // @phpstan-ignore-line
35+
throw new InvalidArgumentException('Parameter "name" is required.');
36+
}
37+
}
38+
39+
return $this->post(sprintf('/vendor-bundles/%s/packages/', $vendorBundleId), $packages);
40+
}
41+
42+
/**
43+
* @param int $vendorBundleId
44+
* @param string $packageName
45+
*/
46+
public function removePackage($vendorBundleId, $packageName)
47+
{
48+
return $this->delete(sprintf('/vendor-bundles/%s/packages/%s/', $vendorBundleId, $packageName));
49+
}
50+
}

src/Client.php

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public function synchronizations()
117117
return new Api\Synchronizations($this, $this->responseMediator);
118118
}
119119

120+
public function vendorBundles()
121+
{
122+
return new Api\VendorBundles($this, $this->responseMediator);
123+
}
124+
120125
public function getHttpClient()
121126
{
122127
return $this->getHttpClientBuilder()->getHttpClient();
+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+
}

0 commit comments

Comments
 (0)